-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
45 lines (37 loc) · 984 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
44
45
package main
import (
"bytes"
"encoding/json"
"fmt"
"gopkg.in/mcuadros/go-syslog.v2"
)
func main() {
channel := make(syslog.LogPartsChannel)
handler := syslog.NewChannelHandler(channel)
server := syslog.NewServer()
server.SetFormat(syslog.Automatic)
server.SetHandler(handler)
server.ListenUDP("0.0.0.0:514")
server.ListenTCP("0.0.0.0:514")
server.Boot()
go func(channel syslog.LogPartsChannel) {
for logParts := range channel {
fmt.Println(logParts)
message, ok := logParts["message"].(string)
if !ok {
message, ok = logParts["content"].(string)
if !ok {
fmt.Println("Errore nel recupero del messaggio dal logParts")
continue
}
}
var prettyJSON bytes.Buffer
if err := json.Indent(&prettyJSON, []byte(message), "", " "); err != nil {
fmt.Printf("Errore nella formattazione del JSON: %s\n", err.Error())
} else {
fmt.Printf("Log JSON ricevuto: %s\n", prettyJSON.String())
}
}
}(channel)
server.Wait()
}