Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
jeertmans opened this issue Mar 16, 2023 · 0 comments
Labels
C-enhancement Category: Enhancement or feature request

Comments

@jeertmans
Copy link

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

@jeertmans jeertmans added the C-enhancement Category: Enhancement or feature request label Mar 16, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-enhancement Category: Enhancement or feature request
Projects
None yet
Development

No branches or pull requests

1 participant