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

[tracing-subscriber]: add chrono crate implementations of FormatTime #2690

Merged
merged 10 commits into from
Sep 25, 2023

Conversation

shayne-fletcher
Copy link
Contributor

Motivation

Issue #2080 explains that it's not possible to soundly use tracing_subscriber::fmt::time::LocalTime in a multithreaded context. It proposes adding alternative time formatters that use the chrono crate to workaround which is what this PR offers.

Solution

A new source file 'chrono_crate.rs' is added to the 'tracing-subscriber' package implementing mod chrono_crate providing two new tag types LocalTime and Utc with associated time::FormatTime trait implementations that call chrono::Local::now().to_rfc3339() and chrono::Utc::now().to_rfc3339() respectively. Simple unit-tests of the new functionality accompany the additions.

@shayne-fletcher shayne-fletcher requested review from hawkw, davidbarsky and a team as code owners August 18, 2023 19:58
@davidbarsky
Copy link
Member

One note: we've got a few broken doc tests. One failure—which you can see [here](https://app.netlify.com/sites/tracing-rs/deploys/64dfd174e129e00008898be10—is complaining that no module named Chrono is in scope. I think you might need to write [`chrono`], but you should be iron out any issues using cargo doc --no-deps --all-features locally.

Copy link
Member

@davidbarsky davidbarsky left a comment

Choose a reason for hiding this comment

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

I forgot to add this, but it's probably not unreasonable to copy-and-paste the contents of https://docs.rs/tracing-subscriber/0.2.25/src/tracing_subscriber/fmt/time/mod.rs.html#157 back into into here.

tracing-subscriber/src/fmt/time/chrono_crate.rs Outdated Show resolved Hide resolved
tracing-subscriber/src/fmt/time/chrono_crate.rs Outdated Show resolved Hide resolved
tracing-subscriber/src/fmt/time/chrono_crate.rs Outdated Show resolved Hide resolved
tracing-subscriber/src/fmt/time/chrono_crate.rs Outdated Show resolved Hide resolved
@shayne-fletcher
Copy link
Contributor Author

shayne-fletcher commented Aug 21, 2023

test plan:

  • cargo test --features "chrono-time" -p tracing-subscriber chrono_format_time
  • cargo doc --no-deps --all-features

@davidbarsky
Copy link
Member

@shayne-fletcher alright, I think that this PR is in a good spot. Because the blast radius of adding a new dependency might be a large, I'd like to get @hawkw's eyes on this PR before we merge.

Copy link
Member

@hawkw hawkw left a comment

Choose a reason for hiding this comment

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

Overall, this looks pretty close to ready --- the API structure seems good to me. I commented on a few things I think we ought to address first.

Thanks for the PR!

tracing-subscriber/src/fmt/time/chrono_crate.rs Outdated Show resolved Hide resolved
tracing-subscriber/src/fmt/time/chrono_crate.rs Outdated Show resolved Hide resolved
tracing-subscriber/src/fmt/time/chrono_crate.rs Outdated Show resolved Hide resolved
tracing-subscriber/src/fmt/time/chrono_crate.rs Outdated Show resolved Hide resolved
tracing-subscriber/src/fmt/time/chrono_crate.rs Outdated Show resolved Hide resolved
tracing-subscriber/src/fmt/time/mod.rs Outdated Show resolved Hide resolved
tracing-subscriber/Cargo.toml Outdated Show resolved Hide resolved
Copy link
Member

@hawkw hawkw left a comment

Choose a reason for hiding this comment

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

looks good to me, modulo one little nit about docs.

Comment on lines +1 to +11
use crate::fmt::format::Writer;
use crate::fmt::time::FormatTime;

use std::sync::Arc;

/// Formats [local time]s and [UTC time]s with `FormatTime` implementations
/// that use the [`chrono` crate].
///
/// [local time]: [`chrono::offset::Local`]
/// [UTC time]: [`chrono::offset::Utc`]
/// [`chrono` crate]: [`chrono`]
Copy link
Member

