2015-05-14 13:20:00 -04:00
|
|
|
// +build linux
|
|
|
|
|
2015-03-09 14:40:57 -04:00
|
|
|
package syslog
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
2015-04-09 00:23:30 -04:00
|
|
|
"io"
|
2015-03-09 14:40:57 -04:00
|
|
|
"log/syslog"
|
|
|
|
"os"
|
|
|
|
"path"
|
|
|
|
|
2015-04-09 00:23:30 -04:00
|
|
|
"github.com/Sirupsen/logrus"
|
2015-03-09 14:40:57 -04:00
|
|
|
"github.com/docker/docker/daemon/logger"
|
|
|
|
)
|
|
|
|
|
2015-04-09 00:23:30 -04:00
|
|
|
const name = "syslog"
|
|
|
|
|
2015-03-09 14:40:57 -04:00
|
|
|
type Syslog struct {
|
|
|
|
writer *syslog.Writer
|
|
|
|
}
|
|
|
|
|
2015-04-09 00:23:30 -04:00
|
|
|
func init() {
|
|
|
|
if err := logger.RegisterLogDriver(name, New); err != nil {
|
|
|
|
logrus.Fatal(err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func New(ctx logger.Context) (logger.Logger, error) {
|
|
|
|
tag := ctx.ContainerID[:12]
|
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
|
|
|
|
}
|
2015-04-09 00:23:30 -04:00
|
|
|
|
2015-03-09 14:40:57 -04:00
|
|
|
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 {
|
2015-04-09 00:23:30 -04:00
|
|
|
return name
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *Syslog) GetReader() (io.Reader, error) {
|
|
|
|
return nil, logger.ReadLogsNotSupported
|
2015-03-09 14:40:57 -04:00
|
|
|
}
|