-
Notifications
You must be signed in to change notification settings - Fork 5
/
logging.go
49 lines (39 loc) · 1.04 KB
/
logging.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
/**
* @Author: kiosk
* @Mail: weijiaxiang007@foxmail.com
* @Date: 2020/12/27
**/
package utils
import (
"fmt"
"github.com/rs/zerolog"
"os"
"strings"
"time"
)
var Logging zerolog.Logger
func init() {
// Default level for this example is info, unless debug flag is present
zerolog.SetGlobalLevel(zerolog.InfoLevel)
output := zerolog.ConsoleWriter{Out: os.Stdout, TimeFormat: time.RFC3339}
output.FormatLevel = func(i interface{}) string {
return strings.ToUpper(fmt.Sprintf("| %-6s|", i))
}
output.FormatMessage = func(i interface{}) string {
return fmt.Sprintf("** %s **", i)
}
output.FormatFieldName = func(i interface{}) string {
return fmt.Sprintf("%s:", i)
}
output.FormatFieldValue = func(i interface{}) string {
return strings.ToUpper(fmt.Sprintf("%s", i))
}
Logging = zerolog.New(output).With().Timestamp().Caller().Logger()
Logging = Logging.Output(zerolog.ConsoleWriter{Out: os.Stderr})
}
func SetDebugLevel() {
zerolog.SetGlobalLevel(zerolog.DebugLevel)
}
func SetQuietLevel() {
zerolog.SetGlobalLevel(zerolog.Disabled)
}