Browse Source

Set logging level for Logrus and TDlib from config

master
bodqhrohro 3 years ago
parent
commit
0f047c3816
3 changed files with 38 additions and 7 deletions
  1. +29
    -0
      log.go
  2. +2
    -0
      telegabber.go
  3. +7
    -7
      telegram/client.go

+ 29
- 0
log.go 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))
}

+ 2
- 0
telegabber.go 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)


+ 7
- 7
telegram/client.go 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 {


Loading…
Cancel
Save