Skip to content

Commit f5b5ead

Browse files
committed
v0.2
Length restrictions in the different RFC standards
1 parent 395254f commit f5b5ead

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

simplesyslog.go

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ type SyslogServer struct {
2121
isActive bool
2222
hostname string
2323
hostip string
24+
Rfc3164 bool
25+
Rfc5424 bool
2426
}
2527

2628
// initialize Syslog connection
@@ -55,7 +57,7 @@ func (ss *SyslogServer) Initialize() (bool, string) {
5557
}
5658

5759
// 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) {
5961
var f = facilities[facility]
6062
var s = severities[severity]
6163

@@ -65,6 +67,14 @@ func (ss SyslogServer) Send(message string, facility string, severity string) {
6567
hostnameCombi := fmt.Sprintf("%s/%s", ss.hostname, ss.hostip)
6668
header := fmt.Sprintf("<%d>%s %s", pri, timestamp, hostnameCombi)
6769

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+
6878
// Full Message
6979
full_message := fmt.Sprintf("%s %s", header, message)
7080

@@ -73,7 +83,7 @@ func (ss SyslogServer) Send(message string, facility string, severity string) {
7383
}
7484

7585
// Terminate closes the connection gracefully
76-
func (ss SyslogServer) Terminate() {
86+
func (ss *SyslogServer) Terminate() {
7787
ss.udpConn.Close()
7888
}
7989

0 commit comments

Comments
 (0)