pub struct SysLog;
impl SysLog
{
#[inline(always)]
pub fn caught_unwind(panic_payload: &(Any + 'static + Send))
{
use self::LogicalCoreChoice::*;
let logical_core_choice = match LogicalCoreChoice::current_logical_core()
{
Any => Self::to_c_string_robustly("Any"),
Specific(logical_core) => Self::to_c_string_robustly(format!("{}", logical_core)),
};
let cause = Self::to_c_string_robustly(Self::panic_payload_to_cause(panic_payload));
unsafe { syslog(LOG_ERR, ConstCStr(b"LogicalCore:%s:Cause:%s\0").as_ptr(), logical_core_choice, cause) }
}
#[inline(always)]
pub(crate) fn exit_signalled(signal_number: Option<SignalNumber>)
{
match signal_number
{
None => unsafe { syslog(LOG_NOTICE, ConstCStr(b"ExitSignalled:Other\0").as_ptr()) },
Some(signal_number) => unsafe { syslog(LOG_NOTICE, ConstCStr(b"ExitSignalled:%s\0").as_ptr(), strsignal(signal_number)) },
}
}
#[inline(always)]
pub fn panic_payload_to_cause(panic_payload: &(Any + 'static + Send)) -> String
{
if panic_payload.is::<String>()
{
panic_payload.downcast_ref::<String>().unwrap().to_string()
}
else if panic_payload.is::<&str>()
{
panic_payload.downcast_ref::<&str>().unwrap().to_string()
}
else
{
"(unknown cause)".to_string()
}
}
#[inline(always)]
pub fn to_c_string_robustly<T: Into<Vec<u8>>>(string: T) -> CString
{
#[inline(always)]
fn substitute_for_bad_c_string() -> CString
{
CString::new("?").unwrap()
}
CString::new(string).unwrap_or_else(|_| substitute_for_bad_c_string())
}
}