Documentation
¶
Index ¶
- Variables
- func Debug(ctx context.Context, msg string, fields ...map[string]any)
- func DiscardLogger() zerolog.Logger
- func Error(ctx context.Context, msg string, fields ...map[string]any)
- func Fatal(ctx context.Context, msg string, fields ...map[string]any)
- func Info(ctx context.Context, msg string, fields ...map[string]any)
- func InitGlobalLogger(config LoggerConfig)
- func NewLogger(cfg Config) (zerolog.Logger, error)
- func Warn(ctx context.Context, msg string, fields ...map[string]any)
- type Config
- type ContextKey
- type GlobalLogger
- type LogLevel
- type LoggerConfig
- type MetricsHook
- type StructuredLogger
- func (l *StructuredLogger) Debug(ctx context.Context, msg string, fields ...map[string]any)
- func (l *StructuredLogger) Error(ctx context.Context, msg string, fields ...map[string]any)
- func (l *StructuredLogger) Fatal(ctx context.Context, msg string, fields ...map[string]any)
- func (l *StructuredLogger) Info(ctx context.Context, msg string, fields ...map[string]any)
- func (l *StructuredLogger) Warn(ctx context.Context, msg string, fields ...map[string]any)
- func (l *StructuredLogger) WithComponent(component string) *StructuredLogger
- func (l *StructuredLogger) WithFields(fields map[string]any) *StructuredLogger
- func (l *StructuredLogger) WithTrace(traceID, spanID string) *StructuredLogger
Constants ¶
This section is empty.
Variables ¶
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 DiscardLogger ¶
DiscardLogger returns a logger that discards all output (useful for tests)
func InitGlobalLogger ¶
func InitGlobalLogger(config LoggerConfig)
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 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
type StructuredLogger ¶
type StructuredLogger struct {
// contains filtered or unexported fields
}
func NewStructuredLogger ¶
func NewStructuredLogger(config LoggerConfig) *StructuredLogger
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