Logrus: Is it possible to override the default `msg` field to be `message`?

Created on 2 Jun 2020  路  3Comments  路  Source: sirupsen/logrus

I see FieldKeyMsg is set here... https://github.com/sirupsen/logrus/blob/master/formatter.go#L8 ...to msg, and I would like it to be set to message but as it's a constant I'm not able to change it and I'm not sure the 'custom formatter' feature allows for changing it either.

Thanks for any guidance you can give me.

EDIT

The reason I ask is because I'm using Datadog and they require the logged field to be message.

question

Most helpful comment

Something like that should work:

formatter := &logrus.JSONFormatter{
    FieldMap: logrus.FieldMap{
        FieldKeyMsg: "message",
    }
},

logrus.SetFormatter(formatter)

All 3 comments

you can use the FieldMap configuration of the JSONFormatter to specify how to name the FieldKeyMsg. You can look at the documentation of the JSONFormatter to see an example.

Something like that should work:

formatter := &logrus.JSONFormatter{
    FieldMap: logrus.FieldMap{
        FieldKeyMsg: "message",
    }
},

logrus.SetFormatter(formatter)

Perfect! Thanks @dgsb

Was this page helpful?
0 / 5 - 0 ratings