github.com/hhrutter/nomad@v0.6.0-rc2.0.20170723054333-80c4b03f0705/client/driver/executor/executor_unix.go (about) 1 // +build darwin dragonfly freebsd linux netbsd openbsd solaris windows 2 3 package executor 4 5 import ( 6 "fmt" 7 "io" 8 9 syslog "github.com/RackSec/srslog" 10 11 "github.com/hashicorp/nomad/client/driver/logging" 12 ) 13 14 func (e *UniversalExecutor) LaunchSyslogServer() (*SyslogServerState, error) { 15 // Ensure the context has been set first 16 if e.ctx == nil { 17 return nil, fmt.Errorf("SetContext must be called before launching the Syslog Server") 18 } 19 20 e.syslogChan = make(chan *logging.SyslogMessage, 2048) 21 l, err := e.getListener(e.ctx.PortLowerBound, e.ctx.PortUpperBound) 22 if err != nil { 23 return nil, err 24 } 25 e.logger.Printf("[DEBUG] syslog-server: launching syslog server on addr: %v", l.Addr().String()) 26 if err := e.configureLoggers(); err != nil { 27 return nil, err 28 } 29 30 e.syslogServer = logging.NewSyslogServer(l, e.syslogChan, e.logger) 31 go e.syslogServer.Start() 32 go e.collectLogs(e.lre, e.lro) 33 syslogAddr := fmt.Sprintf("%s://%s", l.Addr().Network(), l.Addr().String()) 34 return &SyslogServerState{Addr: syslogAddr}, nil 35 } 36 37 func (e *UniversalExecutor) collectLogs(we io.Writer, wo io.Writer) { 38 for logParts := range e.syslogChan { 39 // If the severity of the log line is err then we write to stderr 40 // otherwise all messages go to stdout 41 if logParts.Severity == syslog.LOG_ERR { 42 e.lre.Write(logParts.Message) 43 e.lre.Write([]byte{'\n'}) 44 } else { 45 e.lro.Write(logParts.Message) 46 e.lro.Write([]byte{'\n'}) 47 } 48 } 49 }