Documentation
¶
Overview ¶
Package ecslogrus provides a formatter to be used with the github.com/sirupsen/logrus logger library that helps creating Elastic Common Schema (ECS) conformant log entries.
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Formatter ¶
type Formatter struct { // DisableHTMLEscape allows disabling html escaping in output DisableHTMLEscape bool // DataKey allows users to put all the log entry parameters into a // nested dictionary at a given key. // // DataKey is ignored for well-defined fields, such as "error", // which will instead be stored under the appropriate ECS fields. DataKey string // CallerPrettyfier can be set by the user to modify the content // of the function and file keys in the json data when ReportCaller is // activated. If any of the returned value is the empty string the // corresponding key will be removed from json fields. CallerPrettyfier func(*runtime.Frame) (function string, file string) // PrettyPrint will indent all json logs PrettyPrint bool }
Formatter is a logrus.Formatter, formatting log entries as ECS-compliant JSON.
Example ¶
package main import ( "os" "time" "github.com/sirupsen/logrus" "go.elastic.co/ecslogrus" ) func main() { log := logrus.New() log.SetOutput(os.Stdout) log.SetFormatter(&ecslogrus.Formatter{}) epoch := time.Unix(0, 0).UTC() log.WithTime(epoch).WithField("custom", "foo").Info("hello") }
Output: {"@timestamp":"1970-01-01T00:00:00.000Z","custom":"foo","ecs.version":"1.6.0","log.level":"info","message":"hello"}
Click to show internal directories.
Click to hide internal directories.