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

subscriber: don't bail when timestamp formatting fails #1689

Merged
merged 1 commit into from
Oct 26, 2021

Commits on Oct 26, 2021

  1. subscriber: don't bail when timestamp formatting fails

    ## Motivation
    
    Currently, `tracing_subscriber::fmt` will bail out of formatting the log
    line when formatting the timestamp fails. Previously, when timestamps
    were formatted using the `chrono` crate, this was the correct behavior,
    as getting the timestamp was infallible, and an error would only be
    returned if *formatting* the timestamp to the buffer fails. This should
    never actually happen, because we are writing the timestamp to a string,
    which should never fail; using `?` is just a bit more efficient than
    `.expect` because it doesn't require generating unwinding code.
    
    However, this is no longer the case when using the `time` crate. In the
    `time` API, actually getting a timestamp is fallible, and in some cases,
    will fail. The current code will bail out of formatting the entire log
    line if getting the timestamp fails, which is not great --- using the
    wrong timestamp formatter will result in silently dropping all log
    lines.
    
    ## Solution
    
    This branch changes the `format_timestamp` method to print `<unknown
    time>` when the timestamp formatting fails, rather than bailing. This
    way, we at least print the rest of the log line for the event.
    
    This fixes half of the issue described in #1688 (the other half is
    improving documentation).
    hawkw committed Oct 26, 2021
    Configuration menu
    Copy the full SHA
    a90310e View commit details
    Browse the repository at this point in the history