From 12a208a88094cd2a32e4398a3ec511750fdf359f Mon Sep 17 00:00:00 2001 From: reddi Date: Sat, 15 Feb 2020 22:21:01 +0100 Subject: [PATCH] fs: expand stats output for json log --- fs/accounting/stats.go | 8 +++++++- fs/log.go | 5 +++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/fs/accounting/stats.go b/fs/accounting/stats.go index 00423a46c..33bd690d2 100644 --- a/fs/accounting/stats.go +++ b/fs/accounting/stats.go @@ -375,7 +375,13 @@ func (s *StatsInfo) Transferred() []TransferSnapshot { // Log outputs the StatsInfo to the log func (s *StatsInfo) Log() { - fs.LogLevelPrintf(fs.Config.StatsLogLevel, nil, "%v\n", s) + if fs.Config.UseJSONLog { + out, _ := s.RemoteStats() + fs.LogLevelPrintf(fs.Config.StatsLogLevel, nil, "%T\n", map[string]interface{}(out)) + } else { + fs.LogLevelPrintf(fs.Config.StatsLogLevel, nil, "%v\n", s) + } + } // Bytes updates the stats for bytes bytes diff --git a/fs/log.go b/fs/log.go index 68f09e9cc..785866e23 100644 --- a/fs/log.go +++ b/fs/log.go @@ -3,6 +3,7 @@ package fs import ( "fmt" "log" + "strings" "github.com/pkg/errors" "github.com/sirupsen/logrus" @@ -86,6 +87,10 @@ func LogPrintf(level LogLevel, o interface{}, text string, args ...interface{}) "objectType": fmt.Sprintf("%T", o), } } + if strings.HasPrefix(out, "map[") { + fields["json"] = args[0] + out = "" + } switch level { case LogLevelDebug: logrus.WithFields(fields).Debug(out)