macro_rules! impl_syslog_sender_common {
($sender:ident) => {
impl $sender {
pub fn send_rfc3164<M: std::fmt::Display>(
&mut self,
severity: $crate::Severity,
message: M,
) -> std::io::Result<()> {
let message = self.context.format_rfc3164(severity, Some(message));
self.send_formatted(message.to_string().as_bytes())
}
pub fn send_rfc5424<S: Into<String>, M: std::fmt::Display>(
&mut self,
severity: $crate::Severity,
msgid: Option<S>,
elements: Vec<$crate::SDElement>,
message: M,
) -> std::io::Result<()> {
let message = self
.context
.format_rfc5424(severity, msgid, elements, Some(message));
self.send_formatted(message.to_string().as_bytes())
}
}
};
}
pub(crate) use impl_syslog_sender_common;
macro_rules! impl_syslog_stream_send_formatted {
($sender:ident) => {
impl $sender {
pub fn send_formatted(&mut self, message: &[u8]) -> std::io::Result<()> {
use std::io::Write;
self.writer.write_all(message)?;
self.writer.write_all(self.postfix.as_bytes())?;
Ok(())
}
pub fn flush(&mut self) -> std::io::Result<()> {
use std::io::Write;
self.writer.flush()
}
}
};
}
pub(crate) use impl_syslog_stream_send_formatted;