Function defmt_decoder::log::init_logger

source ·
pub fn init_logger(
    log_format: Option<&str>,
    host_log_format: Option<&str>,
    json: bool,
    should_log: impl Fn(&Metadata<'_>) -> bool + Sync + Send + 'static
) -> DefmtLoggerInfo
Available on unstable only.
Expand description

Initializes a log sink that handles defmt frames.

Defmt frames will be printed to stdout, other logs to stderr.

The caller has to provide a should_log closure that determines whether a log record should be printed.

An optional log_format string can be provided to format the way logs are printed. A format string could look as follows: “{t} [{L}] Location<{f}:{l}> {s}”

The arguments between curly braces are placeholders for log metadata. The following arguments are supported:

  • {f} : file name (e.g. “main.rs”)
  • {F} : file path (e.g. “src/bin/main.rs”)
  • {l} : line number
  • {L} : log level (e.g. “INFO”, “DEBUG”, etc)
  • {m} : module path (e.g. “foo::bar::some_function”)
  • {s} : the actual log
  • {t} : log timestamp

For example, with the log format shown above, a log would look like this: “23124 [INFO] Locationmain.rs:23 Hello, world!”