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

Documentation examples of tracing_subscriber::reload do not work as described #3085

Open
bluenote10 opened this issue Sep 22, 2024 · 1 comment

Comments

@bluenote10
Copy link

bluenote10 commented Sep 22, 2024

Bug Report

I'm not sure if this is an actual (software) bug, or just a case of an outdated documentation: The examples given in the documentation of tracing_subscriber::reload do not seem to work as described there.

Version

│   │       │   │   └── tracing v0.1.40
│   │       │   │       ├── tracing-attributes v0.1.27 (proc-macro)
│   │       │   │       └── tracing-core v0.1.32
│   │       ├── tracing v0.1.40 (*)
│   ├── tracing v0.1.40 (*)
│   ├── tracing-subscriber v0.3.18
│   │   ├── tracing v0.1.40 (*)
│   │   ├── tracing-core v0.1.32 (*)
│   │   └── tracing-log v0.2.0
│   │       └── tracing-core v0.1.32 (*)
└── tracing-subscriber v0.3.18 (*)

The log crate is 0.4.22.

Platform

Linux fabuntu 5.15.0-122-generic #132-Ubuntu SMP Thu Aug 29 13:45:52 UTC 2024 x86_64 x86_64 x86_64 GNU/Linux

Crates

tracing_subscriber

Description

I've copy/pasted the two examples given in the documentation into this standalone module, extended by a bit more debug output:

use log::{info, warn};
use tracing_subscriber::{filter, fmt, prelude::*, reload};

fn example_1() {
    let filter = filter::LevelFilter::WARN;
    let (filter, reload_handle) = reload::Layer::new(filter);
    tracing_subscriber::registry()
        .with(filter)
        .with(fmt::Layer::default())
        .init();
    info!("This will be ignored");
    reload_handle
        .modify(|filter| *filter = filter::LevelFilter::INFO)
        .unwrap();
    warn!("Test line before");
    info!("This will be logged");
    warn!("Test line after");
}

fn example_2() {
    let filtered_layer = fmt::Layer::default().with_filter(filter::LevelFilter::WARN);
    let (filtered_layer, reload_handle) = reload::Layer::new(filtered_layer);
    tracing_subscriber::registry().with(filtered_layer).init();
    info!("This will be ignored");
    reload_handle
        .modify(|layer| *layer.filter_mut() = filter::LevelFilter::INFO)
        .unwrap();
    warn!("Test line before");
    info!("This will be logged");
    warn!("Test line after");
}

fn main() {
    example_1();
}

Running either example_1() or example_2() both result in the output:

2024-09-22T08:02:05.237190Z  WARN debug_logging: Test line before
2024-09-22T08:02:05.237210Z  WARN debug_logging: Test line after

I.e., both examples don't actually log the line info!("This will be logged"); as they suggest to do.

Possibly related to:

@kaffarell
Copy link
Contributor

kaffarell commented Oct 29, 2024

yes, this looks like a duplicate of #2711, which has already been fixed on master with #1270, but hasn't been backported for some reason. Note that it works with the tracing::info!, tracing::warn! macros.

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

No branches or pull requests

2 participants