2017-02-10 21:28:06 +08:00
|
|
|
// Syslog interface for Unix variants only
|
|
|
|
|
2021-09-09 20:25:25 +08:00
|
|
|
//go:build !windows && !nacl && !plan9
|
2017-02-10 21:28:06 +08:00
|
|
|
|
2018-01-13 00:30:54 +08:00
|
|
|
package log
|
2017-02-10 21:28:06 +08:00
|
|
|
|
|
|
|
import (
|
|
|
|
"log"
|
|
|
|
"log/syslog"
|
|
|
|
"os"
|
|
|
|
"path"
|
2018-01-13 00:30:54 +08:00
|
|
|
|
2019-07-29 01:47:38 +08:00
|
|
|
"github.com/rclone/rclone/fs"
|
2017-02-10 21:28:06 +08: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,
|
2020-03-13 01:31:21 +08:00
|
|
|
"LOCAL0": syslog.LOG_LOCAL0,
|
|
|
|
"LOCAL1": syslog.LOG_LOCAL1,
|
|
|
|
"LOCAL2": syslog.LOG_LOCAL2,
|
|
|
|
"LOCAL3": syslog.LOG_LOCAL3,
|
|
|
|
"LOCAL4": syslog.LOG_LOCAL4,
|
|
|
|
"LOCAL5": syslog.LOG_LOCAL5,
|
|
|
|
"LOCAL6": syslog.LOG_LOCAL6,
|
|
|
|
"LOCAL7": syslog.LOG_LOCAL7,
|
2017-02-10 21:28:06 +08:00
|
|
|
}
|
|
|
|
)
|
|
|
|
|
|
|
|
// Starts syslog
|
|
|
|
func startSysLog() bool {
|
2019-12-10 21:54:00 +08:00
|
|
|
facility, ok := syslogFacilityMap[Opt.SyslogFacility]
|
2017-02-10 21:28:06 +08:00
|
|
|
if !ok {
|
2024-08-18 22:58:35 +08:00
|
|
|
fs.Fatalf(nil, "Unknown syslog facility %q - man syslog for list", Opt.SyslogFacility)
|
2017-02-10 21:28:06 +08:00
|
|
|
}
|
|
|
|
Me := path.Base(os.Args[0])
|
|
|
|
w, err := syslog.New(syslog.LOG_NOTICE|facility, Me)
|
|
|
|
if err != nil {
|
2024-08-18 22:58:35 +08:00
|
|
|
fs.Fatalf(nil, "Failed to start syslog: %v", err)
|
2017-02-10 21:28:06 +08:00
|
|
|
}
|
|
|
|
log.SetFlags(0)
|
|
|
|
log.SetOutput(w)
|
2024-06-07 18:42:52 +08:00
|
|
|
fs.LogOutput = func(level fs.LogLevel, text string) {
|
2017-02-10 21:28:06 +08:00
|
|
|
switch level {
|
2018-01-13 00:30:54 +08:00
|
|
|
case fs.LogLevelEmergency:
|
2017-02-10 21:28:06 +08:00
|
|
|
_ = w.Emerg(text)
|
2018-01-13 00:30:54 +08:00
|
|
|
case fs.LogLevelAlert:
|
2017-02-10 21:28:06 +08:00
|
|
|
_ = w.Alert(text)
|
2018-01-13 00:30:54 +08:00
|
|
|
case fs.LogLevelCritical:
|
2017-02-10 21:28:06 +08:00
|
|
|
_ = w.Crit(text)
|
2018-01-13 00:30:54 +08:00
|
|
|
case fs.LogLevelError:
|
2017-02-10 21:28:06 +08:00
|
|
|
_ = w.Err(text)
|
2018-01-13 00:30:54 +08:00
|
|
|
case fs.LogLevelWarning:
|
2017-02-10 21:28:06 +08:00
|
|
|
_ = w.Warning(text)
|
2018-01-13 00:30:54 +08:00
|
|
|
case fs.LogLevelNotice:
|
2017-02-10 21:28:06 +08:00
|
|
|
_ = w.Notice(text)
|
2018-01-13 00:30:54 +08:00
|
|
|
case fs.LogLevelInfo:
|
2017-02-10 21:28:06 +08:00
|
|
|
_ = w.Info(text)
|
2018-01-13 00:30:54 +08:00
|
|
|
case fs.LogLevelDebug:
|
2017-02-10 21:28:06 +08:00
|
|
|
_ = w.Debug(text)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true
|
|
|
|
}
|