-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.go
More file actions
98 lines (86 loc) · 3.03 KB
/
Copy pathmain.go
File metadata and controls
98 lines (86 loc) · 3.03 KB
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
98
package main
import (
"log"
"github.com/mateothegreat/multilog"
)
type CustomLogData struct {
Foo string `json:"foo"`
Bar int `json:"bar"`
}
func init() {
multilog.RegisterLogger(multilog.LogMethod("console"), multilog.NewConsoleLogger(&multilog.NewConsoleLoggerArgs{
Level: multilog.TRACE,
Format: multilog.FormatText,
FilterDropPatterns: []*string{
multilog.PtrString("block_this_group"),
multilog.PtrString(".*drop.*"), // Drop any message that contains the word "drop"
},
}))
// The elasticsearch logger lives in a separate submodule; import it as:
//
// import (
// "crypto/tls"
// "net/http"
//
// elasticsearch "github.com/mateothegreat/multilog/logger/elasticsearch"
// )
//
// multilog.RegisterLogger(multilog.LogMethod("elasticsearch"), elasticsearch.NewElasticsearchLogger(&elasticsearch.NewElasticsearchLoggerArgs{
// Level: multilog.TRACE,
// Config: elasticsearch.Config{ // Alias for go-elasticsearch v8 Config.
// Addresses: []string{"https://localhost:9200"},
// Username: "elastic",
// Password: "elastic",
// Transport: &http.Transport{
// TLSClientConfig: &tls.Config{
// InsecureSkipVerify: true,
// },
// },
// },
// Index: "logs-3",
// Mapping: elasticsearch.DefaultMapping, // Or a custom mapping string; "" creates the index without a mapping.
// FilterDropPatterns: []*string{
// multilog.PtrString(".*drop.*"), // Drop any message that contains the word "drop"
// },
// }))
multilog.RegisterLogger(multilog.LogMethod("customerLogger1"), &multilog.CustomLogger{
Log: func(level multilog.LogLevel, group string, message string, v map[string]interface{}) {
log.Printf("logged via customerLogger1: %s: %s", group, message)
},
})
// Register a custom logger:
customLogger1 := multilog.NewLogger(multilog.LogMethod("customerLogger2"))
// If needed, you can do stuff here when the logger is setup such as
// connecting to something like elasticsearch or whatever:
customLogger1.Setup = func() {
log.Println("Setup customerLogger2")
}
// Define the log method:
customLogger1.Log = func(level multilog.LogLevel, group string, message string, v map[string]interface{}) {
log.Printf("logged via customerLogger: %s: %s", group, message)
}
}
func main() {
multilog.Debug("my_package_name", "test", map[string]interface{}{
"foo": "foo",
"bar": 1,
})
multilog.Warn("my_package_name", "it's about to explode...", map[string]interface{}{
"foo": "boom",
"bar": 1234234234234,
})
multilog.Error("my_package_name", "some error!", map[string]interface{}{
"foo": "bad things happened bro",
"bar": 123,
})
multilog.Info("my_package_name", "some verbose info..", map[string]interface{}{
"foo": "it's happpeeennning!!!",
"bar": 234234234,
})
multilog.Fatal("my_package_name", "this will crash", map[string]interface{}{
"foo": "boom",
"bar": 1234234234234,
})
multilog.Trace("nobody_cares_about_this", "this message will get dropped by the filters", nil)
multilog.Error("block_this_group", "this message will get dropped by the filters", nil)
}