/
option.go
52 lines (41 loc) · 1.2 KB
/
option.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
43
44
45
46
47
48
49
50
51
52
package log
import (
"io"
logging "github.com/ipfs/fs-repo-migrations/fs-repo-6-to-7/gx/ipfs/QmQvJiADDe7JR4m968MwXobTCCzUqQkP87aRHe29MEBGHV/go-logging"
)
// Global writer group for logs to output to
var WriterGroup = NewMirrorWriter()
type Option func()
// Configure applies the provided options sequentially from left to right
func Configure(options ...Option) {
for _, f := range options {
f()
}
}
// LdJSONFormatter Option formats the event log as line-delimited JSON
var LdJSONFormatter = func() {
logging.SetFormatter(&PoliteJSONFormatter{})
}
// TextFormatter Option formats the event log as human-readable plain-text
var TextFormatter = func() {
logging.SetFormatter(logging.DefaultFormatter)
}
func Output(w io.Writer) Option {
return func() {
backend := logging.NewLogBackend(w, "", 0)
logging.SetBackend(backend)
// TODO return previous Output option
}
}
// LevelDebug Option sets the log level to debug
var LevelDebug = func() {
logging.SetLevel(logging.DEBUG, "")
}
// LevelError Option sets the log level to error
var LevelError = func() {
logging.SetLevel(logging.ERROR, "")
}
// LevelInfo Option sets the log level to info
var LevelInfo = func() {
logging.SetLevel(logging.INFO, "")
}