logging

package
v0.2.4 Latest Latest
Warning

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

Go to latest
Published: Mar 13, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Logger *slog.Logger

Logger is the global logger instance (deprecated: use GetLogger() for thread-safe access)

Functions

func GetLogger

func GetLogger() *slog.Logger

GetLogger returns the global logger instance in a thread-safe manner

func NopLogger

func NopLogger() *slog.Logger

NopLogger returns a no-op logger that discards all output

func ParseLevel

func ParseLevel(level string) (slog.Level, error)

ParseLevel converts a string log level to slog.Level

func Sync

func Sync() error

Sync flushes any buffered log entries

func WithRequestID

func WithRequestID(requestID string) *slog.Logger

WithRequestID returns a logger with the request ID field added This is useful for tracing requests across log entries

Types

type Config

type Config struct {
	// LogLevel sets the minimum log level (debug, info, warn, error)
	LogLevel slog.Level
	// LogFilePath is the path to the log file (empty to disable file logging)
	LogFilePath string
}

Config holds logging configuration

type InitResult

type InitResult struct {
	// FileLoggingEnabled indicates whether file logging was successfully enabled
	FileLoggingEnabled bool
	// FileLoggingError contains the error if file logging failed (nil if succeeded or not attempted)
	FileLoggingError error
}

InitResult contains the result of logger initialization

func InitLogger

func InitLogger(cfg Config) (*InitResult, error)

InitLogger initializes the global logger with JSON structured logging It always logs to stdout and optionally logs to a file if LogFilePath is set Returns InitResult indicating whether file logging was enabled and any errors encountered

Jump to

Keyboard shortcuts

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