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

Add an option to control whether timestamps are to be printed or not. #34

Merged
merged 1 commit into from
Jul 29, 2021

Conversation

berke
Copy link
Contributor

@berke berke commented Apr 28, 2021

Timestamps are useful when debugging, but when the program is executed from systemd, journald automatically adds timestamps to the lines, so one gets duplicate timestamps.

This adds an option to turn timestamps off without having to recompile with a different feature set.

println!(
"{} {:<5} [{}] {}",
Local::now().format("%Y-%m-%d %H:%M:%S,%3f"),
level_string,
target,
record.args()
);
return;
Copy link
Contributor

Choose a reason for hiding this comment

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

out of curiosity: why the return; instead of an else?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

To avoid duplicating the code for the two cases where there is no timestamp.

Copy link
Contributor

Choose a reason for hiding this comment

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

Oh yes, forget the #[cfg(feature = "chrono")] just above.

@@ -37,6 +41,7 @@ impl SimpleLogger {
SimpleLogger {
default_level: LevelFilter::Trace,
module_levels: Vec::new(),
timestamps: true
Copy link
Contributor

Choose a reason for hiding this comment

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

indent problem?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sorry about that, I guess I have to figure out how to convince the Rust mode to use spaces instead of tabs.

Copy link
Contributor

Choose a reason for hiding this comment

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

Does cargo fmt works for you?

@borntyping borntyping merged commit 3feeac3 into borntyping:master Jul 29, 2021
@borntyping
Copy link
Owner

Released in 1.12.0 with some changes (and a copy of this feature for colours, too). Thanks for your patience!

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.

None yet

3 participants