pub fn initialize_with_formatter(filename_prefix: &str, formatter: FormatFn)
Expand description
Initializes the current process/thread with a logger, parsing the RUST_LOG environment variables to set the logging level filter and/or directives to set a filter by module name, following the usual env_logger conventions. The format function specifies the format in which the logs will be printed.
To allow for recursive log invocations (a log happening in an argument to log), the format function must take care of reifying the record’s argument before taking the reference to the writer, at the risk of causing double-borrows runtime panics otherwise.
Must be called on every running thread, or else logging will panic the first time it’s used.
use file_per_thread_logger::{initialize_with_formatter, FormatFn};
use std::io::Write;
let formatter: FormatFn = |writer, record| {
// Reify arguments first, to allow for recursive log invocations.
let args = format!("{}", record.args());
writeln!(
writer,
"{} [{}:{}] {}",
record.level(),
record.file().unwrap_or_default(),
record.line().unwrap_or_default(),
args,
)
};
initialize_with_formatter("log-file-prefix", formatter);