remote syslog: one Write() call per \n-terminated line

We don’t want newlines in individual remote syslog lines.
This commit is contained in:
Michael Stapelberg 2020-07-19 17:26:11 +02:00
parent a4c823dc2b
commit 11dacf4264

View File

@ -75,8 +75,11 @@ func (w *remoteSyslogWriter) Write(b []byte) (int, error) {
w.lines.Write(b)
w.syslogMu.Lock()
defer w.syslogMu.Unlock()
if w.syslog != nil {
w.syslog.Write(b)
if w.syslog == nil {
return len(b), nil
}
for _, line := range strings.Split(strings.TrimSpace(string(b)), "\n") {
w.syslog.Write([]byte(line + "\n"))
}
return len(b), nil
}