Documentation ¶
Overview ¶
Package logutil is a utility package for github.com/sirupsen/logrus.
Index ¶
- Constants
- func NewLogger(opts ...Option) (*logrus.Entry, error)
- func NoopEntry() *logrus.Entry
- func NoopLogger() *logrus.Logger
- func WithComponent(e *logrus.Entry, component string) *logrus.Entry
- func WithMethod(e *logrus.Entry, v zero.Interface) *logrus.Entry
- func WithSource(e *logrus.Entry, v zero.Interface) *logrus.Entry
- type Config
- type Format
- type Option
Examples ¶
Constants ¶
const ( // SourceKey is the field key used to store the type name of the logging // source. SourceKey = "source" // MethodKey is the field key used to store the method name where the logger // is being called. MethodKey = "method" // ComponentKey is the field key used to store the logging object's component // path. ComponentKey = "component" )
Variables ¶
This section is empty.
Functions ¶
func NewLogger ¶ added in v0.6.2
NewLogger creates an application-level logrus.Entry.
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 WithComponent ¶ added in v0.2.2
WithComponent appends the component to the component path field of the logrus.Entry.
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 ¶
type Config ¶ added in v0.6.2
type Config struct { // Logging options. Level logrus.Level ReportCaller bool // Output options. Output io.Writer Format Format TextFormatter logrus.TextFormatter JSONFormatter logrus.JSONFormatter // Extension options. Raven *raven.Client }
A Config configures a logrus.Logger.
type Format ¶ added in v0.6.2
type Format uint8
A Format represents an output formatting type for Logrus.
func ParseFormat ¶ added in v0.6.3
ParseFormat parses a Format from the string fmt.
type Option ¶ added in v0.6.2
type Option func(*Config)
A Option modifies a LogrusConfig.
func WithCaller ¶ added in v0.6.3
WithCaller configures a logrus.Logger to report callers.
func WithFormat ¶ added in v0.6.3
WithFormat configures the output format of a logrus.Logger.
func WithLevel ¶ added in v0.6.3
WithLevel configures a logrus.Logger to log at lvl.
func WithLevelString ¶ added in v0.6.3
WithLevelString is like LogrusWithLevel, but parses the level from lvl.
It panics if lvl is an invalid logrus.Level.
func WithOutput ¶ added in v0.6.3
WithOutput configures a logrus.Logger to write to output.