macro_rules! log {
(logger: $logger:expr, target: $target:expr, $lvl:expr, $($arg:tt)+) => { ... };
(logger: $logger:expr, $lvl:expr, $($arg:tt)+) => { ... };
(target: $target:expr, $lvl:expr, $($arg:tt)+) => { ... };
($lvl:expr, $($arg:tt)+) => { ... };
}
Expand description
The standard logging macro.
This macro will generically log with the specified Level
and format!
based argument list.
use log::{log, Level};
let data = (42, "Forty-two");
let private_data = "private";
log!(Level::Error, "Received errors: {}, {}", data.0, data.1);
Optionally, you can specify a target
argument to attach a specific target
to the log record. By default, the target is the module path of the caller.
use log::{log, Level};
let data = (42, "Forty-two");
let private_data = "private";
log!(
target: "app_events",
Level::Error,
"Received errors: {}, {}",
data.0, data.1
);
And optionally, you can specify a logger
argument to use a specific logger
instead of the default global logger.
use log::{log, Level, Log};
let data = (42, "Forty-two");
let private_data = "private";
let my_logger = MyLogger {};
log!(
logger: my_logger,
Level::Error,
"Received errors: {}, {}",
data.0, data.1
);
The logger
argument accepts a value that implements the Log
trait. The value
will be borrowed within the macro.
Note that the global level set via Cargo features, or through set_max_level
will
still apply, even when a custom logger is supplied with the logger
argument.