Documentation
¶
Overview ¶
Package logctx adds contextual logging to logrus.
Example ¶
package main import ( "context" "os" log "github.com/sirupsen/logrus" "github.com/go-logrusutil/logrusutil/logctx" ) func main() { log.SetOutput(os.Stdout) log.SetFormatter(&log.TextFormatter{DisableTimestamp: true}) // setting contextual log entry ctx := logctx.New(context.Background(), log.WithField("foo", "bar")) // adding additional log field ctx = logctx.AddField(ctx, "bizz", "buzz") // retrieving context log entry, adding some data and emitting the log logctx.From(ctx).Info("hello world") }
Output: level=info msg="hello world" bizz=buzz foo=bar
Example (Default) ¶
package main import ( "context" "os" log "github.com/sirupsen/logrus" "github.com/go-logrusutil/logrusutil/logctx" ) func main() { log.SetOutput(os.Stdout) log.SetFormatter(&log.TextFormatter{DisableTimestamp: true}) // set the default log entry logctx.Default = log.WithField("foo", "bar") // get a log entry from context for which a contextual entry was not set logctx.From(context.Background()).Info("hello world") }
Output: level=info msg="hello world" foo=bar
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var Default = logrus.NewEntry(logrus.StandardLogger())
Default is used to create a new log entry if there is none in the context.
Functions ¶
Types ¶
This section is empty.
Click to show internal directories.
Click to hide internal directories.