logging

package
v0.2.6 Latest Latest
Warning

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

Go to latest
Published: Nov 17, 2026 License: Unlicense Imports: 7 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// LogEntriesTotal counts log entries by level
	LogEntriesTotal = promauto.NewCounterVec(
		prometheus.CounterOpts{
			Name: "longbow_log_entries_total",
			Help: "Total number of log entries by level",
		},
		[]string{"level"},
	)

	// LogErrorsTotal counts error-level log entries specifically
	LogErrorsTotal = promauto.NewCounter(
		prometheus.CounterOpts{
			Name: "longbow_log_errors_total",
			Help: "Total number of error log entries",
		},
	)
)

Prometheus metrics for logging operations

Functions

func Debug

func Debug(ctx context.Context, msg string, fields ...map[string]any)

func DiscardLogger

func DiscardLogger() zerolog.Logger

DiscardLogger returns a logger that discards all output (useful for tests)

func Error

func Error(ctx context.Context, msg string, fields ...map[string]any)

func Fatal

func Fatal(ctx context.Context, msg string, fields ...map[string]any)

func Info

func Info(ctx context.Context, msg string, fields ...map[string]any)

func InitGlobalLogger

func InitGlobalLogger(config LoggerConfig)

func NewLogger

func NewLogger(cfg Config) (zerolog.Logger, error)

NewLogger creates a new zerolog logger based on the provided configuration

func Warn

func Warn(ctx context.Context, msg string, fields ...map[string]any)

Types

type Config

type Config struct {
	// Format specifies the log output format: "json" or "text"
	Format string
	// Level specifies the minimum log level: "debug", "info", "warn", "error"
	Level string
	// Output specifies where logs are written (defaults to os.Stdout)
	Output io.Writer
}

Config holds logger configuration options

func DefaultConfig

func DefaultConfig() Config

DefaultConfig returns the default logger configuration

type ContextKey

type ContextKey string
const (
	ComponentKey ContextKey = "component"
	TraceIDKey   ContextKey = "trace_id"
	SpanIDKey    ContextKey = "span_id"
)

type GlobalLogger

type GlobalLogger struct {
	*StructuredLogger
}

func WithComponent

func WithComponent(component string) *GlobalLogger

func WithFields

func WithFields(fields map[string]any) *GlobalLogger

func WithTrace

func WithTrace(traceID, spanID string) *GlobalLogger

type LogLevel

type LogLevel int
const (
	DebugLevel LogLevel = iota
	InfoLevel
	WarnLevel
	ErrorLevel
	FatalLevel
)

type LoggerConfig

type LoggerConfig struct {
	Level         LogLevel
	EnableConsole bool
	EnableFile    bool
	FilePath      string
	EnableJSON    bool
	EnableTrace   bool
	Component     string
}

func DefaultLoggerConfig

func DefaultLoggerConfig() LoggerConfig

type MetricsHook

type MetricsHook struct{}

MetricsHook implements zerolog.Hook to increment Prometheus metrics

func (MetricsHook) Run

func (h MetricsHook) Run(e *zerolog.Event, level zerolog.Level, msg string)

Run increments Prometheus metrics based on the log level

type StructuredLogger

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

func NewStructuredLogger

func NewStructuredLogger(config LoggerConfig) *StructuredLogger

func (*StructuredLogger) Debug

func (l *StructuredLogger) Debug(ctx context.Context, msg string, fields ...map[string]any)

func (*StructuredLogger) Error

func (l *StructuredLogger) Error(ctx context.Context, msg string, fields ...map[string]any)

func (*StructuredLogger) Fatal

func (l *StructuredLogger) Fatal(ctx context.Context, msg string, fields ...map[string]any)

func (*StructuredLogger) Info

func (l *StructuredLogger) Info(ctx context.Context, msg string, fields ...map[string]any)

func (*StructuredLogger) Warn

func (l *StructuredLogger) Warn(ctx context.Context, msg string, fields ...map[string]any)

func (*StructuredLogger) WithComponent

func (l *StructuredLogger) WithComponent(component string) *StructuredLogger

func (*StructuredLogger) WithFields

func (l *StructuredLogger) WithFields(fields map[string]any) *StructuredLogger

func (*StructuredLogger) WithTrace

func (l *StructuredLogger) WithTrace(traceID, spanID string) *StructuredLogger

Jump to

Keyboard shortcuts

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