From 91d87d83c895caa78945276a48c8634fe5e3ecdd Mon Sep 17 00:00:00 2001 From: adwpc Date: Sun, 25 Jul 2021 20:19:01 +0800 Subject: [PATCH] (feat) add StringToLevel --- log.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/log.go b/log.go index 9393f92..1432d97 100644 --- a/log.go +++ b/log.go @@ -70,6 +70,10 @@ func Errorf(format string, v ...interface{}) { defaultLogger.Errorf(format, v... func Panicf(format string, v ...interface{}) { defaultLogger.Panicf(format, v...) } func Init(level string) { + defaultLogger.SetLevel(logrus.Level(StringToLevel(level))) +} + +func StringToLevel(level string) Level { l := logrus.DebugLevel switch level { case "trace": @@ -83,7 +87,7 @@ func Init(level string) { case "error": l = logrus.ErrorLevel } - defaultLogger.SetLevel(l) + return Level(l) } type MyLogger struct {