Set logging level for Logrus and TDlib from config
This commit is contained in:
parent
aaf7233c89
commit
0f047c3816
29
log.go
Normal file
29
log.go
Normal 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))
|
||||
}
|
|
@ -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)
|
||||
|
|
|
@ -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 {
|
||||
|
|
Loading…
Reference in a new issue