8000 Added example of timer by vigna · Pull Request #356 · rust-cli/env_logger · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Added example of timer #356

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open

Added example of timer #356

wants to merge 1 commit into from

Conversation

vigna
Copy link
@vigna vigna commented Mar 28, 2025

No description provided.

Comment on lines +259 to +274
//! ## Using the Logger as a Timer
//!
//! `env_logger` can also be used as a timer by moving an initial
//! timestamp into the closure defining a custom format:
//!
//! ```
//! use std::io::Write;
//!
//! let start = std::time::Instant::now();
//! env_logger::builder()
//! .format(move |buf, record| {
//! writeln!(buf, "{} ({}): {}", record.level(), start.elapsed().as_millis(), record.args())
//! })
//! .init();
//! ```
//!
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was assuming this would be created as another example in examples/. The advantage of this is its easier to interactively play with to see the results.

If its being added to the docs, putting it on Builder::format might be a better approach.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So sorry to disappoint your expectations 😆.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants
0