-
Notifications
You must be signed in to change notification settings - Fork 1
/
log.go
34 lines (28 loc) · 886 Bytes
/
log.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
package main
import (
"io/ioutil"
"os"
"github.com/op/go-logging"
)
var Log = logging.MustGetLogger("vasuki")
func init() {
// Example format string. Everything except the message has a custom color
// which is dependent on the log level. Many fields have a custom output
// formatting too, eg. the time returns the hour down to the milli second.
var format = logging.MustStringFormatter(
`%{color}%{time:15:04:05.000} %{shortfile} ▶ %{level:.10s} %{id:04d}%{color:reset} %{message}`,
)
stdout := logging.NewLogBackend(os.Stdout, "", 0)
formattedStdout := logging.NewBackendFormatter(stdout, format)
logging.SetBackend(formattedStdout)
logging.SetLevel(logging.INFO, "")
}
func EnableDebug(enable bool) {
if enable {
logging.SetLevel(logging.DEBUG, "")
}
}
// Used in tests
func MuteLogs() {
logging.SetBackend(logging.NewLogBackend(ioutil.Discard, "", 0))
}