Documentation ¶
Overview ¶
Package logger provides a global logging interface for structured logging.
Index ¶
- func SetGlobalLogger(l Logger)
- type Logger
- type ZapLogger
- func (z ZapLogger) Debug(msg string, fields ...interface{})
- func (z ZapLogger) Error(msg string, fields ...interface{})
- func (z ZapLogger) Fatal(msg string, fields ...interface{})
- func (z ZapLogger) Info(msg string, fields ...interface{})
- func (z ZapLogger) Panic(msg string, fields ...interface{})
- func (z ZapLogger) Warn(msg string, fields ...interface{})
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func SetGlobalLogger ¶
func SetGlobalLogger(l Logger)
SetGlobalLogger sets the global logger instance to the provided Logger.
Types ¶
type Logger ¶
type Logger interface { // Debug logs a message at the debug level. Debug(format string, args ...interface{}) // Info logs a message at the info level. Info(format string, args ...interface{}) // Warn logs a message at the warn level. Warn(format string, args ...interface{}) // Error logs a message at the error level. Error(format string, args ...interface{}) // Fatal logs a message at the fatal level. The application will terminate after logging the message. Fatal(format string, args ...interface{}) // Panic logs a message at the panic level. The application will panic after logging the message. Panic(format string, args ...interface{}) }
Logger is the interface for structured logging. It provides methods for logging at various levels of severity.
func GetZapDevelopmentLogger ¶
func GetZapDevelopmentLogger(level zap.AtomicLevel) (Logger, error)
GetZapDevelopmentLogger creates and returns a new zap.Logger configured for development use. The development logger is more verbose and is intended for use during development. It uses a console encoder with colored level output and logs at the specified log level.
Parameters:
- level: The minimum logging level at which logs should be written, e.g., zapcore.DebugLevel, zapcore.InfoLevel.
Returns:
- Logger: The configured zap.Logger for development use.
- error: An error if the logger could not be created.
func GetZapLogger ¶
GetZapLogger creates and returns a new zap.Logger based on the environment and log level. It supports "development" and "production" environments.
Parameters:
- env: The environment for the logger, e.g., "development", "production".
- level: The logging level, e.g., "debug", "info".
Returns:
- Logger: The configured zap.Logger based on the environment and log level.
- error: An error if the logger could not be created.
func GetZapProductionLogger ¶
func GetZapProductionLogger(level zap.AtomicLevel) (Logger, error)
GetZapProductionLogger creates and returns a new zap.Logger configured for production use. The production logger is optimized for performance. It uses a JSON encoder, logs to standard error, and writes at InfoLevel and above.
Parameters:
- level: The minimum logging level at which logs should be written, e.g., zapcore.DebugLevel, zapcore.InfoLevel.
Returns:
- Logger: The configured zap.Logger for production use.
- error: An error if the logger could not be created.
type ZapLogger ¶
ZapLogger is an implementation of the Logger interface using the zap logging library.