@@ -21,6 +21,8 @@ type SyslogServer struct {
21
21
isActive bool
22
22
hostname string
23
23
hostip string
24
+ Rfc3164 bool
25
+ Rfc5424 bool
24
26
}
25
27
26
28
// initialize Syslog connection
@@ -55,7 +57,7 @@ func (ss *SyslogServer) Initialize() (bool, string) {
55
57
}
56
58
57
59
// Send allows to send a syslog message to the set server and port
58
- func (ss SyslogServer ) Send (message string , facility string , severity string ) {
60
+ func (ss * SyslogServer ) Send (message string , facility string , severity string ) {
59
61
var f = facilities [facility ]
60
62
var s = severities [severity ]
61
63
@@ -65,6 +67,14 @@ func (ss SyslogServer) Send(message string, facility string, severity string) {
65
67
hostnameCombi := fmt .Sprintf ("%s/%s" , ss .hostname , ss .hostip )
66
68
header := fmt .Sprintf ("<%d>%s %s" , pri , timestamp , hostnameCombi )
67
69
70
+ // RFC length reduction
71
+ if ss .Rfc3164 && len (message ) > 1024 {
72
+ message = fmt .Sprintf ("%s..." , message [:1020 ])
73
+ }
74
+ if ss .Rfc5424 && len (message ) > 2048 {
75
+ message = fmt .Sprintf ("%s..." , message [:2044 ])
76
+ }
77
+
68
78
// Full Message
69
79
full_message := fmt .Sprintf ("%s %s" , header , message )
70
80
@@ -73,7 +83,7 @@ func (ss SyslogServer) Send(message string, facility string, severity string) {
73
83
}
74
84
75
85
// Terminate closes the connection gracefully
76
- func (ss SyslogServer ) Terminate () {
86
+ func (ss * SyslogServer ) Terminate () {
77
87
ss .udpConn .Close ()
78
88
}
79
89
0 commit comments