Created
February 17, 2021 09:54
-
-
Save mesuutt/56672ce413660f17f445a39ea49d36c8 to your computer and use it in GitHub Desktop.
Revisions
-
mesuutt created this gist
Feb 17, 2021 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,33 @@ // formatter adds default fields to each log entry. https://github.com/sirupsen/logrus/pull/653#issuecomment-454467900 type formatter struct { Fields logrus.Fields Lf logrus.Formatter } // Format satisfies the logrus.Formatter interface. func (f *formatter) Format(e *logrus.Entry) ([]byte, error) { for k, v := range f.Fields { e.Data[k] = v } return f.Lf.Format(e) } // Set logrus global logger logrus.SetFormatter(&formatter{ Fields: logrus.Fields{ "facility": "myApp", }, Lf: &logrus.JSONFormatter{ FieldMap: logrus.FieldMap{ logrus.FieldKeyMsg: "message", }, TimestampFormat: time.RFC3339Nano, }, }) // logrus.AddHook(hook) myLogger := logrus.StandardLogger()