Reimplement logging macros in terms of log_event!

Avoid copy-paste message formatting code in src/log.rs, forwarding all
arguments of info! warn! error! macros to generic log_event! macro.
This commit is contained in:
Dmitry Bogatov
2019-09-10 21:42:53 +00:00
parent 57daa0f7f0
commit 7ed5a8e72f

View File

@@ -4,13 +4,8 @@ macro_rules! info {
info!($ctx, $msg,)
};
($ctx:expr, $msg:expr, $($args:expr),* $(,)?) => {
#[allow(unused_unsafe)]
unsafe {
let formatted = format!($msg, $($args),*);
let formatted_c = std::ffi::CString::new(formatted).unwrap();
$ctx.call_cb($crate::constants::Event::INFO, 0,
formatted_c.as_ptr() as libc::uintptr_t);
}};
log_event!($ctx, $crate::constants::Event::INFO, 0, $msg, $($args),*);
};
}
#[macro_export]
@@ -19,13 +14,8 @@ macro_rules! warn {
warn!($ctx, $msg,)
};
($ctx:expr, $msg:expr, $($args:expr),* $(,)?) => {
#[allow(unused_unsafe)]
unsafe {
let formatted = format!($msg, $($args),*);
let formatted_c = std::ffi::CString::new(formatted).unwrap();
$ctx.call_cb($crate::constants::Event::WARNING, 0,
formatted_c.as_ptr() as libc::uintptr_t);
}};
log_event!($ctx, $crate::constants::Event::WARNING, 0, $msg, $($args),*);
};
}
#[macro_export]
@@ -34,13 +24,8 @@ macro_rules! error {
error!($ctx, $msg,)
};
($ctx:expr, $msg:expr, $($args:expr),* $(,)?) => {
#[allow(unused_unsafe)]
unsafe {
let formatted = format!($msg, $($args),*);
let formatted_c = std::ffi::CString::new(formatted).unwrap();
$ctx.call_cb($crate::constants::Event::ERROR, 0,
formatted_c.as_ptr() as libc::uintptr_t);
}};
log_event!($ctx, $crate::constants::Event::ERROR, 0, $msg, $($args),*);
};
}
#[macro_export]