-
Notifications
You must be signed in to change notification settings - Fork 0
/
push-message.go
44 lines (33 loc) · 1.02 KB
/
push-message.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
package logstash_logger
import (
"encoding/json"
"log"
)
func (l *Logstash) pushJsonMessage(jsonMsg map[string]interface{}) {
l.initLoggerConnection()
if l.connection == nil {
log.Println("[Logstash Logger] Logger was not initialized properly, could not push message.")
return
}
jsonData, err := json.Marshal(jsonMsg)
if err != nil {
log.Printf("[Logstash Logger] Failed to parse JSON object: %s\n", err)
}
_, connWriteError := l.connection.Write(jsonData)
if connWriteError != nil {
log.Printf("[Logstash Logger] Failed to send log JSON message: %s\n", connWriteError)
}
l.connection.Close()
}
func (l *Logstash) pushStringMessage(stringMsg string) {
l.initLoggerConnection()
if l.connection == nil {
log.Println("[Logstash Logger] Logger was not initialized properly, could not push message.")
return
}
_, connWriteError := l.connection.Write([]byte(stringMsg))
if connWriteError != nil {
log.Printf("[Logstash Logger] Failed to send log String message: %s\n", connWriteError)
}
l.connection.Close()
}