2023-12-13 23:05:42 +08:00
|
|
|
// TestGetLogger tests the GetLogger function
|
|
|
|
package gologger
|
|
|
|
|
|
|
|
import "testing"
|
|
|
|
|
|
|
|
func TestGetLogger(t *testing.T) {
|
|
|
|
// Initialize loggerMap and loggerConfig
|
2025-06-06 13:55:46 +08:00
|
|
|
|
|
|
|
dl := GetLogger("default")
|
|
|
|
if dl != defaultLogger {
|
|
|
|
t.Errorf("GetLogger(\"defult\") should return defaultLogger")
|
|
|
|
}
|
|
|
|
dl.Error("test")
|
2025-06-06 11:07:04 +08:00
|
|
|
Configure(LoggersConfig{
|
|
|
|
Appenders: map[string]LogAppenderConfig{
|
|
|
|
"console": {
|
|
|
|
Type: "console",
|
|
|
|
Formatter: "json",
|
|
|
|
Options: map[string]interface{}{},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Categories: map[string]LogConfig{
|
|
|
|
"default": {
|
|
|
|
Level: "info",
|
|
|
|
Appenders: []string{"console"},
|
|
|
|
},
|
|
|
|
"app": {
|
|
|
|
Level: "debug",
|
|
|
|
Appenders: []string{"console"},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
2025-06-06 13:55:46 +08:00
|
|
|
dl.Info("test")
|
|
|
|
if dl.level != Info {
|
|
|
|
t.Errorf("GetLogger(\"default\") should return defaultLogger")
|
|
|
|
}
|
2023-12-13 23:05:42 +08:00
|
|
|
al := GetLogger("app")
|
|
|
|
|
|
|
|
if al == dl {
|
|
|
|
t.Errorf("GetLogger(\"app\") should return a new logger")
|
|
|
|
}
|
|
|
|
|
|
|
|
al2 := GetLogger("app")
|
|
|
|
|
|
|
|
if al2 != al {
|
|
|
|
t.Errorf("GetLogger(\"app\") should return the same logger")
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|