Documentation
¶
Index ¶
- Constants
- func ConfigureTimeoutsAsErrors(ctx context.Context)
- func DetermineLevel(err error, timeoutsAsErrors bool) logrus.Level
- func Get(ctx context.Context) *logrus.Entry
- func HandlePanic(ctx context.Context, propagate bool)
- func Set(ctx context.Context, log *logrus.Entry) context.Context
- func SetError(ctx context.Context, err error)
- func SetField(ctx context.Context, field string, value any)
- func SetFields(ctx context.Context, fields Fields)
- func TimeoutsAsErrors(ctx context.Context) bool
- type Config
- type ContextLogger
- type Fields
Constants ¶
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 ¶
ConfigureTimeoutsAsErrors changes to default behaviour of logging timeouts as info, to log them as errors
func DetermineLevel ¶
DetermineLevel returns a suggested logrus Level type for a given error
func Get ¶
Get retrieves the logrus Entry from the ContextLogger in a context and returns a new logrus Entry if none is found
func HandlePanic ¶
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 TimeoutsAsErrors ¶
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.
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