Created
February 17, 2021 09:54
-
-
Save mesuutt/56672ce413660f17f445a39ea49d36c8 to your computer and use it in GitHub Desktop.
This file contains 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 characters
// 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() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment