mirror of
https://github.com/chatmail/core.git
synced 2026-05-02 21:06:31 +03:00
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:
27
src/log.rs
27
src/log.rs
@@ -4,13 +4,8 @@ macro_rules! info {
|
|||||||
info!($ctx, $msg,)
|
info!($ctx, $msg,)
|
||||||
};
|
};
|
||||||
($ctx:expr, $msg:expr, $($args:expr),* $(,)?) => {
|
($ctx:expr, $msg:expr, $($args:expr),* $(,)?) => {
|
||||||
#[allow(unused_unsafe)]
|
log_event!($ctx, $crate::constants::Event::INFO, 0, $msg, $($args),*);
|
||||||
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);
|
|
||||||
}};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[macro_export]
|
#[macro_export]
|
||||||
@@ -19,13 +14,8 @@ macro_rules! warn {
|
|||||||
warn!($ctx, $msg,)
|
warn!($ctx, $msg,)
|
||||||
};
|
};
|
||||||
($ctx:expr, $msg:expr, $($args:expr),* $(,)?) => {
|
($ctx:expr, $msg:expr, $($args:expr),* $(,)?) => {
|
||||||
#[allow(unused_unsafe)]
|
log_event!($ctx, $crate::constants::Event::WARNING, 0, $msg, $($args),*);
|
||||||
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);
|
|
||||||
}};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[macro_export]
|
#[macro_export]
|
||||||
@@ -34,13 +24,8 @@ macro_rules! error {
|
|||||||
error!($ctx, $msg,)
|
error!($ctx, $msg,)
|
||||||
};
|
};
|
||||||
($ctx:expr, $msg:expr, $($args:expr),* $(,)?) => {
|
($ctx:expr, $msg:expr, $($args:expr),* $(,)?) => {
|
||||||
#[allow(unused_unsafe)]
|
log_event!($ctx, $crate::constants::Event::ERROR, 0, $msg, $($args),*);
|
||||||
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);
|
|
||||||
}};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[macro_export]
|
#[macro_export]
|
||||||
|
|||||||
Reference in New Issue
Block a user