emabee/flexi_logger

SyslogWriter needs to append LF to buffer when try_tcp is used for connection

griffdp opened this issue · 0 comments

It appears that rsyslog by default uses the LF character as the delimiter for messages received via plaintext TCP.

With flexilogger v0.23.3, log messages sent via UDP result in correctly formatted (1 log message per line) log files.
Sending the same log messages via TCP results in no line separation between log messages in the log file:

    Logger::try_with_str("debug")?
        .log_to_writer(SyslogWriter::try_new(
            UserLevel,
            None,
            LevelFilter::Off,
            String::from("my-app"),
            Syslog::try_tcp("127.0.0.1:1514")?,
        )?)
        .start()?;
 
    info!("my-app started");
    info!("my-app doing something");
    info!("my-app idle");

Temporarily amending the Rfc5424 format string for the write function of LogWriter for SyslogWriter in src/writers/syslog_writer.rs to append a LF character produces correctly separated log lines in the log file:

"<{pri}>{version} {timestamp} {hostname} {appname} {procid} {msgid} - {msg}",
to
"<{pri}>{version} {timestamp} {hostname} {appname} {procid} {msgid} - {msg}\n",

This would need to be done only when the syslog connection is TCP.