macro_rules! g_log {
($log_level:expr, $format:literal $(,$arg:expr)* $(,)?) => { ... };
($log_domain:expr, $log_level:expr, $format:literal $(,$arg:expr)* $(,)?) => { ... };
}
Expand description
Macro used to log using GLib logging system. It uses g_log.
Example:
use glib::{LogLevel, g_log};
g_log!("test", LogLevel::Debug, "test");
g_log!("test", LogLevel::Message, "test");
// trailing commas work as well:
g_log!("test", LogLevel::Message, "test",);
// You can also pass arguments like in format! or println!:
let x = 12;
g_log!("test", LogLevel::Error, "test: {}", x);
g_log!("test", LogLevel::Critical, "test: {}", x);
g_log!("test", LogLevel::Warning, "test: {} {}", x, "a");
// trailing commas work as well:
g_log!("test", LogLevel::Warning, "test: {} {}", x, "a",);
To be noted that the log domain is optional:
use glib::{LogLevel, g_log};
// As you can see: no log domain:
g_log!(LogLevel::Message, "test");
// For the rest, it's just like when you have the log domain:
// trailing commas:
g_log!(LogLevel::Message, "test",);
// formatting:
let x = 12;
g_log!(LogLevel::Warning, "test: {} {}", x, "a");
g_log!(LogLevel::Warning, "test: {} {}", x, "a",);