From 14ac4e7469621e09e29cd7e39fea507a1dee35db Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=A8=8B=E5=B9=BF?= Date: Mon, 23 Jan 2023 10:24:39 +0800 Subject: [PATCH] add map for logger --- main.go | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/main.go b/main.go index dd5f267..d6c3708 100644 --- a/main.go +++ b/main.go @@ -14,6 +14,8 @@ const ( Trace ) +var loggerMap map[string]Logger + type LogConfig struct { Name string Level int @@ -49,5 +51,12 @@ func (l *Logger) Trace(msg string) { l.log(Trace, msg) } 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 + } + }