feat: refine the Logger interface

This commit is contained in:
WqyJh
2025-02-10 16:36:16 +08:00
parent 4e156e533c
commit 3f3cf7a60d
+17 -1
View File
@@ -3,8 +3,10 @@ package openairt
import "log"
type Logger interface {
Errorf(format string, v ...any)
Debugf(format string, v ...any)
Infof(format string, v ...any)
Warnf(format string, v ...any)
Errorf(format string, v ...any)
}
// NopLogger is a logger that does nothing.
@@ -16,6 +18,12 @@ func (l NopLogger) Errorf(_ string, _ ...any) {}
// Warnf does nothing.
func (l NopLogger) Warnf(_ string, _ ...any) {}
// Infof does nothing.
func (l NopLogger) Infof(_ string, _ ...any) {}
// Debugf does nothing.
func (l NopLogger) Debugf(_ string, _ ...any) {}
// StdLogger is a logger that logs to the "log" package.
type StdLogger struct{}
@@ -26,3 +34,11 @@ func (l StdLogger) Errorf(format string, v ...any) {
func (l StdLogger) Warnf(format string, v ...any) {
log.Printf("[WARN] "+format, v...)
}
func (l StdLogger) Infof(format string, v ...any) {
log.Printf("[INFO] "+format, v...)
}
func (l StdLogger) Debugf(format string, v ...any) {
log.Printf("[DEBUG] "+format, v...)
}