-
Notifications
You must be signed in to change notification settings - Fork 13
/
output_examples_test.go
97 lines (86 loc) · 2.44 KB
/
output_examples_test.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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
package xlog_test
import (
"log/syslog"
"github.com/rs/xlog"
)
func Example_combinedOutputs() {
conf := xlog.Config{
Output: xlog.NewOutputChannel(xlog.MultiOutput{
// Output interesting messages to console
0: xlog.FilterOutput{
Cond: func(fields map[string]interface{}) bool {
val, found := fields["type"]
return found && val == "interesting"
},
Output: xlog.NewConsoleOutput(),
},
// Also setup by-level loggers
1: xlog.LevelOutput{
// Send debug messages to console if they match type
Debug: xlog.FilterOutput{
Cond: func(fields map[string]interface{}) bool {
val, found := fields["type"]
return found && val == "interesting"
},
Output: xlog.NewConsoleOutput(),
},
},
// Also send everything over syslog
2: xlog.NewSyslogOutput("", "", ""),
}),
}
lh := xlog.NewHandler(conf)
_ = lh
}
func ExampleMultiOutput() {
conf := xlog.Config{
Output: xlog.NewOutputChannel(xlog.MultiOutput{
// Output everything to console
0: xlog.NewConsoleOutput(),
// and also to local syslog
1: xlog.NewSyslogOutput("", "", ""),
}),
}
lh := xlog.NewHandler(conf)
_ = lh
}
func ExampleFilterOutput() {
conf := xlog.Config{
Output: xlog.NewOutputChannel(xlog.FilterOutput{
// Match messages containing a field type = interesting
Cond: func(fields map[string]interface{}) bool {
val, found := fields["type"]
return found && val == "interesting"
},
// Output matching messages to the console
Output: xlog.NewConsoleOutput(),
}),
}
lh := xlog.NewHandler(conf)
_ = lh
}
func ExampleLevelOutput() {
conf := xlog.Config{
Output: xlog.NewOutputChannel(xlog.LevelOutput{
// Send debug message to console
Debug: xlog.NewConsoleOutput(),
// and error messages to syslog
Error: xlog.NewSyslogOutput("", "", ""),
// other levels are discarded
}),
}
lh := xlog.NewHandler(conf)
_ = lh
}
func ExampleNewSyslogWriter() {
conf := xlog.Config{
Output: xlog.NewOutputChannel(xlog.LevelOutput{
Debug: xlog.NewLogstashOutput(xlog.NewSyslogWriter("", "", syslog.LOG_LOCAL0|syslog.LOG_DEBUG, "")),
Info: xlog.NewLogstashOutput(xlog.NewSyslogWriter("", "", syslog.LOG_LOCAL0|syslog.LOG_INFO, "")),
Warn: xlog.NewLogstashOutput(xlog.NewSyslogWriter("", "", syslog.LOG_LOCAL0|syslog.LOG_WARNING, "")),
Error: xlog.NewLogstashOutput(xlog.NewSyslogWriter("", "", syslog.LOG_LOCAL0|syslog.LOG_ERR, "")),
}),
}
lh := xlog.NewHandler(conf)
_ = lh
}