-
Notifications
You must be signed in to change notification settings - Fork 0
/
main_logrus.go
56 lines (44 loc) · 1.07 KB
/
main_logrus.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
53
54
55
56
/*
@Time : 2020/5/18 10:38
@Author : ZhaoJunfeng
@File : main
*/
package main
import (
"os"
"github.com/sirupsen/logrus"
)
// Create a new instance of the logger. You can have any number of instances.
var log = logrus.New()
var logger *logrus.Entry
func init() {
log.Formatter = new(logrus.JSONFormatter)
log.Out = os.Stdout
log.Level = logrus.TraceLevel
log.SetReportCaller(true)
logger= log.WithFields(logrus.Fields{
"common": "this is a common field",
"other": "I also should be logged always",
})
}
func main() {
logger.WithFields(logrus.Fields{
"animal": "walrus",
"number": 0,
}).Trace("Went to the beach")
logger.WithFields(logrus.Fields{
"animal": "walrus",
"number": 8,
}).Debug("Started observing beach")
logger.WithFields(logrus.Fields{
"animal": "walrus",
"size": 10,
}).Info("A group of walrus emerges from the ocean")
logger.WithFields(logrus.Fields{
"omg": true,
"number": 122,
}).Warn("The group's number increased tremendously!")
logger.WithFields(logrus.Fields{
"temperature": -4,
}).Debug("Temperature changes")
}