2018-10-26 23:05:01 +00:00
|
|
|
// +build linux
|
2018-11-25 18:24:10 +00:00
|
|
|
|
|
|
|
// Package logger is a wrapper around UNIX syslog, so that it also may
|
|
|
|
// be wrapped with something else for Windows (Sadly, the stdlib log/syslog
|
|
|
|
// is frozen, and there is no Windows implementation.)
|
2018-10-26 23:05:01 +00:00
|
|
|
package logger
|
|
|
|
|
|
|
|
import (
|
|
|
|
sl "log/syslog"
|
|
|
|
)
|
|
|
|
|
2018-11-25 18:24:10 +00:00
|
|
|
// Priority is the logger priority
|
2018-10-26 23:05:01 +00:00
|
|
|
type Priority = sl.Priority
|
2018-11-25 18:24:10 +00:00
|
|
|
// Writer is a syslog Writer
|
2018-10-26 23:05:01 +00:00
|
|
|
type Writer = sl.Writer
|
|
|
|
|
2018-11-25 18:24:10 +00:00
|
|
|
// nolint: golint
|
2018-10-26 23:05:01 +00:00
|
|
|
const (
|
|
|
|
// Severity.
|
|
|
|
|
|
|
|
// From /usr/include/sys/syslog.h.
|
|
|
|
// These are the same on Linux, BSD, and OS X.
|
|
|
|
LOG_EMERG Priority = iota
|
|
|
|
LOG_ALERT
|
|
|
|
LOG_CRIT
|
|
|
|
LOG_ERR
|
|
|
|
LOG_WARNING
|
|
|
|
LOG_NOTICE
|
|
|
|
LOG_INFO
|
|
|
|
LOG_DEBUG
|
|
|
|
)
|
|
|
|
|
2018-11-25 18:24:10 +00:00
|
|
|
// nolint: golint
|
2018-10-26 23:05:01 +00:00
|
|
|
const (
|
|
|
|
// Facility.
|
|
|
|
|
|
|
|
// From /usr/include/sys/syslog.h.
|
|
|
|
// These are the same up to LOG_FTP on Linux, BSD, and OS X.
|
|
|
|
LOG_KERN Priority = iota << 3
|
|
|
|
LOG_USER
|
|
|
|
LOG_MAIL
|
|
|
|
LOG_DAEMON
|
|
|
|
LOG_AUTH
|
|
|
|
LOG_SYSLOG
|
|
|
|
LOG_LPR
|
|
|
|
LOG_NEWS
|
|
|
|
LOG_UUCP
|
|
|
|
LOG_CRON
|
|
|
|
LOG_AUTHPRIV
|
|
|
|
LOG_FTP
|
|
|
|
_ // unused
|
|
|
|
_ // unused
|
|
|
|
_ // unused
|
|
|
|
_ // unused
|
|
|
|
LOG_LOCAL0
|
|
|
|
LOG_LOCAL1
|
|
|
|
LOG_LOCAL2
|
|
|
|
LOG_LOCAL3
|
|
|
|
LOG_LOCAL4
|
|
|
|
LOG_LOCAL5
|
|
|
|
LOG_LOCAL6
|
|
|
|
LOG_LOCAL7
|
|
|
|
)
|
|
|
|
|
|
|
|
var (
|
|
|
|
l *sl.Writer
|
|
|
|
)
|
|
|
|
|
2018-11-25 18:24:10 +00:00
|
|
|
// New returns a new log Writer.
|
2018-10-26 23:05:01 +00:00
|
|
|
func New(flags Priority, tag string) (w *Writer, e error) {
|
2018-11-25 18:24:10 +00:00
|
|
|
w, e = sl.New(flags, tag)
|
2018-10-26 23:05:01 +00:00
|
|
|
l = w
|
|
|
|
return w, e
|
|
|
|
}
|
|
|
|
|
2018-11-25 18:24:10 +00:00
|
|
|
// Alert returns a log Alert error
|
2018-10-26 23:05:01 +00:00
|
|
|
func Alert(s string) error {
|
|
|
|
return l.Alert(s)
|
|
|
|
}
|
2018-11-25 18:24:10 +00:00
|
|
|
|
|
|
|
// LogClose closes the log Writer.
|
2018-10-26 23:05:01 +00:00
|
|
|
func LogClose() error {
|
|
|
|
return l.Close()
|
|
|
|
}
|
2018-11-25 18:24:10 +00:00
|
|
|
|
|
|
|
// LogCrit returns a log Alert error
|
2018-10-26 23:05:01 +00:00
|
|
|
func LogCrit(s string) error {
|
|
|
|
return l.Crit(s)
|
|
|
|
}
|
2018-11-25 18:24:10 +00:00
|
|
|
|
|
|
|
// LogDebug returns a log Debug error
|
2018-10-26 23:05:01 +00:00
|
|
|
func LogDebug(s string) error {
|
|
|
|
return l.Debug(s)
|
|
|
|
}
|
2018-11-25 18:24:10 +00:00
|
|
|
|
|
|
|
// LogEmerg returns a log Emerg error
|
2018-10-26 23:05:01 +00:00
|
|
|
func LogEmerg(s string) error {
|
|
|
|
return l.Emerg(s)
|
|
|
|
}
|
2018-11-25 18:24:10 +00:00
|
|
|
|
|
|
|
// LogErr returns a log Err error
|
2018-10-26 23:05:01 +00:00
|
|
|
func LogErr(s string) error {
|
|
|
|
return l.Err(s)
|
|
|
|
}
|
2018-11-25 18:24:10 +00:00
|
|
|
|
|
|
|
// LogInfo returns a log Info error
|
2018-10-26 23:05:01 +00:00
|
|
|
func LogInfo(s string) error {
|
|
|
|
return l.Info(s)
|
|
|
|
}
|
2018-11-25 18:24:10 +00:00
|
|
|
|
|
|
|
// LogNotice returns a log Notice error
|
2018-10-26 23:05:01 +00:00
|
|
|
func LogNotice(s string) error {
|
|
|
|
return l.Notice(s)
|
|
|
|
}
|
2018-11-25 18:24:10 +00:00
|
|
|
|
|
|
|
// LogWarning returns a log Warning error
|
2018-10-26 23:05:01 +00:00
|
|
|
func LogWarning(s string) error {
|
|
|
|
return l.Warning(s)
|
|
|
|
}
|
2018-11-25 18:24:10 +00:00
|
|
|
|
|
|
|
// LogWrite writes to the logger at default level
|
2018-10-26 23:05:01 +00:00
|
|
|
func LogWrite(b []byte) (int, error) {
|
|
|
|
return l.Write(b)
|
|
|
|
}
|