mirror of
https://github.com/rclone/rclone.git
synced 2025-08-18 17:38:52 +02:00
log: add --use-json-log for JSON logging
This commit is contained in:
committed by
Nick Craig-Wood
parent
a3449bda30
commit
520fb03bfd
20
fs/log.go
20
fs/log.go
@@ -5,6 +5,7 @@ import (
|
||||
"log"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
"github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
// LogLevel describes rclone's logs. These are a subset of the syslog log levels.
|
||||
@@ -79,7 +80,24 @@ func LogPrintf(level LogLevel, o interface{}, text string, args ...interface{})
|
||||
if o != nil {
|
||||
out = fmt.Sprintf("%v: %s", o, out)
|
||||
}
|
||||
LogPrint(level, out)
|
||||
if Config.UseJSONLog {
|
||||
switch level {
|
||||
case LogLevelDebug:
|
||||
logrus.Debug(out)
|
||||
case LogLevelInfo:
|
||||
logrus.Info(out)
|
||||
case LogLevelNotice, LogLevelWarning:
|
||||
logrus.Warn(out)
|
||||
case LogLevelError:
|
||||
logrus.Error(out)
|
||||
case LogLevelCritical:
|
||||
logrus.Fatal(out)
|
||||
case LogLevelEmergency, LogLevelAlert:
|
||||
logrus.Panic(out)
|
||||
}
|
||||
} else {
|
||||
LogPrint(level, out)
|
||||
}
|
||||
}
|
||||
|
||||
// LogLevelPrintf writes logs at the given level
|
||||
|
Reference in New Issue
Block a user