Skip to content

Add example for millisecond since init #355

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
vigna opened this issue Mar 27, 2025 · 4 comments
Open

Add example for millisecond since init #355

vigna opened this issue Mar 27, 2025 · 4 comments

Comments

@vigna
Copy link

vigna commented Mar 27, 2025

Log4J has this nice feature that part of the log record is the number of millisecond since the logger initialization. It makes for a very simple timer giving you an idea of how long the process has run. Would it be possible to get it in env_logger?

@epage
Copy link
Contributor

epage commented Mar 27, 2025

I suspect this could be implemented with a custom formatter (env_logger::Builder::format). Would you be willing to experiment with that to see what lessons could be learned in how well this works and generalizes?

@vigna
Copy link
Author

vigna commented Mar 27, 2025

We already have a custom formatter. But to obtain that result we would need to store in a OnceLock or similar the start, and accessing the OnceLock would add further contention.

@vigna
Copy link
Author

vigna commented Mar 28, 2025

Ok, sorry, we just found that we can do an Instant::now() and move the value inside the closure. So it's entirely doable. Maybe it would be interesting as an example.

@vigna vigna closed this as completed Mar 28, 2025
@epage epage reopened this Mar 28, 2025
@epage
Copy link
Contributor

epage commented Mar 28, 2025

Re-opening to track someone writing that example.

@epage epage changed the title Millisecond since init Add example for millisecond since init Mar 28, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants