-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathloggly.go
39 lines (32 loc) · 1.03 KB
/
loggly.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
package vdlog
//https://github.com/segmentio/go-loggly/blob/master/loggly.go
import (
"bytes"
"fmt"
"net/http"
)
//const logglyURL = "logs-01.loggly.com/inputs/TOKEN/tag/http/"
func createLogglySync(token string, secure bool, logglyLogLevelTrigger EventLevel) func(e Event) error {
return func(e Event) error {
if e.Level > logglyLogLevelTrigger {
return nil
}
var logglyURL string
if secure {
logglyURL = fmt.Sprintf("https://logs-01.loggly.com/inputs/%s/tag/http", token)
} else {
logglyURL = fmt.Sprintf("http://logs-01.loggly.com/inputs/%s/tag/http", token)
}
body := bytes.NewBuffer(e.ToJSON())
resp, err := http.Post(logglyURL, "application/json; charset=utf-8", body)
if err != nil {
return err
}
defer resp.Body.Close()
return nil
}
}
//LogToLoggly allows to send messages to Loggly.com, if secure is true, https is used, which can increase security but reduce bandwidth
func LogToLoggly(token string, secure bool, level EventLevel) {
AddSink("loggly", createLogglySync(token, secure, level))
}