...
1
2
3 package logrus_test
4
5 import (
6 "log/syslog"
7 "os"
8
9 "github.com/sirupsen/logrus"
10 slhooks "github.com/sirupsen/logrus/hooks/syslog"
11 )
12
13
14 func Example_hook() {
15 var log = logrus.New()
16 log.Formatter = new(logrus.TextFormatter)
17 log.Formatter.(*logrus.TextFormatter).DisableColors = true
18 log.Formatter.(*logrus.TextFormatter).DisableTimestamp = true
19 if sl, err := slhooks.NewSyslogHook("udp", "localhost:514", syslog.LOG_INFO, ""); err == nil {
20 log.Hooks.Add(sl)
21 }
22 log.Out = os.Stdout
23
24 log.WithFields(logrus.Fields{
25 "animal": "walrus",
26 "size": 10,
27 }).Info("A group of walrus emerges from the ocean")
28
29 log.WithFields(logrus.Fields{
30 "omg": true,
31 "number": 122,
32 }).Warn("The group's number increased tremendously!")
33
34 log.WithFields(logrus.Fields{
35 "omg": true,
36 "number": 100,
37 }).Error("The ice breaks!")
38
39
40
41
42
43 }
44
View as plain text