forked from pires/kubernetes-elasticsearch-cluster
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_log.go
55 lines (45 loc) · 992 Bytes
/
test_log.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
package main
import (
"errors"
"net/http"
"os"
"time"
"github.com/apex/log"
"github.com/apex/log/handlers/es"
"github.com/apex/log/handlers/multi"
"github.com/apex/log/handlers/text"
"github.com/tj/go-elastic"
)
func main() {
esClient := elastic.New("http://host:9200")
esClient.HTTPClient = &http.Client{
Timeout: 5 * time.Second,
}
e := es.New(&es.Config{
Client: esClient,
Format: "test-es",
BufferSize: 100,
})
t := text.New(os.Stderr)
log.SetHandler(multi.New(e, t))
ctx := log.WithFields(log.Fields{
"file": "something.png",
"type": "image/png",
"user": "tobi",
})
go func() {
for range time.Tick(time.Millisecond * 200) {
ctx.Info("upload")
ctx.Info("upload complete")
ctx.Warn("upload retry")
ctx.WithError(errors.New("unauthorized")).Error("upload failed")
ctx.Errorf("failed to upload %s", "img.png")
}
}()
go func() {
for range time.Tick(time.Millisecond * 25) {
ctx.Info("upload")
}
}()
select {}
}