2017-02-10 13:28:06 +00:00
|
|
|
// Syslog interface for Unix variants only
|
|
|
|
|
|
|
|
// +build !windows,!nacl,!plan9
|
|
|
|
|
2018-01-12 16:30:54 +00:00
|
|
|
package log
|
2017-02-10 13:28:06 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
"log"
|
|
|
|
"log/syslog"
|
|
|
|
"os"
|
|
|
|
"path"
|
2018-01-12 16:30:54 +00:00
|
|
|
|
2019-07-28 17:47:38 +00:00
|
|
|
"github.com/rclone/rclone/fs"
|
2017-02-10 13:28:06 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
var (
|
|
|
|
syslogFacilityMap = map[string]syslog.Priority{
|
|
|
|
"KERN": syslog.LOG_KERN,
|
|
|
|
"USER": syslog.LOG_USER,
|
|
|
|
"MAIL": syslog.LOG_MAIL,
|
|
|
|
"DAEMON": syslog.LOG_DAEMON,
|
|
|
|
"AUTH": syslog.LOG_AUTH,
|
|
|
|
"SYSLOG": syslog.LOG_SYSLOG,
|
|
|
|
"LPR": syslog.LOG_LPR,
|
|
|
|
"NEWS": syslog.LOG_NEWS,
|
|
|
|
"UUCP": syslog.LOG_UUCP,
|
|
|
|
"CRON": syslog.LOG_CRON,
|
|
|
|
"AUTHPRIV": syslog.LOG_AUTHPRIV,
|
|
|
|
"FTP": syslog.LOG_FTP,
|
|
|
|
}
|
|
|
|
)
|
|
|
|
|
|
|
|
// Starts syslog
|
|
|
|
func startSysLog() bool {
|
2019-12-10 13:54:00 +00:00
|
|
|
facility, ok := syslogFacilityMap[Opt.SyslogFacility]
|
2017-02-10 13:28:06 +00:00
|
|
|
if !ok {
|
2019-12-10 13:54:00 +00:00
|
|
|
log.Fatalf("Unknown syslog facility %q - man syslog for list", Opt.SyslogFacility)
|
2017-02-10 13:28:06 +00:00
|
|
|
}
|
|
|
|
Me := path.Base(os.Args[0])
|
|
|
|
w, err := syslog.New(syslog.LOG_NOTICE|facility, Me)
|
|
|
|
if err != nil {
|
|
|
|
log.Fatalf("Failed to start syslog: %v", err)
|
|
|
|
}
|
|
|
|
log.SetFlags(0)
|
|
|
|
log.SetOutput(w)
|
2018-01-12 16:30:54 +00:00
|
|
|
fs.LogPrint = func(level fs.LogLevel, text string) {
|
2017-02-10 13:28:06 +00:00
|
|
|
switch level {
|
2018-01-12 16:30:54 +00:00
|
|
|
case fs.LogLevelEmergency:
|
2017-02-10 13:28:06 +00:00
|
|
|
_ = w.Emerg(text)
|
2018-01-12 16:30:54 +00:00
|
|
|
case fs.LogLevelAlert:
|
2017-02-10 13:28:06 +00:00
|
|
|
_ = w.Alert(text)
|
2018-01-12 16:30:54 +00:00
|
|
|
case fs.LogLevelCritical:
|
2017-02-10 13:28:06 +00:00
|
|
|
_ = w.Crit(text)
|
2018-01-12 16:30:54 +00:00
|
|
|
case fs.LogLevelError:
|
2017-02-10 13:28:06 +00:00
|
|
|
_ = w.Err(text)
|
2018-01-12 16:30:54 +00:00
|
|
|
case fs.LogLevelWarning:
|
2017-02-10 13:28:06 +00:00
|
|
|
_ = w.Warning(text)
|
2018-01-12 16:30:54 +00:00
|
|
|
case fs.LogLevelNotice:
|
2017-02-10 13:28:06 +00:00
|
|
|
_ = w.Notice(text)
|
2018-01-12 16:30:54 +00:00
|
|
|
case fs.LogLevelInfo:
|
2017-02-10 13:28:06 +00:00
|
|
|
_ = w.Info(text)
|
2018-01-12 16:30:54 +00:00
|
|
|
case fs.LogLevelDebug:
|
2017-02-10 13:28:06 +00:00
|
|
|
_ = w.Debug(text)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true
|
|
|
|
}
|