fs: Remove github.com/sirupsen/logrus and replace with log/slog

This removes logrus which is not developed any more and replaces it
with the new log/slog from the Go standard library.

It implements its own slog Handler which is backwards compatible with
all of rclone's previous logging modes.
This commit is contained in:
Nick Craig-Wood
2025-05-12 15:18:11 +01:00
parent 36b89960e3
commit dfa4d94827
17 changed files with 931 additions and 322 deletions

View File

@@ -5,7 +5,7 @@
package log
import (
"log"
"log/slog"
"log/syslog"
"os"
"path"
@@ -39,7 +39,7 @@ var (
)
// Starts syslog
func startSysLog() bool {
func startSysLog(handler *OutputHandler) bool {
facility, ok := syslogFacilityMap[Opt.SyslogFacility]
if !ok {
fs.Fatalf(nil, "Unknown syslog facility %q - man syslog for list", Opt.SyslogFacility)
@@ -49,27 +49,27 @@ func startSysLog() bool {
if err != nil {
fs.Fatalf(nil, "Failed to start syslog: %v", err)
}
log.SetFlags(0)
log.SetOutput(w)
fs.LogOutput = func(level fs.LogLevel, text string) {
handler.clearFormatFlags(logFormatDate | logFormatTime | logFormatMicroseconds | logFormatUTC | logFormatLongFile | logFormatShortFile | logFormatPid)
handler.setFormatFlags(logFormatNoLevel)
handler.SetOutput(func(level slog.Level, text string) {
switch level {
case fs.LogLevelEmergency:
case fs.SlogLevelEmergency:
_ = w.Emerg(text)
case fs.LogLevelAlert:
case fs.SlogLevelAlert:
_ = w.Alert(text)
case fs.LogLevelCritical:
case fs.SlogLevelCritical:
_ = w.Crit(text)
case fs.LogLevelError:
case slog.LevelError:
_ = w.Err(text)
case fs.LogLevelWarning:
case slog.LevelWarn:
_ = w.Warning(text)
case fs.LogLevelNotice:
case fs.SlogLevelNotice:
_ = w.Notice(text)
case fs.LogLevelInfo:
case slog.LevelInfo:
_ = w.Info(text)
case fs.LogLevelDebug:
case slog.LevelDebug:
_ = w.Debug(text)
}
}
})
return true
}