Documentation
¶
Index ¶
- Constants
- Variables
- func NewContext(ctx context.Context, logger Logger) context.Context
- type Builder
- func (that *Builder) Build() (*Log, error)
- func (that *Builder) WithExporter(exporter Exporter) *Builder
- func (that *Builder) WithHook(hook Hook) *Builder
- func (that *Builder) WithHookForLevel(hook Hook, level Level) *Builder
- func (that *Builder) WithHookForLevels(hook Hook, levels []Level) *Builder
- func (that *Builder) WithLevel(level Level) *Builder
- type Constructor
- type ContextMode
- type Entry
- func (that *Entry) Debug(ctx context.Context, args ...interface{})
- func (that *Entry) Debugf(ctx context.Context, format string, args ...interface{})
- func (that *Entry) Error(ctx context.Context, args ...interface{})
- func (that *Entry) Errorf(ctx context.Context, format string, args ...interface{})
- func (that *Entry) Fatal(ctx context.Context, args ...interface{})
- func (that *Entry) Fatalf(ctx context.Context, format string, args ...interface{})
- func (that *Entry) Info(ctx context.Context, args ...interface{})
- func (that *Entry) Infof(ctx context.Context, format string, args ...interface{})
- func (that *Entry) Log(ctx context.Context, level Level, args ...interface{})
- func (that *Entry) Logf(ctx context.Context, level Level, format string, args ...interface{})
- func (that *Entry) Panic(ctx context.Context, args ...interface{})
- func (that *Entry) Panicf(ctx context.Context, format string, args ...interface{})
- func (that *Entry) Trace(ctx context.Context, args ...interface{})
- func (that *Entry) Tracef(ctx context.Context, format string, args ...interface{})
- func (that *Entry) Warning(ctx context.Context, args ...interface{})
- func (that *Entry) Warningf(ctx context.Context, format string, args ...interface{})
- func (that *Entry) WithError(err error) LoggerEntry
- func (that *Entry) WithField(key string, value interface{}) LoggerEntry
- func (that *Entry) WithFields(fields Fields) LoggerEntry
- func (that *Entry) WithTime(t time.Time) *Entry
- type Exporter
- type Factory
- type FieldKey
- type FieldMap
- type Fields
- type Formatter
- type Hook
- type HookFunc
- type Hooks
- type Level
- type Log
- func (that *Log) AddHook(levels []Level, hook Hook)
- func (that *Log) Debug(ctx context.Context, args ...interface{})
- func (that *Log) DebugFn(ctx context.Context, fn LogFunction)
- func (that *Log) Debugf(ctx context.Context, format string, args ...interface{})
- func (that *Log) Error(ctx context.Context, args ...interface{})
- func (that *Log) ErrorFn(ctx context.Context, fn LogFunction)
- func (that *Log) Errorf(ctx context.Context, format string, args ...interface{})
- func (that *Log) Fatal(ctx context.Context, args ...interface{})
- func (that *Log) FatalFn(ctx context.Context, fn LogFunction)
- func (that *Log) Fatalf(ctx context.Context, format string, args ...interface{})
- func (that *Log) FreeBuffer(buffer *bytes.Buffer)
- func (that *Log) GetBuffer() *bytes.Buffer
- func (that *Log) Info(ctx context.Context, args ...interface{})
- func (that *Log) InfoFn(ctx context.Context, fn LogFunction)
- func (that *Log) Infof(ctx context.Context, format string, args ...interface{})
- func (that *Log) IsLevelEnabled(level Level) bool
- func (that *Log) Log(ctx context.Context, level Level, args ...interface{})
- func (that *Log) LogFn(ctx context.Context, level Level, fn LogFunction)
- func (that *Log) Logf(ctx context.Context, level Level, format string, args ...interface{})
- func (that *Log) Panic(ctx context.Context, args ...interface{})
- func (that *Log) PanicFn(ctx context.Context, fn LogFunction)
- func (that *Log) Panicf(ctx context.Context, format string, args ...interface{})
- func (that *Log) Trace(ctx context.Context, args ...interface{})
- func (that *Log) TraceFn(ctx context.Context, fn LogFunction)
- func (that *Log) Tracef(ctx context.Context, format string, args ...interface{})
- func (that *Log) Warning(ctx context.Context, args ...interface{})
- func (that *Log) WarningFn(ctx context.Context, fn LogFunction)
- func (that *Log) Warningf(ctx context.Context, format string, args ...interface{})
- func (that *Log) WithError(err error) LoggerEntry
- func (that *Log) WithField(key string, value interface{}) LoggerEntry
- func (that *Log) WithFields(fields Fields) LoggerEntry
- func (that *Log) WithTime(t time.Time) *Entry
- type LogFunction
- type Logger
- type LoggerEntry
- type LoggerPiece
- type Piece
- func (that *Piece) Message(ctx context.Context, msg string)
- func (that *Piece) Messagef(ctx context.Context, format string, args ...interface{})
- func (that *Piece) WithError(err error) LoggerPiece
- func (that *Piece) WithField(key string, value interface{}) LoggerPiece
- func (that *Piece) WithFields(fields Fields) LoggerPiece
- type Resolver
Constants ¶
View Source
const ( DefaultTimestampFormat = "2006-01-02 15:04:05" FieldKeyMsg = "msg" FieldKeyLevel = "level" FieldKeyTime = "time" FieldKeyLoggerError = "logger_error" FieldKeyEntity = "entity" FieldKeyAction = "action" FieldKeyMethod = "method" FieldKeySubject = "subject" FieldKeyData = "data" FieldKeyDuration = "duration" FieldKeyTraceID = "trace_id" )
View Source
const ( EntityActionIncomeRequest = ">>" EntityActionOutcomeRequest = "<<" EntityActionIncomeResponse = ">" EntityActionOutcomeResponse = "<" EntityActionTransitRequest = ">>>" EntityActionTransitResponse = "<--" EntityActionTransitNotification = "<<<" )
Variables ¶
View Source
var ContextModes = enums.New[ContextMode]( map[ContextMode]string{ ContextModeNone: "", ContextModeTransparent: "transparent", ContextModeOpaque: "opaque", }, )
View Source
var (
ErrRequiredFieldExporter = errors.New("exporter is required")
)
View Source
var ErrorKey = "error"
View Source
var Levels = enums.New[Level]( map[Level]string{ PanicLevel: "panic", FatalLevel: "fatal", ErrorLevel: "error", WarnLevel: "warn", InfoLevel: "info", DebugLevel: "debug", TraceLevel: "trace", }, )
View Source
var Resolve = func(ctx context.Context) Logger { log := GetLogger(ctx, nil) if log == nil { panic(fmt.Errorf("logger not found in context: %v", ctx)) } return log }
Resolve returns logger from context
Functions ¶
Types ¶
type Builder ¶ added in v1.0.14
type Builder struct {
// contains filtered or unexported fields
}
func NewBuilder ¶ added in v1.0.14
func NewBuilder() *Builder
func (*Builder) WithExporter ¶ added in v1.0.14
func (*Builder) WithHookForLevel ¶ added in v1.0.15
func (*Builder) WithHookForLevels ¶ added in v1.0.14
type Constructor ¶ added in v1.0.15
var DefaultConstructor Constructor = func(exporter Exporter, level Level) (Logger, error) { return NewBuilder(). WithExporter(exporter). WithLevel(level). Build() }
type ContextMode ¶ added in v1.0.15
type ContextMode int
const ( ContextModeNone ContextMode = iota ContextModeTransparent ContextModeOpaque )
func (ContextMode) String ¶ added in v1.0.15
func (that ContextMode) String() string
type Entry ¶
type Entry struct {
Logger *Log
Data Fields
Time time.Time
Level Level
Message string
Buffer *bytes.Buffer
LogErr string
}
func (*Entry) WithError ¶
func (that *Entry) WithError(err error) LoggerEntry
func (*Entry) WithField ¶
func (that *Entry) WithField(key string, value interface{}) LoggerEntry
func (*Entry) WithFields ¶
func (that *Entry) WithFields(fields Fields) LoggerEntry
type Factory ¶ added in v1.0.15
func NewFactory ¶ added in v1.0.15
func NewFactory(exporter Exporter, constructor Constructor) *Factory
type FieldMap ¶
func (FieldMap) DecodePrefixFieldClashes ¶ added in v1.0.1
func (FieldMap) EncodePrefixFieldClashes ¶ added in v1.0.1
type Level ¶
type Level uint8
const ( // PanicLevel level, highest level of severity. Logs and then calls panic with the // message passed to Debug, Info, ... PanicLevel Level = iota // FatalLevel level. Logs and then calls `logger.Exit(1)`. It will exit even if the // logging level is set to Panic. FatalLevel // ErrorLevel level. Logs. Used for errors that should definitely be noted. // Commonly used for hooks to send errors to an error tracking service. ErrorLevel // WarnLevel level. Non-critical entries that deserve eyes. WarnLevel // InfoLevel level. General operational entries about what's going on inside the // application. InfoLevel // DebugLevel level. Usually only enabled when debugging. Very verbose logging. DebugLevel // TraceLevel level. Designates finer-grained informational events than the Debug. TraceLevel )
type Log ¶
type Log struct {
// contains filtered or unexported fields
}
func NewDummyLogger ¶
func NewDummyLogger() *Log
func (*Log) FreeBuffer ¶
func (*Log) IsLevelEnabled ¶
func (*Log) WithError ¶
func (that *Log) WithError(err error) LoggerEntry
func (*Log) WithField ¶
func (that *Log) WithField(key string, value interface{}) LoggerEntry
func (*Log) WithFields ¶
func (that *Log) WithFields(fields Fields) LoggerEntry
type LogFunction ¶
type LogFunction func(ctx context.Context, logger LoggerEntry)
type Logger ¶
type Logger interface {
LoggerEntry
PanicFn(ctx context.Context, fn LogFunction)
FatalFn(ctx context.Context, fn LogFunction)
ErrorFn(ctx context.Context, fn LogFunction)
InfoFn(ctx context.Context, fn LogFunction)
DebugFn(ctx context.Context, fn LogFunction)
TraceFn(ctx context.Context, fn LogFunction)
}
type LoggerEntry ¶
type LoggerEntry interface {
WithField(key string, value interface{}) LoggerEntry
WithFields(fields Fields) LoggerEntry
WithError(err error) LoggerEntry
Panicf(ctx context.Context, format string, args ...interface{})
Fatalf(ctx context.Context, format string, args ...interface{})
Errorf(ctx context.Context, format string, args ...interface{})
Warningf(ctx context.Context, format string, args ...interface{})
Infof(ctx context.Context, format string, args ...interface{})
Debugf(ctx context.Context, format string, args ...interface{})
Tracef(ctx context.Context, format string, args ...interface{})
Panic(ctx context.Context, args ...interface{})
Fatal(ctx context.Context, args ...interface{})
Error(ctx context.Context, args ...interface{})
Warning(ctx context.Context, args ...interface{})
Info(ctx context.Context, args ...interface{})
Debug(ctx context.Context, args ...interface{})
Trace(ctx context.Context, args ...interface{})
}
type LoggerPiece ¶ added in v1.0.15
type LoggerPiece interface {
WithField(key string, value interface{}) LoggerPiece
WithFields(fields Fields) LoggerPiece
WithError(err error) LoggerPiece
Message(ctx context.Context, msg string)
Messagef(ctx context.Context, format string, args ...interface{})
}
type Piece ¶ added in v1.0.15
type Piece struct {
// contains filtered or unexported fields
}
func (*Piece) WithError ¶ added in v1.0.15
func (that *Piece) WithError(err error) LoggerPiece
func (*Piece) WithField ¶ added in v1.0.15
func (that *Piece) WithField(key string, value interface{}) LoggerPiece
func (*Piece) WithFields ¶ added in v1.0.15
func (that *Piece) WithFields(fields Fields) LoggerPiece
Source Files
¶
Click to show internal directories.
Click to hide internal directories.