Documentation ¶
Index ¶
- func FromStruct(s interface{}) logrus.Fields
- func Get(ctx context.Context) logrus.FieldLogger
- func GetSubsystem(ctx context.Context) string
- func PrettyPrint(v interface{}) string
- func Start(ctx context.Context, subsystem string, opts ...ContextOption) context.Context
- func Update(ctx context.Context, opts ...ContextOption) context.Context
- func WithField(ctx context.Context, key string, value interface{}) context.Context
- func WithFields(ctx context.Context, fields logrus.Fields) context.Context
- type ContextOption
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func FromStruct ¶
FromStruct converts any struct into a valid logrus.Fields. It can be customized with the logfield annotation:
type Instance struct { InstanceID string `logfield:"instance-id"` InstanceName string `logfield:"instance-name"` }
See mapstructure docs for more information: https://pkg.go.dev/github.com/mitchellh/mapstructure?tab=doc
func Get ¶
func Get(ctx context.Context) logrus.FieldLogger
Get extracts the current logger from the given context. It returns the standard logger, if there is no logger in the context.
func GetSubsystem ¶ added in v8.1.0
GetSubsystem extracts the name of the subsystem from the given context.
func PrettyPrint ¶
func PrettyPrint(v interface{}) string
PrettyPrint prints the given struct in a readable form. It tries JSON first, and if it fails it falls back to fmt.Sprintf.
func Start ¶
Start creates a new logger and stores it in the returned context. Additionally it creates a new trace ID and injects them into the new logger together with previous trace IDs from the given context.
func Update ¶
func Update(ctx context.Context, opts ...ContextOption) context.Context
Update creates a new context with an updated logger.
Types ¶
type ContextOption ¶
type ContextOption func(meta) meta
ContextOption is used for modifying a logger.
func Field ¶
func Field(key string, value interface{}) ContextOption
Field is a ContextOption that sets a single field to the logger.
func Fields ¶
func Fields(fields logrus.Fields) ContextOption
Fields is a ContextOption that sets the given fields to the logger.