Skip to content

Commit

Permalink
feat(syslog): remove the timestamp from the log message
Browse files Browse the repository at this point in the history
  • Loading branch information
tgragnato committed Sep 9, 2024
1 parent 89b9f99 commit e500ea0
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion transport/syslog/transport.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,27 @@ import (
"flag"
"log"
"log/syslog"
"strings"

"github.com/tgragnato/goflow/transport"
)

type customWriter struct {
writer *syslog.Writer
}

func (cw *customWriter) Write(p []byte) (n int, err error) {
message := string(p)
parts := strings.SplitN(message, " ", 3)
if len(parts) == 3 {
// Remove the timestamp from the log message (YYYY/MM/DD HH:MM:SS message)
message = parts[2]
// Remove leading and trailing whitespaces
message = strings.TrimSpace(message)
}
return cw.writer.Write([]byte(message))
}

type SyslogDriver struct {
protocol string
address string
Expand All @@ -26,7 +43,7 @@ func (s *SyslogDriver) Init() error {
return errors.New("Failed to connect to remote syslog server: " + err.Error())
}

log.SetOutput(remoteSyslog)
log.SetOutput(&customWriter{writer: remoteSyslog})
return nil
}

Expand Down

0 comments on commit e500ea0

Please sign in to comment.