Set logging level for Logrus and TDlib from config

This commit is contained in:
bodqhrohro 2019-11-05 02:09:07 +02:00
parent aaf7233c89
commit 0f047c3816
3 changed files with 38 additions and 7 deletions

29
log.go Normal file
View file

@ -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))
}

View file

@ -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)

View file

@ -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 {