flog

package
v0.92.1 Latest Latest
Warning

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

Go to latest
Published: Jun 6, 2026 License: GPL-3.0 Imports: 19 Imported by: 0

Documentation

Overview

Package flog provides structured logging for Flowbot.

Index

Constants

View Source
const (
	DebugLevel = "debug"
	InfoLevel  = "info"
	WarnLevel  = "warn"
	ErrorLevel = "error"
	FatalLevel = "fatal"
	PanicLevel = "panic"
)

Variables

View Source
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.

View Source
var SlackLogger = &slackLogger{}
View Source
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

func Ctx(ctx context.Context) *zerolog.Logger

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 Debug

func Debug(format string, a ...any)

Debug logs a formatted debug message.

func DebugEvt added in v0.92.0

func DebugEvt() *zerolog.Event

DebugEvt returns a Debug-level event pre-configured with caller info.

func DebugFields added in v0.92.0

func DebugFields(msg string, fields map[string]any)

DebugFields logs a debug message with structured fields.

func Err added in v0.92.0

func Err(err error)

Err logs an error without triggering alarm.

func ErrFields added in v0.92.0

func ErrFields(err error, msg string, fields map[string]any)

ErrFields logs an error with structured fields, without triggering alarm.

func Error

func Error(err error)

Error logs an error.

func ErrorEvt added in v0.92.0

func ErrorEvt() *zerolog.Event

ErrorEvt returns an Error-level event pre-configured with caller and stack info.

func Fatal

func Fatal(format string, a ...any)

Fatal logs a formatted fatal message and exits the program.

func GetLogger

func GetLogger() zerolog.Logger

GetLogger returns the underlying zerolog.Logger.

func Info

func Info(format string, a ...any)

Info logs a formatted info message.

func InfoEvt added in v0.92.0

func InfoEvt() *zerolog.Event

InfoEvt returns an Info-level event pre-configured with caller info.

func InfoFields added in v0.92.0

func InfoFields(msg string, fields map[string]any)

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

func Module(name string) *zerolog.Logger

Module returns a logger with the configured per-module log level. Falls back to the global logger if the module is not configured.

func Panic

func Panic(format string, a ...any)

Panic logs a formatted panic message and panics.

func Sampled added in v0.92.0

func Sampled() *zerolog.Logger

Sampled returns a logger with burst sampling applied.

func SetLevel

func SetLevel(level string)

SetLevel sets the global default log level.

func SetModuleLevel added in v0.92.0

func SetModuleLevel(name, lvlStr string)

SetModuleLevel sets the log level for a specific module.

func Warn

func Warn(format string, a ...any)

Warn logs a formatted warning message.

func WarnEvt added in v0.92.0

func WarnEvt() *zerolog.Event

WarnEvt returns a Warn-level event pre-configured with caller info.

func WarnFields added in v0.92.0

func WarnFields(msg string, fields map[string]any)

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

type RotationConfig struct {
	MaxSize    int
	MaxAge     int
	MaxBackups int
	Compress   bool
}

RotationConfig controls log file rotation via lumberjack.

type SamplingConfig added in v0.92.0

type SamplingConfig struct {
	Burst  int
	Period time.Duration
}

SamplingConfig controls log sampling to reduce noise from high-frequency log points.

Jump to

Keyboard shortcuts

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