moby/daemon/logger/syslog/syslog.go
Deng Guangxing 4f91a333d5 move syslog-tag to syslog.New function
Signed-off-by: Deng Guangxing <dengguangxing@huawei.com>
Signed-off-by: Michael Crosby <crosbymichael@gmail.com>
2015-04-13 11:24:18 -07:00

39 lines
653 B
Go

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) {
log, err := syslog.New(syslog.LOG_USER, fmt.Sprintf("%s: <%s> ", path.Base(os.Args[0]), tag))
if err != nil {
return nil, err
}
return &Syslog{
writer: log,
}, nil
}
func (s *Syslog) Log(msg *logger.Message) error {
if msg.Source == "stderr" {
return s.writer.Err(string(msg.Line))
}
return s.writer.Info(string(msg.Line))
}
func (s *Syslog) Close() error {
return s.writer.Close()
}
func (s *Syslog) Name() string {
return "Syslog"
}