forked from muka/peerjs-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
logger.go
42 lines (35 loc) · 773 Bytes
/
logger.go
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
37
38
39
40
41
42
package peer
import (
"github.com/sirupsen/logrus"
)
func createLogger(source string, debugLevel int8) *logrus.Entry {
log := logrus.New()
// 0 Prints no logs.
// 1 Prints only errors.
// 2 Prints errors and warnings.
// 3 Prints all logs.
switch debugLevel {
case 0:
log.SetLevel(logrus.PanicLevel)
break
case 1:
log.SetLevel(logrus.ErrorLevel)
break
case 2:
log.SetLevel(logrus.WarnLevel)
break
default:
log.SetLevel(logrus.DebugLevel)
break
}
//TODO configure logger format
// log.SetFormatter(&logrus.JSONFormatter{})
log.SetFormatter(&logrus.TextFormatter{})
// log to stderr by default
// log.SetOutput(os.Stderr)
// log.SetOutput(os.Stdout)
return log.WithFields(logrus.Fields{
"module": "peer",
"source": source,
})
}