Choose a reason for hiding this comment

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

I think this was supposed to be a module-level doc comment?

Suggested change
use crate::fmt::format::Writer;
use crate::fmt::time::FormatTime;
use std::sync::Arc;
/// Formats [local time]s and [UTC time]s with `FormatTime` implementations
/// that use the [`chrono` crate].
///
/// [local time]: [`chrono::offset::Local`]
/// [UTC time]: [`chrono::offset::Utc`]
/// [`chrono` crate]: [`chrono`]
//! Formats [local time]s and [UTC time]s with `FormatTime` implementations
//! that use the [`chrono` crate].
//!
//! [local time]: [`chrono::offset::Local`]
//! [UTC time]: [`chrono::offset::Utc`]
//! [`chrono` crate]: [`chrono`]
use crate::fmt::format::Writer;
use crate::fmt::time::FormatTime;
use std::sync::Arc;

Copy link
Member

Choose a reason for hiding this comment

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

...but, i guess having a module-level doc comment isn't super important since the module is private?

@davidbarsky davidbarsky merged commit 2f8f249 into tokio-rs:master Sep 25, 2023
54 checks passed
davidbarsky added a commit that referenced this pull request Sep 26, 2023
…2690)

Issue #2080 explains that it's not
possible to soundly use
[`tracing_subscriber::fmt::time::LocalTime`](https://docs.rs/tracing-subscriber/latest/tracing_subscriber/fmt/time/struct.LocalTime.html)
in a multithreaded context. It proposes adding alternative time formatters that
use the [chrono crate](https://docs.rs/chrono/latest/chrono/) to workaround
which is what this PR offers.

A new source file 'chrono_crate.rs' is added to the 'tracing-subscriber'
package implementing `mod chrono_crate` providing two new tag types `LocalTime`
and `Utc` with associated `time::FormatTime` trait implementations that call
`chrono::Local::now().to_rfc3339()` and `chrono::Utc::now().to_rfc3339()`
respectively. Simple unit-tests of the new functionality accompany the
additions.
---------

Co-authored-by: David Barsky <[email protected]>
Co-authored-by: Shayne Fletcher <[email protected]>
davidbarsky added a commit that referenced this pull request Sep 27, 2023
…2690)

Issue #2080 explains that it's not
possible to soundly use
[`tracing_subscriber::fmt::time::LocalTime`](https://docs.rs/tracing-subscriber/latest/tracing_subscriber/fmt/time/struct.LocalTime.html)
in a multithreaded context. It proposes adding alternative time formatters that
use the [chrono crate](https://docs.rs/chrono/latest/chrono/) to workaround
which is what this PR offers.

A new source file 'chrono_crate.rs' is added to the 'tracing-subscriber'
package implementing `mod chrono_crate` providing two new tag types `LocalTime`
and `Utc` with associated `time::FormatTime` trait implementations that call
`chrono::Local::now().to_rfc3339()` and `chrono::Utc::now().to_rfc3339()`
respectively. Simple unit-tests of the new functionality accompany the
additions.
---------

Co-authored-by: David Barsky <[email protected]>
Co-authored-by: Shayne Fletcher <[email protected]>
davidbarsky added a commit that referenced this pull request Sep 27, 2023
…2690)

Issue #2080 explains that it's not
possible to soundly use
[`tracing_subscriber::fmt::time::LocalTime`](https://docs.rs/tracing-subscriber/latest/tracing_subscriber/fmt/time/struct.LocalTime.html)
in a multithreaded context. It proposes adding alternative time formatters that
use the [chrono crate](https://docs.rs/chrono/latest/chrono/) to workaround
which is what this PR offers.

A new source file 'chrono_crate.rs' is added to the 'tracing-subscriber'
package implementing `mod chrono_crate` providing two new tag types `LocalTime`
and `Utc` with associated `time::FormatTime` trait implementations that call
`chrono::Local::now().to_rfc3339()` and `chrono::Utc::now().to_rfc3339()`
respectively. Simple unit-tests of the new functionality accompany the
additions.
---------

Co-authored-by: David Barsky <[email protected]>
Co-authored-by: Shayne Fletcher <[email protected]>
davidbarsky added a commit that referenced this pull request Sep 27, 2023
…2690)

Issue #2080 explains that it's not
possible to soundly use
[`tracing_subscriber::fmt::time::LocalTime`](https://docs.rs/tracing-subscriber/latest/tracing_subscriber/fmt/time/struct.LocalTime.html)
in a multithreaded context. It proposes adding alternative time formatters that
use the [chrono crate](https://docs.rs/chrono/latest/chrono/) to workaround
which is what this PR offers.

A new source file 'chrono_crate.rs' is added to the 'tracing-subscriber'
package implementing `mod chrono_crate` providing two new tag types `LocalTime`
and `Utc` with associated `time::FormatTime` trait implementations that call
`chrono::Local::now().to_rfc3339()` and `chrono::Utc::now().to_rfc3339()`
respectively. Simple unit-tests of the new functionality accompany the
additions.
---------

Co-authored-by: David Barsky <[email protected]>
Co-authored-by: Shayne Fletcher <[email protected]>
davidbarsky added a commit that referenced this pull request Sep 27, 2023
…2690)

Issue #2080 explains that it's not
possible to soundly use
[`tracing_subscriber::fmt::time::LocalTime`](https://docs.rs/tracing-subscriber/latest/tracing_subscriber/fmt/time/struct.LocalTime.html)
in a multithreaded context. It proposes adding alternative time formatters that
use the [chrono crate](https://docs.rs/chrono/latest/chrono/) to workaround
which is what this PR offers.

A new source file 'chrono_crate.rs' is added to the 'tracing-subscriber'
package implementing `mod chrono_crate` providing two new tag types `LocalTime`
and `Utc` with associated `time::FormatTime` trait implementations that call
`chrono::Local::now().to_rfc3339()` and `chrono::Utc::now().to_rfc3339()`
respectively. Simple unit-tests of the new functionality accompany the
additions.
---------

Co-authored-by: David Barsky <[email protected]>
Co-authored-by: Shayne Fletcher <[email protected]>
davidbarsky added a commit that referenced this pull request Sep 27, 2023
…2690)

Issue #2080 explains that it's not
possible to soundly use
[`tracing_subscriber::fmt::time::LocalTime`](https://docs.rs/tracing-subscriber/latest/tracing_subscriber/fmt/time/struct.LocalTime.html)
in a multithreaded context. It proposes adding alternative time formatters that
use the [chrono crate](https://docs.rs/chrono/latest/chrono/) to workaround
which is what this PR offers.

A new source file 'chrono_crate.rs' is added to the 'tracing-subscriber'
package implementing `mod chrono_crate` providing two new tag types `LocalTime`
and `Utc` with associated `time::FormatTime` trait implementations that call
`chrono::Local::now().to_rfc3339()` and `chrono::Utc::now().to_rfc3339()`
respectively. Simple unit-tests of the new functionality accompany the
additions.
---------

Co-authored-by: David Barsky <[email protected]>
Co-authored-by: Shayne Fletcher <[email protected]>
davidbarsky added a commit that referenced this pull request Sep 27, 2023
…2690)

Issue #2080 explains that it's not
possible to soundly use
[`tracing_subscriber::fmt::time::LocalTime`](https://docs.rs/tracing-subscriber/latest/tracing_subscriber/fmt/time/struct.LocalTime.html)
in a multithreaded context. It proposes adding alternative time formatters that
use the [chrono crate](https://docs.rs/chrono/latest/chrono/) to workaround
which is what this PR offers.

A new source file 'chrono_crate.rs' is added to the 'tracing-subscriber'
package implementing `mod chrono_crate` providing two new tag types `LocalTime`
and `Utc` with associated `time::FormatTime` trait implementations that call
`chrono::Local::now().to_rfc3339()` and `chrono::Utc::now().to_rfc3339()`
respectively. Simple unit-tests of the new functionality accompany the
additions.
---------

Co-authored-by: David Barsky <[email protected]>
Co-authored-by: Shayne Fletcher <[email protected]>
davidbarsky added a commit that referenced this pull request Sep 29, 2023
…2690)

Issue #2080 explains that it's not
possible to soundly use
[`tracing_subscriber::fmt::time::LocalTime`](https://docs.rs/tracing-subscriber/latest/tracing_subscriber/fmt/time/struct.LocalTime.html)
in a multithreaded context. It proposes adding alternative time formatters that
use the [chrono crate](https://docs.rs/chrono/latest/chrono/) to workaround
which is what this PR offers.

A new source file 'chrono_crate.rs' is added to the 'tracing-subscriber'
package implementing `mod chrono_crate` providing two new tag types `LocalTime`
and `Utc` with associated `time::FormatTime` trait implementations that call
`chrono::Local::now().to_rfc3339()` and `chrono::Utc::now().to_rfc3339()`
respectively. Simple unit-tests of the new functionality accompany the
additions.
---------

Co-authored-by: David Barsky <[email protected]>
Co-authored-by: Shayne Fletcher <[email protected]>
hawkw pushed a commit that referenced this pull request Oct 1, 2023
…2690)

Issue #2080 explains that it's not
possible to soundly use
[`tracing_subscriber::fmt::time::LocalTime`](https://docs.rs/tracing-subscriber/latest/tracing_subscriber/fmt/time/struct.LocalTime.html)
in a multithreaded context. It proposes adding alternative time formatters that
use the [chrono crate](https://docs.rs/chrono/latest/chrono/) to workaround
which is what this PR offers.

A new source file 'chrono_crate.rs' is added to the 'tracing-subscriber'
package implementing `mod chrono_crate` providing two new tag types `LocalTime`
and `Utc` with associated `time::FormatTime` trait implementations that call
`chrono::Local::now().to_rfc3339()` and `chrono::Utc::now().to_rfc3339()`
respectively. Simple unit-tests of the new functionality accompany the
additions.
---------

Co-authored-by: David Barsky <[email protected]>
Co-authored-by: Shayne Fletcher <[email protected]>
hawkw pushed a commit that referenced this pull request Nov 13, 2023
# 0.3.18 (November 13, 2023)

This release of `tracing-subscriber` adds support for the [`NO_COLOR`] environment
variable (an informal standard to disable emitting ANSI color escape codes) in
`fmt::Layer`, reintroduces support for the [`chrono`] crate, and increases the
minimum supported Rust version (MSRV) to Rust 1.63.0.

It also introduces several minor API improvements.

### Added

- **chrono**: Add [`chrono`] implementations of `FormatTime` ([#2690])
- **subscriber**: Add support for the [`NO_COLOR`] environment variable in
`fmt::Layer` ([#2647])
- **fmt**: make `format::Writer::new()` public ([#2680])
- **filter**: Implement `layer::Filter` for `Option<Filter>` ([#2407])

### Changed

- **log**: bump version of `tracing-log` to 0.2 ([#2772])
- Increased minimum supported Rust version (MSRV) to 1.63.0+.

[`chrono`]: https://github.com/chronotope/chrono
[`NO_COLOR`]: https://no-color.org/
[#2690]: #2690
[#2647]: #2647
[#2680]: #2680
[#2407]: #2407
[#2772]: #2772

Thanks to @shayne-fletcher, @dmlary, @kaifastromai, and @jsgf for contributing!
azzamsa added a commit to azzamsa/tin that referenced this pull request Nov 28, 2023
azzamsa added a commit to azzamsa/learn that referenced this pull request Nov 28, 2023
kaffarell pushed a commit to kaffarell/tracing that referenced this pull request Feb 14, 2024
# 0.3.18 (November 13, 2023)

This release of `tracing-subscriber` adds support for the [`NO_COLOR`] environment
variable (an informal standard to disable emitting ANSI color escape codes) in
`fmt::Layer`, reintroduces support for the [`chrono`] crate, and increases the
minimum supported Rust version (MSRV) to Rust 1.63.0.

It also introduces several minor API improvements.

### Added

- **chrono**: Add [`chrono`] implementations of `FormatTime` ([tokio-rs#2690])
- **subscriber**: Add support for the [`NO_COLOR`] environment variable in
`fmt::Layer` ([tokio-rs#2647])
- **fmt**: make `format::Writer::new()` public ([tokio-rs#2680])
- **filter**: Implement `layer::Filter` for `Option<Filter>` ([tokio-rs#2407])

### Changed

- **log**: bump version of `tracing-log` to 0.2 ([tokio-rs#2772])
- Increased minimum supported Rust version (MSRV) to 1.63.0+.

[`chrono`]: https://github.com/chronotope/chrono
[`NO_COLOR`]: https://no-color.org/
[tokio-rs#2690]: tokio-rs#2690
[tokio-rs#2647]: tokio-rs#2647
[tokio-rs#2680]: tokio-rs#2680
[tokio-rs#2407]: tokio-rs#2407
[tokio-rs#2772]: tokio-rs#2772

Thanks to @shayne-fletcher, @dmlary, @kaifastromai, and @jsgf for contributing!
kaffarell pushed a commit to kaffarell/tracing that referenced this pull request May 22, 2024
…okio-rs#2690)

Issue tokio-rs#2080 explains that it's not
possible to soundly use
[`tracing_subscriber::fmt::time::LocalTime`](https://docs.rs/tracing-subscriber/latest/tracing_subscriber/fmt/time/struct.LocalTime.html)
in a multithreaded context. It proposes adding alternative time formatters that
use the [chrono crate](https://docs.rs/chrono/latest/chrono/) to workaround
which is what this PR offers.

A new source file 'chrono_crate.rs' is added to the 'tracing-subscriber'
package implementing `mod chrono_crate` providing two new tag types `LocalTime`
and `Utc` with associated `time::FormatTime` trait implementations that call
`chrono::Local::now().to_rfc3339()` and `chrono::Utc::now().to_rfc3339()`
respectively. Simple unit-tests of the new functionality accompany the
additions.
---------

Co-authored-by: David Barsky <[email protected]>
Co-authored-by: Shayne Fletcher <[email protected]>
kaffarell pushed a commit to kaffarell/tracing that referenced this pull request May 22, 2024
# 0.3.18 (November 13, 2023)

This release of `tracing-subscriber` adds support for the [`NO_COLOR`] environment
variable (an informal standard to disable emitting ANSI color escape codes) in
`fmt::Layer`, reintroduces support for the [`chrono`] crate, and increases the
minimum supported Rust version (MSRV) to Rust 1.63.0.

It also introduces several minor API improvements.

### Added

- **chrono**: Add [`chrono`] implementations of `FormatTime` ([tokio-rs#2690])
- **subscriber**: Add support for the [`NO_COLOR`] environment variable in
`fmt::Layer` ([tokio-rs#2647])
- **fmt**: make `format::Writer::new()` public ([tokio-rs#2680])
- **filter**: Implement `layer::Filter` for `Option<Filter>` ([tokio-rs#2407])

### Changed

- **log**: bump version of `tracing-log` to 0.2 ([tokio-rs#2772])
- Increased minimum supported Rust version (MSRV) to 1.63.0+.

[`chrono`]: https://github.com/chronotope/chrono
[`NO_COLOR`]: https://no-color.org/
[tokio-rs#2690]: tokio-rs#2690
[tokio-rs#2647]: tokio-rs#2647
[tokio-rs#2680]: tokio-rs#2680
[tokio-rs#2407]: tokio-rs#2407
[tokio-rs#2772]: tokio-rs#2772

Thanks to @shayne-fletcher, @dmlary, @kaifastromai, and @jsgf for contributing!
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.

3 participants