mirror of
https://github.com/minio/minio.git
synced 2025-01-11 23:13:23 -05:00
Fix logrus error message logging
This commit is contained in:
parent
c3aa35424e
commit
bf8b8981bf
15
logger.go
15
logger.go
@ -18,6 +18,7 @@ package main
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
|
"reflect"
|
||||||
|
|
||||||
"github.com/Sirupsen/logrus"
|
"github.com/Sirupsen/logrus"
|
||||||
"github.com/minio/minio/pkg/probe"
|
"github.com/minio/minio/pkg/probe"
|
||||||
@ -48,10 +49,16 @@ func errorIf(err *probe.Error, msg string, fields map[string]interface{}) {
|
|||||||
if fields == nil {
|
if fields == nil {
|
||||||
fields = make(map[string]interface{})
|
fields = make(map[string]interface{})
|
||||||
}
|
}
|
||||||
|
fields["Error"] = struct {
|
||||||
fields["error"] = err.ToGoError()
|
Cause string `json:"cause,omitempty"`
|
||||||
if jsonErr, e := json.Marshal(err); e == nil {
|
Type string `json:"type,omitempty"`
|
||||||
fields["probe"] = string(jsonErr)
|
CallTrace []probe.TracePoint `json:"trace,omitempty"`
|
||||||
|
SysInfo map[string]string `json:"sysinfo,omitempty"`
|
||||||
|
}{
|
||||||
|
err.Cause.Error(),
|
||||||
|
reflect.TypeOf(err.Cause).String(),
|
||||||
|
err.CallTrace,
|
||||||
|
err.SysInfo,
|
||||||
}
|
}
|
||||||
log.WithFields(fields).Error(msg)
|
log.WithFields(fields).Error(msg)
|
||||||
}
|
}
|
||||||
|
@ -42,10 +42,7 @@ func (s *LoggerSuite) TestLogger(c *C) {
|
|||||||
c.Assert(err, IsNil)
|
c.Assert(err, IsNil)
|
||||||
c.Assert(fields["level"], Equals, "error")
|
c.Assert(fields["level"], Equals, "error")
|
||||||
|
|
||||||
msg, ok := fields["error"]
|
msg, ok := fields["Error"]
|
||||||
c.Assert(ok, Equals, true)
|
|
||||||
c.Assert(msg, Equals, "Fake error")
|
|
||||||
|
|
||||||
_, ok = fields["probe"]
|
|
||||||
c.Assert(ok, Equals, true)
|
c.Assert(ok, Equals, true)
|
||||||
|
c.Assert(msg.(map[string]interface{})["cause"], Equals, "Fake error")
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user