@@ -15,20 +15,19 @@ type LogLevel int
1515
1616const (
1717 // LogLevelDebug is for messages that are useful during software debugging.
18- LogLevelDebug LogLevel = iota - 1 // Adjusted value to -1 to follow Zap's convention for DEBUG.
18+ LogLevelDebug LogLevel = - 1 // Zap's DEBUG level
1919 // LogLevelInfo is for informational messages, indicating normal operation.
20- LogLevelInfo
20+ LogLevelInfo LogLevel = 0 // Zap's INFO level
2121 // LogLevelWarn is for messages that highlight potential issues in the system.
22- LogLevelWarn
22+ LogLevelWarn LogLevel = 1 // Zap's WARN level
2323 // LogLevelError is for messages that highlight errors in the application's execution.
24- LogLevelError
25- // LogLevelDPanic is for severe error conditions that are actionable in development. It panics in development and logs as an error in production.
26- LogLevelDPanic
24+ LogLevelError LogLevel = 2 // Zap's ERROR level
25+ // LogLevelDPanic is for severe error conditions that are actionable in development.
26+ LogLevelDPanic LogLevel = 3 // Zap's DPANIC level
2727 // LogLevelPanic is for severe error conditions that should cause the program to panic.
28- LogLevelPanic
28+ LogLevelPanic LogLevel = 4 // Zap's PANIC level
2929 // LogLevelFatal is for errors that require immediate program termination.
30- LogLevelFatal
31- // LogLevelNone is used to disable logging.
30+ LogLevelFatal LogLevel = 5 // Zap's FATAL level
3231 LogLevelNone
3332)
3433
@@ -53,41 +52,6 @@ type defaultLogger struct {
5352 logLevel LogLevel // logLevel determines the current logging level (e.g., DEBUG, INFO, WARN).
5453}
5554
56- // NewDefaultLogger creates and returns a new logger instance with a default production configuration.
57- // It uses JSON formatting for log messages and sets the initial log level to Info. If the logger cannot
58- // be initialized, the function panics to indicate a critical setup failure.
59- func NewDefaultLogger () Logger {
60- // Set up custom encoder configuration
61- encoderCfg := zap .NewProductionEncoderConfig ()
62- encoderCfg .TimeKey = "timestamp"
63- encoderCfg .EncodeTime = zapcore .ISO8601TimeEncoder // Use ISO8601 format for timestamps
64-
65- // Define the logger configuration
66- config := zap.Config {
67- Level : zap .NewAtomicLevelAt (zap .InfoLevel ), // Default log level is Info
68- Development : false , // Set to true if the logger is used in a development environment
69- Encoding : "json" , // Use JSON format for structured logging
70- EncoderConfig : encoderCfg ,
71- OutputPaths : []string {"stdout" }, // Log to standard output
72- ErrorOutputPaths : []string {"stderr" }, // Log internal Zap errors to standard error
73- InitialFields : map [string ]interface {}{
74- "application" : "your-application-name" , // Customize this field to suit your needs
75- },
76- }
77-
78- // Build the logger from the configuration
79- logger , err := config .Build ()
80- if err != nil {
81- panic (err ) // Panic if there is an error initializing the logger
82- }
83-
84- // Wrap the Zap logger in your defaultLogger struct, which implements your Logger interface
85- return & defaultLogger {
86- logger : logger ,
87- logLevel : LogLevelInfo , // Assuming LogLevelInfo maps to zap.InfoLevel
88- }
89- }
90-
9155// SetLevel updates the logging level of the logger. It controls the verbosity of the logs,
9256// allowing the option to filter out less severe messages based on the specified level.
9357func (d * defaultLogger ) SetLevel (level LogLevel ) {
0 commit comments