clog

package
v0.0.0-...-6170df9 Latest Latest
Warning

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

Go to latest
Published: Feb 7, 2025 License: MIT, MIT Imports: 10 Imported by: 1

Documentation

Index

Constants

View Source
const (
	// ServiceKey is the log entry key for the name of the crpc service
	ServiceKey = "_service"

	// HostKey is the log entry key for the hostname / container ID
	HostKey = "_hostname"

	// VersionKey is the log entry key for the current version of the codebase
	VersionKey = "_commit_hash"

	// LevelKey is the log entry key for the log level
	LevelKey = "_level"

	// MessageKey is the log entry key for a generic message
	MessageKey = "_message"

	// TimestampKey is the log entry key for the timestamp
	TimestampKey = "_timestamp"
)

Variables

This section is empty.

Functions

func ConfigureTimeoutsAsErrors

func ConfigureTimeoutsAsErrors(ctx context.Context)

ConfigureTimeoutsAsErrors changes to default behaviour of logging timeouts as info, to log them as errors

func DetermineLevel

func DetermineLevel(err error, timeoutsAsErrors bool) logrus.Level

DetermineLevel returns a suggested logrus Level type for a given error

func Get

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

Get retrieves the logrus Entry from the ContextLogger in a context and returns a new logrus Entry if none is found

func HandlePanic

func HandlePanic(ctx context.Context, propagate bool)

HandlePanic structurally logs a panic before optionally propagating.

Propagating a panic can be important for cases like calls made via net/http where the whole process isn't required to fail because one request panics. Propagating makes sure we dont disturb upstream panic handling.

func Set

func Set(ctx context.Context, log *logrus.Entry) context.Context

Set sets a persistent, mutable logger for the request context.

func SetError

func SetError(ctx context.Context, err error)

SetError adds or updates an error to the ContextLogger in a context

func SetField

func SetField(ctx context.Context, field string, value any)

SetField adds or updates a field to the ContextLogger in a context

func SetFields

func SetFields(ctx context.Context, fields Fields)

SetFields adds or updates fields to the ContextLogger in a context

func TimeoutsAsErrors

func TimeoutsAsErrors(ctx context.Context) bool

TimeoutsAsErrors determines whether ConfigureTimeoutsAsErrors was called on the context

Types

type Config

type Config struct {
	// Format configures the output format. Possible options:
	//   - text - logrus default text output, good for local development
	//   - json - fields and message encoded as json, good for storage in e.g. cloudwatch
	Format string `json:"format"`

	// Debug enables debug level logging, otherwise INFO level
	Debug bool `json:"debug"`
}

Config allows services to configure the logging format, level and storage options for Logrus logging.

func (Config) Configure

func (c Config) Configure(ctx context.Context) *logrus.Entry

Configure applies standard Logging structure options to a logrus Entry.

type ContextLogger

type ContextLogger struct {
	// contains filtered or unexported fields
}

ContextLogger wraps logrus Entry to allow field mutation, which means the context itself can store a pointer to a ContextLogger, so it doesn't need replacing each time new fields are added to the logger

func NewContextLogger

func NewContextLogger(log *logrus.Entry) *ContextLogger

NewContextLogger creates a new (mutable) ContextLogger instance from an (immutable) logrus Entry

func (*ContextLogger) GetLogger

func (l *ContextLogger) GetLogger() *logrus.Entry

GetLogger returns (an immutable) logrus entry from a (mutable) ContextLogger instance

func (*ContextLogger) SetError

func (l *ContextLogger) SetError(err error) *ContextLogger

SetError updates the internal error

func (*ContextLogger) SetField

func (l *ContextLogger) SetField(field string, value any) *ContextLogger

SetField updates the internal field map

func (*ContextLogger) SetFields

func (l *ContextLogger) SetFields(fields logrus.Fields) *ContextLogger

SetFields updates the internal field map with multiple fields at a time

type Fields

type Fields map[string]any

Jump to

Keyboard shortcuts

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