github.com/gunjan5/docker@v1.8.2/daemon/logger/journald/journald.go (about) 1 // +build linux 2 3 package journald 4 5 import ( 6 "fmt" 7 8 "github.com/Sirupsen/logrus" 9 "github.com/coreos/go-systemd/journal" 10 "github.com/docker/docker/daemon/logger" 11 ) 12 13 const name = "journald" 14 15 type Journald struct { 16 Jmap map[string]string 17 } 18 19 func init() { 20 if err := logger.RegisterLogDriver(name, New); err != nil { 21 logrus.Fatal(err) 22 } 23 } 24 25 func New(ctx logger.Context) (logger.Logger, error) { 26 if !journal.Enabled() { 27 return nil, fmt.Errorf("journald is not enabled on this host") 28 } 29 // Strip a leading slash so that people can search for 30 // CONTAINER_NAME=foo rather than CONTAINER_NAME=/foo. 31 name := ctx.ContainerName 32 if name[0] == '/' { 33 name = name[1:] 34 } 35 jmap := map[string]string{ 36 "CONTAINER_ID": ctx.ContainerID[:12], 37 "CONTAINER_ID_FULL": ctx.ContainerID, 38 "CONTAINER_NAME": name} 39 return &Journald{Jmap: jmap}, nil 40 } 41 42 func (s *Journald) Log(msg *logger.Message) error { 43 if msg.Source == "stderr" { 44 return journal.Send(string(msg.Line), journal.PriErr, s.Jmap) 45 } 46 return journal.Send(string(msg.Line), journal.PriInfo, s.Jmap) 47 } 48 49 func (s *Journald) Close() error { 50 return nil 51 } 52 53 func (s *Journald) Name() string { 54 return name 55 }