aboutsummaryrefslogtreecommitdiff
path: root/log.go
blob: b2878156af20a3985b58c9d629ef8755f2d7387e (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
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))
}