Documentation ¶
Overview ¶
Package logutil is a utility package for github.com/sirupsen/logrus.
Index ¶
Examples ¶
Constants ¶
View Source
const ( // ComponentKey is the field key used to store the component name. ComponentKey = "component" // MethodKey is the field key used to store the methodname. MethodKey = "method" )
Variables ¶
This section is empty.
Functions ¶
func AddComponent ¶ added in v0.3.0
AddComponent appends the component name to the logrus.Entry.
Example ¶
l := logrus.New() l.SetOutput(os.Stdout) l.SetFormatter(_logrusFormatter) log := logrus.NewEntry(l) log1 := logutil.AddComponent(log, (*Component1)(nil)) log1.Info("Added first component.") log2 := logutil.AddComponent(log1, (*Component2)(nil)) log2.Info("Added second component.") log1.Info("First logger components unchanged.")
Output: level=info msg="Added first component." component=logutil_test.Component1 level=info msg="Added second component." component="[logutil_test.Component1 logutil_test.Component2]" level=info msg="First logger components unchanged." component=logutil_test.Component1
func NoopEntry ¶
NoopEntry returns a no-op logrus.NoopEntry.
Example ¶
package main import ( "os" "github.com/sirupsen/logrus" "go.stevenxie.me/gopkg/logutil" ) var _logrusFormatter = &logrus.TextFormatter{DisableTimestamp: true} func main() { // Regular logger will produce output. log := logrus.New() log.SetOutput(os.Stdout) log.SetFormatter(_logrusFormatter) log.WithField("kind", "default").Info("Oh-ho, who's this?") // No-op logger will not produce output. noopLog := logutil.NoopLogger() noopLog.SetFormatter(_logrusFormatter) noopLog.WithField("kind", "noop").Info("Hey, it's a-me.") }
Output: level=info msg="Oh-ho, who's this?" kind=default
func WithMethod ¶ added in v0.3.0
WithMethod adds the name of the method v to the logrus.Entry.
Example ¶
l := logrus.New() l.SetOutput(os.Stdout) l.SetFormatter(_logrusFormatter) ss := SomeStruct{log: logrus.NewEntry(l)} ss.LogWithMethod()
Output: level=info msg="Hello from method!" method=LogWithMethod
Types ¶
This section is empty.
Click to show internal directories.
Click to hide internal directories.