-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
61 lines (54 loc) · 1.55 KB
/
main.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
package main
import (
"crypto/tls"
"net/http"
"github.com/elastic/go-elasticsearch/v8"
"github.com/mateothegreat/go-multilog/multilog"
)
type CustomLogData struct {
Foo string `json:"foo"`
Bar int `json:"bar"`
}
func init() {
multilog.RegisterLogger(multilog.LogMethod("console"), multilog.NewConsoleLogger(&multilog.NewConsoleLoggerArgs{
Format: multilog.FormatText,
FilterDropPatterns: []*string{
multilog.PtrString("block_this_group"),
multilog.PtrString(".*drop.*"), // Drop any message that contains the word "drop"
},
}))
mapping := `
{
"mappings": {
"properties": {
"time": { "type": "date" },
"level": { "type": "keyword" },
"group": { "type": "keyword" },
"message": { "type": "text" },
"data": { "type": "object" }
}
}
}`
multilog.RegisterLogger(multilog.LogMethod("elasticsearch"), multilog.NewElasticsearchLogger(&multilog.NewElasticsearchLoggerArgs{
Config: elasticsearch.Config{
Addresses: []string{"https://localhost:9200"},
Username: "elastic",
Password: "elastic",
Transport: &http.Transport{
TLSClientConfig: &tls.Config{
InsecureSkipVerify: true,
},
},
},
Index: "logs-3",
Mapping: &mapping,
FilterDropPatterns: []*string{
multilog.PtrString("block_this_group"),
multilog.PtrString(".*drop.*"), // Drop any message that contains the word "drop"
},
}))
}
func main() {
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)
}