Skip to content

Commit fd27426

Browse files
committed
fix(yalogger): correct level iota, setting config
1 parent 41dcbd1 commit fd27426

3 files changed

Lines changed: 61 additions & 8 deletions

File tree

yalogger/constants.go

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,24 @@ package yalogger
33
type Level uint8
44

55
const (
6-
TraceLevel Level = iota
7-
DebugLevel
8-
InfoLevel
9-
WarnLevel
10-
ErrorLevel
6+
// PanicLevel level, highest level of severity. Logs and then calls panic with the
7+
// message passed to Debug, Info, ...
8+
PanicLevel Level = iota
9+
// FatalLevel level. Logs and then calls `logger.Exit(1)`. It will exit even if the
10+
// logging level is set to Panic.
1111
FatalLevel
12+
// ErrorLevel level. Logs. Used for errors that should definitely be noted.
13+
// Commonly used for hooks to send errors to an error tracking service.
14+
ErrorLevel
15+
// WarnLevel level. Non-critical entries that deserve eyes.
16+
WarnLevel
17+
// InfoLevel level. General operational entries about what's going on inside the
18+
// application.
19+
InfoLevel
20+
// DebugLevel level. Usually only enabled when debugging. Very verbose logging.
21+
DebugLevel
22+
// TraceLevel level. Designates finer-grained informational events than the Debug.
23+
TraceLevel
1224
)
1325

1426
type BaseLoggerType uint8

yalogger/logrus_logger.go

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ func NewBaseLogger(config *Config) BaseLogger {
3232
if config == nil {
3333
config = &Config{
3434
BaseLoggerType: Logrus,
35-
Level: DebugLevel,
35+
Level: TraceLevel,
3636
FullTimestamp: false,
3737
TimestampFormat: "2006-01-02 15:04:05",
3838
DisableTimestamp: true,
@@ -48,11 +48,11 @@ func NewBaseLogger(config *Config) BaseLogger {
4848
TimestampFormat: config.TimestampFormat,
4949
DisableTimestamp: config.DisableTimestamp,
5050
})
51+
52+
return &baseLogrus{logger: base}
5153
default:
5254
panic("Unsupported logger type, you are a teapot!!!")
5355
}
54-
55-
return &baseLogrus{logger: logrus.New()}
5656
}
5757

5858
// NewLogger creates a new Logger instance from the base logrus logger.
@@ -200,6 +200,33 @@ func (l *logrusAdapter) Fatalf(format string, args ...any) {
200200
l.entry.Fatalf(format, args...)
201201
}
202202

203+
// Panic logs a message at the Panic level and may terminate the application.
204+
//
205+
// Parameters:
206+
//
207+
// - msg: the panic message.
208+
//
209+
// Example usage:
210+
//
211+
// logger.Panic("Unexpected error occurred")
212+
func (l *logrusAdapter) Panic(msg string) {
213+
l.entry.Panic(msg)
214+
}
215+
216+
// Panicf logs a formatted panic message at the Panic level and may terminate the application.
217+
//
218+
// Parameters:
219+
//
220+
// - format: the message format.
221+
// - args: the arguments for the format.
222+
//
223+
// Example usage:
224+
//
225+
// logger.Panicf("Critical failure: %s", err)
226+
func (l *logrusAdapter) Panicf(format string, args ...any) {
227+
l.entry.Panicf(format, args...)
228+
}
229+
203230
// Trace logs a message at the Trace level, providing fine-grained debugging information.
204231
//
205232
// Parameters:

yalogger/yalogger.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,20 @@ type Logger interface {
122122
// logger.Fatalf("Cannot load config file: %s", path)
123123
Fatalf(format string, args ...any)
124124

125+
// Panic logs a message at the Panic level and may terminate the application.
126+
//
127+
// Example usage:
128+
//
129+
// logger.Panic("Unexpected error occurred")
130+
Panic(msg string)
131+
132+
// Panicf logs a formatted message at the Panic level.
133+
//
134+
// Example usage:
135+
//
136+
// logger.Panicf("Critical failure: %s", err)
137+
Panicf(format string, args ...any)
138+
125139
// WithField returns a logger instance with a single field added to the context.
126140
//
127141
// Example usage:

0 commit comments

Comments
 (0)