aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--log.go29
-rw-r--r--telegabber.go2
-rw-r--r--telegram/client.go14
3 files changed, 38 insertions, 7 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))
+}
diff --git a/telegabber.go b/telegabber.go
index 6754038..8c098e1 100644
--- a/telegabber.go
+++ b/telegabber.go
@@ -19,6 +19,8 @@ func main() {
log.Fatal(err)
}
+ SetLogrusLevel(config.XMPP.Loglevel)
+
cm, err := xmpp.NewComponent(config.XMPP, config.Telegram)
if err != nil {
log.Fatal(err)
diff --git a/telegram/client.go b/telegram/client.go
index b0cee44..3d361b6 100644
--- a/telegram/client.go
+++ b/telegram/client.go
@@ -12,13 +12,13 @@ import (
)
var logConstants = map[string]int32{
- "fatal": 0,
- "error": 1,
- "warn": 2,
- "info": 3,
- "debug": 4,
- "verbose": 5,
- "all": 1023,
+ ":fatal": 0,
+ ":error": 1,
+ ":warn": 2,
+ ":info": 3,
+ ":debug": 4,
+ ":verbose": 5,
+ ":all": 1023,
}
func stringToLogConstant(c string) int32 {