Logrus test
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 package main | |
2 | |
3 import ( | |
4 "os" | |
5 | |
6 "github.com/sirupsen/logrus" | |
7 ) | |
8 | |
9 func main() { | |
10 log := logrus.New() | |
11 // set where we log | |
12 log.SetOutput(os.Stdout) | |
13 // set the levell | |
14 log.SetLevel(logrus.TraceLevel) | |
15 | |
16 // simple thing logged | |
17 log.Info("HELLO WORLD") | |
18 log.Warn("Warning for the WORLD") | |
19 | |
20 // more advanced | |
21 clog := log.WithFields(logrus.Fields{"id": 129923213, "user": "John"}) | |
22 clog.Info("John entered the room") | |
23 | |
24 // add one more level | |
25 | |
26 moreContext := clog.WithFields(logrus.Fields{"money": 1000}) | |
27 moreContext.Error("John left the building") | |
28 | |
29 // you can change gloval formatter | |
30 clog.Logger.SetFormatter(&logrus.JSONFormatter{}) | |
31 | |
32 // and change context value | |
33 moreContext = moreContext.WithField("user", "Jason") | |
34 moreContext = moreContext.WithField("id", 1) | |
35 moreContext.Error("John became a JASON") | |
36 | |
37 } | |
~ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment