Documentation ¶
Index ¶
- Constants
- Variables
- func ContextLog(ctx Valuer, err []error, entry *logrus.Entry) *logrus.Entry
- func GetLoggableValue(ctx Valuer, key string) interface{}
- func GetLoggableValues(ctx Valuer) logrus.Fields
- func LogIfError(ctx context.Context, fn func() error, logger Logger, msg string)
- func WatchingLoggable(ctx context.Context, l Loggable) context.Context
- func WithField(ctx context.Context, k string, v interface{}) context.Context
- func WithFields(ctx context.Context, m logrus.Fields) context.Context
- func WithLoggable(ctx context.Context, l Loggable) context.Context
- func WithUUID(ctx context.Context) (context.Context, string)
- type Loggable
- type Logger
- type Valuer
Examples ¶
Constants ¶
View Source
const UUIDKey = "uuid"
Variables ¶
View Source
var GlobalFields = logrus.Fields{}
Functions ¶
func GetLoggableValue ¶
GetLoggableValue returns the value of the metadata currently attached to the Context.
func GetLoggableValues ¶
func LogIfError ¶
LogIfError makes it less verbose to defer a Close() call while handling an unlikely-but-possible error return by logging it. Example:
defer LogIfError(ctx, f.Close, log, "failed to close file")
func WatchingLoggable ¶
WatchingLoggable attaches a Loggable to the Context. Upon logging, LogFields will be called and the fields will be attached as metadata.
Example ¶
loggable := &exampleLoggable{"foo": "bar"} ctx := context.Background() ctx = WatchingLoggable(ctx, loggable) log := New("testing") // Typically called as log(ctx, nil).Debug("the message") entry := log(ctx, nil) fmt.Printf("%+v", entry.Data["foo"])
Output: bar
func WithField ¶
WithField attaches a key-value pair to a Context. Upon logging, the pair will be attached as metadata.
Example ¶
ctx := context.Background() ctx = WithField(ctx, "foo", "bar") log := New("testing") // Typically called as log(ctx, nil).Debug("the message") entry := log(ctx, nil) fmt.Printf("%+v", entry.Data["foo"])
Output: bar
func WithFields ¶
WithFields attaches fields to a Context. Upon logging, those fields will be attached as metadata.
Example ¶
ctx := context.Background() ctx = WithFields(ctx, logrus.Fields{ "foo": "bar", }) log := New("testing") // Typically called as log(ctx, nil).Debug("the message") entry := log(ctx, nil) fmt.Printf("%+v", entry.Data["foo"])
Output: bar
func WithLoggable ¶
WithLoggable attaches a Loggable's fields to the Context. Upon logging, those fields will be attached as metadata.
Types ¶
Click to show internal directories.
Click to hide internal directories.