-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
43 lines (36 loc) · 928 Bytes
/
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
package main
import (
"fmt"
"os"
"github.com/getsentry/raven-go"
"gopkg.in/mcuadros/go-syslog.v2"
)
func main() {
channel := make(syslog.LogPartsChannel)
handler := syslog.NewChannelHandler(channel)
raven.SetDSN(os.Getenv("SENTRY_DSN"))
if os.Getenv("DEBUG") == "true" {
fmt.Println("Using Sentry DSN:", os.Getenv("SENTRY_DSN"))
}
server := syslog.NewServer()
server.SetFormat(syslog.RFC5424)
server.SetHandler(handler)
server.ListenTCP("0.0.0.0:10514")
server.Boot()
go func(channel syslog.LogPartsChannel) {
for logParts := range channel {
info := map[string]string{
"message": logParts["message"].(string),
"hostname": logParts["hostname"].(string),
}
if os.Getenv("DEBUG") == "true" {
fmt.Println(logParts)
fmt.Println("Sending", info)
}
if str, ok := logParts["message"].(string); ok {
raven.CaptureMessage(str, info, nil)
}
}
}(channel)
server.Wait()
}