From 5b00614d9981e22feb1718348f6e04e508b2e079 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=A8=8B=E5=B9=BF?= Date: Mon, 23 Jan 2023 10:20:17 +0800 Subject: [PATCH] fix get logger --- main.go | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/main.go b/main.go index cc62d3e..dd5f267 100644 --- a/main.go +++ b/main.go @@ -14,15 +14,18 @@ const ( Trace ) +type LogConfig struct { + Name string + Level int +} type Logger struct { - name string - level int + LogConfig } -func (l *Logger) log(level int, msg string) { +func (l *Logger) log(Level int, msg string) { now := time.Now() - if level <= l.level { - fmt.Println(now.Format("2006-01-02 15:04:05"), " ", l.name, ": ", msg) + if Level <= l.Level { + fmt.Println(now.Format("2006-01-02 15:04:05"), " ", l.Name, ": ", msg) } } @@ -45,6 +48,6 @@ func (l *Logger) Debug(msg string) { func (l *Logger) Trace(msg string) { l.log(Trace, msg) } -func GetLogger(name string) Logger { - return Logger{name, 0} +func GetLogger(logConfig LogConfig) Logger { + return Logger{logConfig} }