add map for logger

This commit is contained in:
程广 2023-01-23 10:24:39 +08:00
parent 5b00614d99
commit 14ac4e7469
1 changed files with 10 additions and 1 deletions

11
main.go
View File

@ -14,6 +14,8 @@ const (
Trace Trace
) )
var loggerMap map[string]Logger
type LogConfig struct { type LogConfig struct {
Name string Name string
Level int Level int
@ -49,5 +51,12 @@ func (l *Logger) Trace(msg string) {
l.log(Trace, msg) l.log(Trace, msg)
} }
func GetLogger(logConfig LogConfig) Logger { func GetLogger(logConfig LogConfig) Logger {
return Logger{logConfig} if logger, ok := loggerMap[logConfig.Name]; ok {
return logger
} else {
logger = Logger{logConfig}
loggerMap[logConfig.Name] = logger
return logger
}
} }