Skip to content

Bad output message when using with_timer() API #1848

@jaudiger

Description

@jaudiger

Bug Report

Version

├── tracing v0.1.29 (*)
├── tracing-subscriber v0.3.6
│   ├── tracing-core v0.1.21 (*)
│   ├── tracing-log v0.1.2
│   │   └── tracing-core v0.1.21 (*)
│   └── tracing-serde v0.1.2
│       └── tracing-core v0.1.21 (*)
│   └── tracing v0.1.29 (*)

Platform

Linux 0533f12981cc 5.15.15-200.fc35.x86_64 #1 SMP Sun Jan 16 17:37:06 UTC 2022 x86_64 x86_64 x86_64 GNU/Linux

Crates

tracing-subscriber

Description

I tried to create a configurable subscriber based on configuration input, but I encountered an issue that block me.

I tried this code:

let timer = UtcTime::new(format_description!(
    "[year]-[month]-[day] [hour]:[minute]:[second].[subsecond digits:3]"
));

let mut subscriber_builder = tracing_subscriber::fmt()
    .with_max_level(Level::INFO);

   // For demonstration purpose
    if true {
        subscriber_builder = subscriber_builder.with_timer(timer);
    }

tracing::subscriber::set_global_default( subscriber_builder.finish())
    .with_context(|| "Failed to initialize the logging library")?;

I expected to build the code as it's possible with the following code:

let subscriber = tracing_subscriber::fmt()
    .with_max_level(Level::INFO)
    .with_timer(timer)
    .finish();

tracing::subscriber::set_global_default(subscriber)
    .with_context(|| "Failed to initialize the logging library")?;

Instead, this happened:

error[E0308]: mismatched types
  --> src/application/tracing/tracing.rs:86:76
   |
86 |                         subscriber_builder = subscriber_builder.with_timer(timer);
   |                                                                            ^^^^^ expected struct `tracing_subscriber::fmt::time::SystemTime`, found struct `UtcTime`
   |
   = note: expected struct `tracing_subscriber::fmt::time::SystemTime`
              found struct `UtcTime<&[FormatItem<'_>]>`

For more information about this error, try `rustc --explain E0308`.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions