1
0
Fork 0
mirror of https://github.com/moby/moby.git synced 2022-11-09 12:21:53 -05:00
moby--moby/daemon/logger/journald/journald.go
Morgan Bauer ccbe539e86
golint fixes for daemon/logger/*
- downcase and privatize exported variables that were unused
 - make accurate an error message
 - added package comments
 - remove unused var ReadLogsNotSupported
 - enable linter
 - some spelling corrections

Signed-off-by: Morgan Bauer <mbauer@us.ibm.com>
2015-07-29 13:09:39 -07:00

60 lines
1.4 KiB
Go

// +build linux
// Package journald provides the log driver for forwarding server logs
// to endpoints that receive the systemd format.
package journald
import (
"fmt"
"github.com/Sirupsen/logrus"
"github.com/coreos/go-systemd/journal"
"github.com/docker/docker/daemon/logger"
)
const name = "journald"
type journald struct {
Jmap map[string]string
}
func init() {
if err := logger.RegisterLogDriver(name, New); err != nil {
logrus.Fatal(err)
}
}
// New creates a journald logger using the configuration passed in on
// the context. Supported context configuration variables are
// syslog-address, syslog-facility, & syslog-tag.
func New(ctx logger.Context) (logger.Logger, error) {
if !journal.Enabled() {
return nil, fmt.Errorf("journald is not enabled on this host")
}
// Strip a leading slash so that people can search for
// CONTAINER_NAME=foo rather than CONTAINER_NAME=/foo.
name := ctx.ContainerName
if name[0] == '/' {
name = name[1:]
}
jmap := map[string]string{
"CONTAINER_ID": ctx.ContainerID[:12],
"CONTAINER_ID_FULL": ctx.ContainerID,
"CONTAINER_NAME": name}
return &journald{Jmap: jmap}, nil
}
func (s *journald) Log(msg *logger.Message) error {
if msg.Source == "stderr" {
return journal.Send(string(msg.Line), journal.PriErr, s.Jmap)
}
return journal.Send(string(msg.Line), journal.PriInfo, s.Jmap)
}
func (s *journald) Close() error {
return nil
}
func (s *journald) Name() string {
return name
}