mirror of
https://github.com/rclone/rclone.git
synced 2024-11-29 03:45:25 +01:00
log: add object and objectType to json logs
This commit is contained in:
parent
c2635e39cc
commit
94ee43fe54
40
fs/log.go
40
fs/log.go
@ -77,25 +77,33 @@ var LogPrint = func(level LogLevel, text string) {
|
|||||||
// LogPrintf produces a log string from the arguments passed in
|
// LogPrintf produces a log string from the arguments passed in
|
||||||
func LogPrintf(level LogLevel, o interface{}, text string, args ...interface{}) {
|
func LogPrintf(level LogLevel, o interface{}, text string, args ...interface{}) {
|
||||||
out := fmt.Sprintf(text, args...)
|
out := fmt.Sprintf(text, args...)
|
||||||
|
|
||||||
|
if Config.UseJSONLog {
|
||||||
|
fields := logrus.Fields{}
|
||||||
|
if o != nil {
|
||||||
|
fields = logrus.Fields{
|
||||||
|
"object": fmt.Sprintf("%+v", o),
|
||||||
|
"objectType": fmt.Sprintf("%T", o),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
switch level {
|
||||||
|
case LogLevelDebug:
|
||||||
|
logrus.WithFields(fields).Debug(out)
|
||||||
|
case LogLevelInfo:
|
||||||
|
logrus.WithFields(fields).Info(out)
|
||||||
|
case LogLevelNotice, LogLevelWarning:
|
||||||
|
logrus.WithFields(fields).Warn(out)
|
||||||
|
case LogLevelError:
|
||||||
|
logrus.WithFields(fields).Error(out)
|
||||||
|
case LogLevelCritical:
|
||||||
|
logrus.WithFields(fields).Fatal(out)
|
||||||
|
case LogLevelEmergency, LogLevelAlert:
|
||||||
|
logrus.WithFields(fields).Panic(out)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
if o != nil {
|
if o != nil {
|
||||||
out = fmt.Sprintf("%v: %s", o, out)
|
out = fmt.Sprintf("%v: %s", o, 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)
|
LogPrint(level, out)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user