aboutsummaryrefslogtreecommitdiff
path: root/log.go
diff options
context:
space:
mode:
authorbodqhrohro <bodqhrohro@gmail.com>2019-11-05 03:09:07 +0300
committerbodqhrohro <bodqhrohro@gmail.com>2019-11-05 03:09:07 +0300
commit0f047c38168949b246223dc1b1154a6969753d2e (patch)
tree796066e609cf26c7a37c6fc3431668eea97c97da /log.go
parentaaf7233c89af4dfbc2a8b9f5e11b4ff5e9713567 (diff)
Set logging level for Logrus and TDlib from config
Diffstat (limited to 'log.go')
-rw-r--r--log.go29
1 files changed, 29 insertions, 0 deletions
diff --git a/log.go b/log.go
new file mode 100644
index 0000000..b287815
--- /dev/null
+++ b/log.go
@@ -0,0 +1,29 @@
+package main
+
+import (
+ log "github.com/sirupsen/logrus"
+)
+
+var logConstants = map[string]log.Level{
+ ":fatal": log.FatalLevel,
+ ":error": log.ErrorLevel,
+ ":warn": log.WarnLevel,
+ ":info": log.InfoLevel,
+ ":debug": log.DebugLevel,
+ ":verbose": log.TraceLevel,
+ ":all": log.TraceLevel,
+}
+
+func stringToLogConstant(c string) log.Level {
+ level, ok := logConstants[c]
+ if !ok {
+ level = log.FatalLevel
+ }
+
+ return level
+}
+
+// SetLogrusLevel sets Logrus logging level from a string
+func SetLogrusLevel(level string) {
+ log.SetLevel(stringToLogConstant(level))
+}