-
Notifications
You must be signed in to change notification settings - Fork 3
/
setup.go
52 lines (44 loc) · 842 Bytes
/
setup.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 logrusKit
import (
"github.com/sirupsen/logrus"
)
func MustSetUp(config *Config) {
err := SetUp(config)
if err != nil {
DisableQuote(nil)
logrus.Fatalf("%+v", err)
}
}
// SetUp
/*
PS: 可以多次调用.
@param config 可以为nil(debug级别、禁用双引号、不输出基本信息)
*/
func SetUp(config *Config) error {
if config == nil {
config = &Config{
Level: "debug",
EnableQuote: false,
PrintBasic: false,
}
}
logrus.SetFormatter(NewDefaultTextFormatter())
logrus.SetReportCaller(true)
/* Level */
level, err := StringToLevel(config.Level)
if err != nil {
return err
}
logrus.SetLevel(level)
/* EnableQuote */
if config.EnableQuote {
EnableQuote(nil)
} else {
DisableQuote(nil)
}
/* EnableQuote */
if config.PrintBasic {
PrintBasicDetails(nil)
}
return nil
}