aboutsummaryrefslogtreecommitdiffstats
path: root/core/log.go
blob: dea6cbb1d52f2eb3b235530628d5d12a08963beb (plain)
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
30
31
32
33
34
35
36
package core

import (
	"os"
	"strings"

	"github.com/sirupsen/logrus"
)

var (
	debug       = os.Getenv("DEBUG_GOVPP") != ""
	debugMsgIDs = strings.Contains(os.Getenv("DEBUG_GOVPP"), "msgid")

	log = logrus.New()
)

// init initializes global logger
func init() {
	log.Formatter = &logrus.TextFormatter{
		EnvironmentOverrideColors: true,
	}
	if debug {
		log.Level = logrus.DebugLevel
		log.Debugf("govpp: debug level enabled")
	}
}

// SetLogger sets global logger to l.
func SetLogger(l *logrus.Logger) {
	log = l
}

// SetLogLevel sets global logger level to lvl.
func SetLogLevel(lvl logrus.Level) {
	log.Level = lvl
}