fix get logger

This commit is contained in:
程广 2023-01-23 10:20:17 +08:00
parent 84aa021d1a
commit 5b00614d99
1 changed files with 10 additions and 7 deletions

17
main.go
View File

@ -14,15 +14,18 @@ const (
Trace Trace
) )
type LogConfig struct {
Name string
Level int
}
type Logger struct { type Logger struct {
name string LogConfig
level int
} }
func (l *Logger) log(level int, msg string) { func (l *Logger) log(Level int, msg string) {
now := time.Now() now := time.Now()
if level <= l.level { if Level <= l.Level {
fmt.Println(now.Format("2006-01-02 15:04:05"), " ", l.name, ": ", msg) 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) { func (l *Logger) Trace(msg string) {
l.log(Trace, msg) l.log(Trace, msg)
} }
func GetLogger(name string) Logger { func GetLogger(logConfig LogConfig) Logger {
return Logger{name, 0} return Logger{logConfig}
} }