Open fizyk opened 4 years ago
I checked and problem lays in different behavior for certain levels (severityError, severityCritical, severityAlert) (https://github.com/TV4/logrus-stackdriver-formatter/blob/master/formatter.go#L150)
Those threat error
field specially.
For any other logging level, any error-typed
value is just passed within context
object (context.Data
to be specific) to json.Marshal
(https://github.com/TV4/logrus-stackdriver-formatter/blob/master/formatter.go#L187) which just ignores error-typed values (but keeps keys)
example of such behaviour can be found here: https://play.golang.org/p/pVFYjn1BoL7
So potential fix would be to find all error-typed values and convert them into string using .Error()
or require from user to use MarshalJSON()
-able objects that fulfill error
interface as well.
(example of such custom error https://play.golang.org/p/Z7YNNl6lNZE)
Example of proposed custom type working with logrus.WithError(...).Warn(...)
can be found here: https://play.golang.org/p/wOziKs36nRU
When using WithError alog with Warn and below, the formatter leaves the error key in data, but strips the error message leaving an empty string.
Console output