logutil

package
v5.0.0 Latest Latest
Warning

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

Go to latest
Published: Apr 21, 2023 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FromStruct

func FromStruct(s interface{}) logrus.Fields

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

Get extracts the current logger from the given context. It returns the standard logger, if there is no logger in the 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

func Start(ctx context.Context, subsystem string, opts ...ContextOption) context.Context

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.

func WithField

func WithField(ctx context.Context, key string, value interface{}) context.Context

WithField is a shortcut for using the Update function with a single Field option.

func WithFields

func WithFields(ctx context.Context, fields logrus.Fields) context.Context

WithFields is a shortcut for using the Update function with a single Fields option.

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.

Jump to

Keyboard shortcuts

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