mirror of
https://github.com/grafana/grafana.git
synced 2025-07-31 23:12:30 +08:00
Backend plugins: Log wrapper args formatting (#20514)
Backend plugins is recommended to use hclog with json formatting to get proper log output in grafana server log. Old hclog-wrapper.go that I deleted while back is still in the repo so deletes that.
This commit is contained in:

committed by
GitHub

parent
ec18e2bfc3
commit
58b7958952
@ -13,20 +13,41 @@ type logWrapper struct {
|
||||
Logger glog.Logger
|
||||
}
|
||||
|
||||
func formatArgs(args ...interface{}) []interface{} {
|
||||
if len(args) == 0 || len(args)%2 != 0 {
|
||||
return args
|
||||
}
|
||||
|
||||
res := []interface{}{}
|
||||
|
||||
for n := 0; n < len(args); n = n + 2 {
|
||||
key := args[n]
|
||||
|
||||
if stringKey, ok := key.(string); ok && stringKey == "timestamp" {
|
||||
continue
|
||||
}
|
||||
|
||||
res = append(res, key)
|
||||
res = append(res, args[n+1])
|
||||
}
|
||||
|
||||
return res
|
||||
}
|
||||
|
||||
func (lw logWrapper) Trace(msg string, args ...interface{}) {
|
||||
lw.Logger.Debug(msg, args...)
|
||||
lw.Logger.Debug(msg, formatArgs(args...)...)
|
||||
}
|
||||
func (lw logWrapper) Debug(msg string, args ...interface{}) {
|
||||
lw.Logger.Debug(msg, args...)
|
||||
lw.Logger.Debug(msg, formatArgs(args...)...)
|
||||
}
|
||||
func (lw logWrapper) Info(msg string, args ...interface{}) {
|
||||
lw.Logger.Info(msg, args...)
|
||||
lw.Logger.Info(msg, formatArgs(args...)...)
|
||||
}
|
||||
func (lw logWrapper) Warn(msg string, args ...interface{}) {
|
||||
lw.Logger.Warn(msg, args...)
|
||||
lw.Logger.Warn(msg, formatArgs(args...)...)
|
||||
}
|
||||
func (lw logWrapper) Error(msg string, args ...interface{}) {
|
||||
lw.Logger.Error(msg, args...)
|
||||
lw.Logger.Error(msg, formatArgs(args...)...)
|
||||
}
|
||||
|
||||
func (lw logWrapper) IsTrace() bool { return true }
|
||||
|
Reference in New Issue
Block a user