requestidlogger

package
v0.0.15 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 5, 2023 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FromContext

func FromContext(ctx context.Context) (zerolog.Logger, error)

FromContext retrieves a previously set logger on the supplied context. If the logger does not exist, an error is returned.

func SetOnContext

func SetOnContext(ctx context.Context, parent zerolog.Logger) (context.Context, zerolog.Logger)

SetOnContext retrieves an existing request id from the context, and sets it on the context of a child logger created from the provided parent Logger. The request id is retrieved via the functions provided by the gokit/requestid package.

If the request id is not found, an error message is logged to the parent logger, a new child context logger with the a RequestID of "NOT_FOUND" is set on the context, and the new context and logger is returned.

To retrieve the logger from the new context, use FromContext()

func UpdateLogger

func UpdateLogger(ctx context.Context, updateFunc func(logger zerolog.Context) zerolog.Context) (context.Context, error)

UpdateLogger will run the provided updateFunc on the zerolog.Logger within the context assuming it exists. It will return a new context with the updated logger. This is useful for modifying the loggers zerolog.Context without setting requestID on the logger multiple times. Similar to zerolog.Logger.UpdateContext().

If the logger isn't found this returns the passed in context along with an error.

To retrieve the updated logger from the new context, use FromContext()

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL