macro_rules! custom_print {
(
$level:expr, $level_char_control:expr, $level_char:expr,
$sep_char_control:expr, $sep_char:expr, $text_control:expr,
$($fmt_args:tt)*
) => { ... };
}Available on crate feature
print only.Expand description
Print message with a custom log format and level.
This lets you customize the “level char”, the separator char, and the colors for level char, separator char, and the main text color. Note that if colors are disabled from CLI (–color=never), the control sequences are replaced with empty string.
static GREEN: &str = "\x1b[92m";
static RED: &str = "\x1b[91m";
static YELLOW: &str = "\x1b[93m";
static RESET: &str = "\x1b[0m";
/// This logs P) in green
macro_rules! pass {
($($args:tt)*) => { cu::custom_print!(cu::lv::I, GREEN, 'P', "", ')', GREEN, $($args)*) }
}
/// This logs F) in red
macro_rules! fail {
($($args:tt)*) => { cu::custom_print!(cu::lv::E, RED, 'F', "", ')', RED, $($args)*) }
}
let count = 5;
pass!("{count} tests passed");
fail!("{count} tests failed");
// the part after reset remains red
fail!("{YELLOW}some{RESET} tests failed");