Documentation ¶
Overview ¶
logger.go
logger.go
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func GetLoggerBasedOnEnv ¶
GetLoggerBasedOnEnv returns a zap.Logger instance configured for either production or development based on the APP_ENV environment variable. If APP_ENV is set to "development", it returns a development logger. Otherwise, it defaults to a production logger.
func ToZapFields ¶
ToZapFields converts a variadic list of key-value pairs into a slice of Zap fields. This allows for structured logging with strongly-typed values. The function assumes that keys are strings and values can be of any type, leveraging zap.Any for type detection.
Types ¶
type LogLevel ¶
type LogLevel int
LogLevel represents the level of logging. Higher values denote more severe log messages.
const ( // LogLevelDebug is for messages that are useful during software debugging. LogLevelDebug LogLevel = -1 // Zap's DEBUG level // LogLevelInfo is for informational messages, indicating normal operation. LogLevelInfo LogLevel = 0 // Zap's INFO level // LogLevelWarn is for messages that highlight potential issues in the system. LogLevelWarn LogLevel = 1 // Zap's WARN level // LogLevelError is for messages that highlight errors in the application's execution. LogLevelError LogLevel = 2 // Zap's ERROR level // LogLevelDPanic is for severe error conditions that are actionable in development. LogLevelDPanic LogLevel = 3 // Zap's DPANIC level // LogLevelPanic is for severe error conditions that should cause the program to panic. LogLevelPanic LogLevel = 4 // Zap's PANIC level // LogLevelFatal is for errors that require immediate program termination. LogLevelFatal LogLevel = 5 // Zap's FATAL level LogLevelNone )
type Logger ¶
type Logger interface { SetLevel(level LogLevel) Debug(msg string, fields ...zapcore.Field) Info(msg string, fields ...zapcore.Field) Warn(msg string, fields ...zapcore.Field) Error(msg string, fields ...zapcore.Field) error Panic(msg string, fields ...zapcore.Field) Fatal(msg string, fields ...zapcore.Field) With(fields ...zapcore.Field) Logger GetLogLevel() LogLevel }
Logger interface with structured logging capabilities at various levels.
func BuildLogger ¶
BuildLogger creates and returns a new logger instance with a default production configuration. It uses JSON formatting for log messages and sets the initial log level to Info. If the logger cannot be initialized, the function panics to indicate a critical setup failure.