logrus

package
v0.0.0-...-80b5034 Latest Latest
Warning

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

Go to latest
Published: Feb 1, 2025 License: BSD-3-Clause Imports: 16 Imported by: 29

Documentation

Index

Constants

View Source
const (

	// EntryPropertyIgnoreFields means the provided fields in types.Entry.Fields should be
	// ignored by Emitter.LogEntry.
	//
	// This property is used when the fields are already set in the logrus.Entry and therefore
	// it is just an optimization (to avoid useless calculations and memory allocations).
	EntryPropertyIgnoreFields
)

Variables

View Source
var DefaultLogrusLogger = func() *logrus.Logger {
	l := logrus.New()
	l.Formatter = &logrus.TextFormatter{
		CallerPrettyfier: func(caller *runtime.Frame) (string, string) {
			return "", fmt.Sprintf("%s:%d", filepath.Base(caller.File), caller.Line)
		},
	}
	return l
}

DefaultLogrusLogger returns a logrus logger with the default configuration.

The configuration might be changed in future.

Overwritable.

Do not override this anywhere but in the `main` package.

View Source
var (
	// FieldNameTraceIDs is the field name used to store trace IDs.
	FieldNameTraceIDs = "trace_id"
)
View Source
var LogrusCtxKeyCaller = logrusCtxKeyCallerT{}

Functions

func Default

func Default() types.Logger

Default returns a types.Logger based on logrus, using the default configuration.

The configuration might be changed in future. Use this function if you would like to delegate logger configuration to somebody else and you do not rely on specific output format.

func LevelFromLogrus

func LevelFromLogrus(level logrus.Level) types.Level

LevelFromLogrus maps logrus.Level into types.Level

func LevelToLogrus

func LevelToLogrus(level types.Level) logrus.Level

LevelToLogrus maps types.Level into logrus.Level

func New

func New(logger *logrus.Logger, opts ...types.Option) types.Logger

New returns a types.Logger implementation based on a logrus Logger.

This function takes ownership of the logger instance.

Types

type CompactLogger

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

CompactLogger implements types.CompactLogger given a logrus logger.

func (*CompactLogger) Emitter

func (l *CompactLogger) Emitter() types.Emitter

Emitter implements types.Emitter

func (*CompactLogger) Flush

func (l *CompactLogger) Flush()

Flush implements types.CompactLogger

func (*CompactLogger) Level

func (l *CompactLogger) Level() types.Level

Level implements types.CompactLogger

func (*CompactLogger) Log

func (l *CompactLogger) Log(level types.Level, values ...any)

Log implements types.CompactLogger

func (*CompactLogger) LogEntry

func (l *CompactLogger) LogEntry(entry *types.Entry)

LogEntry logs the given entry.

func (*CompactLogger) LogFields

func (l *CompactLogger) LogFields(level types.Level, message string, fields field.AbstractFields)

LogFields implements types.CompactLogger

func (*CompactLogger) Logf

func (l *CompactLogger) Logf(level types.Level, format string, args ...any)

Logf implements types.CompactLogger

func (*CompactLogger) WithContextFields

func (l *CompactLogger) WithContextFields(allFields *field.FieldsChain, newFieldsCount int) belt.Tool

WithContextFields implements types.Tool

func (*CompactLogger) WithEntryProperties

func (l *CompactLogger) WithEntryProperties(props ...types.EntryProperty) adapter.CompactLogger

WithEntryProperties implements types.CompactLogger.

func (*CompactLogger) WithField

func (l *CompactLogger) WithField(
	key field.Key,
	value field.Value,
	props ...field.Property,
) adapter.CompactLogger

WithField implements types.CompactLogger

func (*CompactLogger) WithFields

func (l *CompactLogger) WithFields(fields field.AbstractFields) adapter.CompactLogger

WithFields implements types.CompactLogger

func (*CompactLogger) WithHooks

func (l *CompactLogger) WithHooks(hooks ...types.Hook) adapter.CompactLogger

WithHooks implements types.CompactLogger

func (*CompactLogger) WithLevel

func (l *CompactLogger) WithLevel(newLevel types.Level) adapter.CompactLogger

WithLevel implements types.CompactLogger

func (*CompactLogger) WithMessagePrefix

func (l *CompactLogger) WithMessagePrefix(prefix string) adapter.CompactLogger

WithMessagePrefix implements types.CompactLogger

func (*CompactLogger) WithPreHooks

func (l *CompactLogger) WithPreHooks(preHooks ...types.PreHook) adapter.CompactLogger

WithPreHooks implements types.CompactLogger

func (*CompactLogger) WithTraceIDs

func (l *CompactLogger) WithTraceIDs(allTraceIDs belt.TraceIDs, newTraceIDsCount int) belt.Tool

WithTraceIDs implements types.CompactLogger

type Emitter

type Emitter struct {
	// LogrusEntry is the actual emitter. And Emitter structure is only a wrapper
	// to implement another interface based on logrus.Entry.
	//
	// We use logrus.Entry instead of logrus.Logger to be able to store precompiled fields
	LogrusEntry *logrus.Entry
}

Emitter implements types.Emitter given a logrus entry.

func NewEmitter

func NewEmitter(logger *logrus.Logger, logLevel logger.Level) *Emitter

NewEmitter returns a new types.Emitter implementation based on a logrus logger. This functions takes ownership of the logrus Logger instance.

func (*Emitter) CheckLevel

func (l *Emitter) CheckLevel(level types.Level) bool

CheckLevel returns true if an event of a given logging level will be logged

func (*Emitter) Emit

func (l *Emitter) Emit(entry *types.Entry)

Emit implements types.Emitter

func (*Emitter) Flush

func (l *Emitter) Flush()

Flush implements types.Emitter

type EntryProperty

type EntryProperty uint

EntryProperty is a type of values which could be used in field types.Entry.Properties.

type RestoreCallerHook

type RestoreCallerHook struct{}

RestoreCallerHook is a logrus.Hook which sets the Caller from a Context.

func (RestoreCallerHook) Fire

func (RestoreCallerHook) Fire(entry *logrus.Entry) error

func (RestoreCallerHook) Levels

func (RestoreCallerHook) Levels() []logrus.Level

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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