Documentation
¶
Overview ¶
Package flog provides structured logging for Flowbot.
Index ¶
- Constants
- Variables
- func ClearErrorBuffer()
- func Ctx(ctx context.Context) *zerolog.Logger
- func Debug(format string, a ...any)
- func DebugEvt() *zerolog.Event
- func DebugFields(msg string, fields map[string]any)
- func Err(err error)
- func ErrFields(err error, msg string, fields map[string]any)
- func Error(err error)
- func ErrorEvt() *zerolog.Event
- func Fatal(format string, a ...any)
- func GetLogger() zerolog.Logger
- func Info(format string, a ...any)
- func InfoEvt() *zerolog.Event
- func InfoFields(msg string, fields map[string]any)
- func Init(cfg Config)
- func Module(name string) *zerolog.Logger
- func Panic(format string, a ...any)
- func Sampled() *zerolog.Logger
- func SetLevel(level string)
- func SetModuleLevel(name, lvlStr string)
- func Warn(format string, a ...any)
- func WarnEvt() *zerolog.Event
- func WarnFields(msg string, fields map[string]any)
- type Config
- type ErrorEntry
- type RotationConfig
- type SamplingConfig
Constants ¶
const ( DebugLevel = "debug" InfoLevel = "info" WarnLevel = "warn" ErrorLevel = "error" FatalLevel = "fatal" PanicLevel = "panic" )
Variables ¶
var FxModule = fx.Module("flog", fx.Provide(func(cfg *config.Type) (zerolog.Logger, error) { logCfg := cfg.Log fc := Config{ Level: logCfg.Level, Caller: logCfg.Caller, StackTrace: logCfg.StackTrace, JSONOutput: logCfg.JSONOutput, FileLog: logCfg.FileLog, FileLogPath: logCfg.FileLogPath, ModuleLevel: logCfg.ModuleLevel, } if logCfg.Sampling != nil { fc.Sampling = &SamplingConfig{ Burst: logCfg.Sampling.Burst, Period: time.Duration(logCfg.Sampling.Period) * time.Second, } } if logCfg.Rotation != nil { fc.Rotation = &RotationConfig{ MaxSize: logCfg.Rotation.MaxSize, MaxAge: logCfg.Rotation.MaxAge, MaxBackups: logCfg.Rotation.MaxBackups, Compress: logCfg.Rotation.Compress, } } Init(fc) return GetLogger(), nil }), )
FxModule provides the zerolog.Logger to the Fx dependency injection graph. It reads log configuration from *config.Type and calls Init before returning.
var SlackLogger = &slackLogger{}
var WatermillLogger = &watermillLogger{}
Functions ¶
func ClearErrorBuffer ¶ added in v0.92.0
func ClearErrorBuffer()
ClearErrorBuffer clears the error buffer. Exported for tests.
func Ctx ¶ added in v0.92.0
Ctx returns a zerolog.Logger annotated with trace_id and span_id from the OpenTelemetry span in the given context. If no span is present, the global logger is returned unchanged.
func DebugEvt ¶ added in v0.92.0
DebugEvt returns a Debug-level event pre-configured with caller info.
func DebugFields ¶ added in v0.92.0
DebugFields logs a debug message with structured fields.
func ErrFields ¶ added in v0.92.0
ErrFields logs an error with structured fields, without triggering alarm.
func ErrorEvt ¶ added in v0.92.0
ErrorEvt returns an Error-level event pre-configured with caller and stack info.
func InfoEvt ¶ added in v0.92.0
InfoEvt returns an Info-level event pre-configured with caller info.
func InfoFields ¶ added in v0.92.0
InfoFields logs an info message with structured fields.
func Init ¶
func Init(cfg Config)
Init initializes the logging subsystem. Must be called once at startup.
func Module ¶ added in v0.92.0
Module returns a logger with the configured per-module log level. Falls back to the global logger if the module is not configured.
func SetModuleLevel ¶ added in v0.92.0
func SetModuleLevel(name, lvlStr string)
SetModuleLevel sets the log level for a specific module.
func WarnFields ¶ added in v0.92.0
WarnFields logs a warning message with structured fields.
Types ¶
type Config ¶ added in v0.92.0
type Config struct {
Level string
Caller bool
StackTrace bool
JSONOutput bool
FileLog bool
FileLogPath string
ModuleLevel map[string]string
Sampling *SamplingConfig
Rotation *RotationConfig
}
Config holds all logging configuration.
type ErrorEntry ¶ added in v0.92.0
type ErrorEntry struct {
Time time.Time `json:"time"`
Message string `json:"message"`
Caller string `json:"caller,omitzero"`
}
ErrorEntry represents a recorded error log entry for health dashboard display.
func RecentErrors ¶ added in v0.92.0
func RecentErrors() []ErrorEntry
RecentErrors returns a copy of recent error entries in insertion order. Returns at most errorBufferCapacity entries, oldest first.
type RotationConfig ¶ added in v0.92.0
RotationConfig controls log file rotation via lumberjack.
type SamplingConfig ¶ added in v0.92.0
SamplingConfig controls log sampling to reduce noise from high-frequency log points.