Skip to content

Exposing init_logger to the public API for uniform logging across preprocessors #2049

@jeertmans

Description

@jeertmans

Problem

Currently, all preprocessors need to call their own logging library. As calls to preprocessors are done within the main mdBook process, it would make sense to have a uniform logger across all preprocessors, so that when they log messages, it does not look weird compared to mdBook's own logging.

Proposed Solution

Move main::init_logger to utils::init_logger and make it public, so that people can opt in for the same logger as mdBook.

mdBook/src/main.rs

Lines 97 to 121 in efb671a

fn init_logger() {
let mut builder = Builder::new();
builder.format(|formatter, record| {
writeln!(
formatter,
"{} [{}] ({}): {}",
Local::now().format("%Y-%m-%d %H:%M:%S"),
record.level(),
record.target(),
record.args()
)
});
if let Ok(var) = env::var("RUST_LOG") {
builder.parse_filters(&var);
} else {
// if no RUST_LOG provided, default to logging at the Info level
builder.filter(None, LevelFilter::Info);
// Filter extraneous html5ever not-implemented messages
builder.filter(Some("html5ever"), LevelFilter::Error);
}
builder.init();
}

Notes

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-enhancementCategory: Enhancement or feature request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions