Documentation
¶
Overview ¶
Package logger provides structured logging functionality using zerolog. It offers a simple interface for initializing and configuring application-wide logging.
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func GetLogger ¶
GetLogger returns the configured logger instance. This logger inherits the global configuration set by Init(). It's safe to call this function multiple times and from multiple goroutines.
Example ¶
ExampleGetLogger demonstrates how to get and use a logger instance.
// First initialize the logger
Init("info")
// Get a logger instance
logger := GetLogger()
// Use the logger
logger.Info().Str("component", "example").Msg("Application started")
logger.Debug().Int("count", 42).Msg("Processing items")
func Init ¶
func Init(level string)
Init initializes the global logger with the specified level. Supported levels: debug, info, warn/warning, error, fatal, panic. If an invalid level is provided, defaults to info level. The logger is configured to use console output for better readability.
Example ¶
ExampleInit demonstrates basic usage of the Init function with different log levels.
// Initialize logger with info level
Init("info")
// Initialize logger with debug level for development
Init("debug")
// Initialize logger with error level for production
Init("error")
Example (WithInvalidLevel) ¶
ExampleInit_withInvalidLevel demonstrates that invalid log levels default to info level gracefully.
// Invalid levels default to info
Init("invalid-level")
logger := GetLogger()
logger.Info().Msg("This will be logged at info level")
Types ¶
This section is empty.