logging

package
v0.1.6 Latest Latest
Warning

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

Go to latest
Published: Sep 16, 2023 License: MIT Imports: 5 Imported by: 5

Documentation

Overview

Package logging provides functionality to store logrus logging Entry inside a context.Context and then retrieve it from the context.Context.

This package also provides a hook to export logs to signoz via the fluentd protocol.

If you want to set the fields of a logger to be stored in a context so the context and logger can be passed to other functions:

ctx = logging.ToContext(ctx, logrus.Fields{"foo": "bar", "val": 3})

The context returned from ToContext can then be passed to other functions where the logger can be retrieved using WithContext and the logger will be returned with all the fields intact:

logger := logging.FromContext(ctx)

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FromContext

func FromContext(ctx context.Context) *logrus.Entry

FromContext returns the a logger instance, either a newly initialised logger if one doesn't exist, a fieldless logger if the provided context is nil, or a logger retrieved from the provided context.

The ability to call FromContext with a nil context and get a clean logger instance eliminates the need for a logging.New() constructor.

func New

func New() *logrus.Logger

func ToContext

func ToContext(ctx context.Context, fields logrus.Fields) (*logrus.Entry, context.Context)

ToContext adds the provided fields to the logger returned by WithContext, then stores it in the provided context against the loggerKey key.

Types

This section is empty.

Jump to

Keyboard shortcuts

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