Documentation
¶
Index ¶
- Constants
- Variables
- func Default() types.Logger
- func LevelFromLogrus(level logrus.Level) types.Level
- func LevelToLogrus(level types.Level) logrus.Level
- func New(logger *logrus.Logger, opts ...types.Option) types.Logger
- type CompactLogger
- func (l *CompactLogger) Emitter() types.Emitter
- func (l *CompactLogger) Flush()
- func (l *CompactLogger) Level() types.Level
- func (l *CompactLogger) Log(level types.Level, values ...any)
- func (l *CompactLogger) LogEntry(entry *types.Entry)
- func (l *CompactLogger) LogFields(level types.Level, message string, fields field.AbstractFields)
- func (l *CompactLogger) Logf(level types.Level, format string, args ...any)
- func (l *CompactLogger) WithContextFields(allFields *field.FieldsChain, newFieldsCount int) belt.Tool
- func (l *CompactLogger) WithEntryProperties(props ...types.EntryProperty) adapter.CompactLogger
- func (l *CompactLogger) WithField(key field.Key, value field.Value, props ...field.Property) adapter.CompactLogger
- func (l *CompactLogger) WithFields(fields field.AbstractFields) adapter.CompactLogger
- func (l *CompactLogger) WithHooks(hooks ...types.Hook) adapter.CompactLogger
- func (l *CompactLogger) WithLevel(newLevel types.Level) adapter.CompactLogger
- func (l *CompactLogger) WithMessagePrefix(prefix string) adapter.CompactLogger
- func (l *CompactLogger) WithPreHooks(preHooks ...types.PreHook) adapter.CompactLogger
- func (l *CompactLogger) WithTraceIDs(allTraceIDs belt.TraceIDs, newTraceIDsCount int) belt.Tool
- type Emitter
- type EntryProperty
- type RestoreCallerHook
Constants ¶
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 ¶
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.
var (
// FieldNameTraceIDs is the field name used to store trace IDs.
FieldNameTraceIDs = "trace_id"
)
var LogrusCtxKeyCaller = logrusCtxKeyCallerT{}
Functions ¶
func Default ¶
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 ¶
LevelFromLogrus maps logrus.Level into types.Level
func LevelToLogrus ¶
LevelToLogrus maps types.Level into logrus.Level
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) 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 ¶
NewEmitter returns a new types.Emitter implementation based on a logrus logger. This functions takes ownership of the logrus Logger instance.
func (*Emitter) CheckLevel ¶
CheckLevel returns true if an event of a given logging level will be logged
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) Levels ¶
func (RestoreCallerHook) Levels() []logrus.Level