#[derive(Debug)]
pub struct SyslogFormatted
{
msg_header: Option<String>,
msg_payload: String,
full_msg: Option<String>,
}
impl SyslogFormatted
{
pub
fn new(msg_header: Option<String>, msg_payload: String) -> Self
{
return Self{ msg_header: msg_header, msg_payload: msg_payload, full_msg: None };
}
pub(crate)
fn get_stderr_output(&self) -> &str
{
return &self.msg_payload;
}
pub(crate)
fn get_full_msg(&mut self) -> &str
{
if self.full_msg.is_some() == true
{
return self.full_msg.as_ref().unwrap();
}
else
{
let header=
if self.msg_header.is_some() == true
{
let msg = [self.msg_header.as_ref().unwrap().as_str(), self.msg_payload.as_str()].concat();
self.full_msg.replace(msg);
self.full_msg.as_ref().unwrap().as_str()
}
else
{
self.msg_payload.as_ref()
};
return header;
}
}
}
pub trait SyslogFormatter: std::fmt::Debug + Send + Clone + From<String> + From<&'static str> + 'static
{
fn vsyslog1_format(&self, max_msg_size: usize, prifac: SyslogMsgPriFac, progname: &str, pid: Option<&str>) -> SyslogFormatted;
}
#[cfg(target_os = "windows")]
pub mod windows_10;
pub mod syslog_3146;
pub mod syslog_5424;
pub mod syslog_file;
pub use syslog_3146::FormatRfc3146;
pub use syslog_5424::FormatRfc5424;
pub use syslog_file::FormatFile;
#[cfg(target_os = "windows")]
pub use windows_10::FormatWindows;
use crate::{SyslogMsgPriFac};
#[cfg(target_os = "linux")]
pub type DefaultSyslogFormatter = FormatRfc3146;
#[cfg(any(
target_os = "freebsd",
target_os = "dragonfly",
target_os = "openbsd",
target_os = "netbsd",
target_os = "macos"
))]
pub type DefaultSyslogFormatter = FormatRfc5424;
#[cfg(target_os = "windows")]
pub type DefaultSyslogFormatter = FormatWindows;
pub type DefaultSyslogFormatterFile = FormatFile;