2015-03-09 14:40:57 -04:00
|
|
|
package syslog
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"log/syslog"
|
|
|
|
"os"
|
|
|
|
"path"
|
|
|
|
|
|
|
|
"github.com/docker/docker/daemon/logger"
|
|
|
|
)
|
|
|
|
|
|
|
|
type Syslog struct {
|
|
|
|
writer *syslog.Writer
|
|
|
|
}
|
|
|
|
|
|
|
|
func New(tag string) (logger.Logger, error) {
|
2015-04-15 03:16:43 -04:00
|
|
|
log, err := syslog.New(syslog.LOG_DAEMON, fmt.Sprintf("%s/%s", path.Base(os.Args[0]), tag))
|
2015-03-09 14:40:57 -04:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
return &Syslog{
|
|
|
|
writer: log,
|
|
|
|
}, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *Syslog) Log(msg *logger.Message) error {
|
|
|
|
if msg.Source == "stderr" {
|
2015-04-13 05:56:12 -04:00
|
|
|
return s.writer.Err(string(msg.Line))
|
2015-03-09 14:40:57 -04:00
|
|
|
}
|
2015-04-13 05:56:12 -04:00
|
|
|
return s.writer.Info(string(msg.Line))
|
2015-03-09 14:40:57 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
func (s *Syslog) Close() error {
|
2015-03-23 15:03:24 -04:00
|
|
|
return s.writer.Close()
|
2015-03-09 14:40:57 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
func (s *Syslog) Name() string {
|
|
|
|
return "Syslog"
|
|
|
|
}
|