From 9f3542977a4a7d7f526536fc7ca3b4fee82ae45c Mon Sep 17 00:00:00 2001 From: Tobias Bieniek Date: Fri, 29 Mar 2024 14:51:03 +0100 Subject: [PATCH] Revert "tests: Use `tracing::subscriber::DefaultGuard` to set subscriber (#8023)" This reverts commit aa0f7844be82350a43f593e547ff33cab6abc34a. --- src/tests/dump_db.rs | 2 +- src/tests/util/test_app.rs | 9 +-------- src/util/tracing.rs | 9 +++------ 3 files changed, 5 insertions(+), 15 deletions(-) diff --git a/src/tests/dump_db.rs b/src/tests/dump_db.rs index 8e07bab664f..753d8c9a968 100644 --- a/src/tests/dump_db.rs +++ b/src/tests/dump_db.rs @@ -3,7 +3,7 @@ use crates_io_test_db::TestDatabase; #[test] fn dump_db_and_reimport_dump() { - let _guard = crates_io::util::tracing::init_for_test(); + crates_io::util::tracing::init_for_test(); let db_one = TestDatabase::new(); diff --git a/src/tests/util/test_app.rs b/src/tests/util/test_app.rs index cce2e0d62cf..e2ef5d2e996 100644 --- a/src/tests/util/test_app.rs +++ b/src/tests/util/test_app.rs @@ -23,12 +23,8 @@ use oauth2::{ClientId, ClientSecret}; use std::collections::HashSet; use std::{rc::Rc, sync::Arc, time::Duration}; use tokio::runtime::Runtime; -use tracing::subscriber::DefaultGuard; struct TestAppInner { - #[allow(dead_code)] - tracing_guard: DefaultGuard, - pub runtime: Runtime, app: Arc, @@ -81,10 +77,9 @@ pub struct TestApp(Rc); impl TestApp { /// Initialize an application with an `Uploader` that panics pub fn init() -> TestAppBuilder { - let tracing_guard = crates_io::util::tracing::init_for_test(); + crates_io::util::tracing::init_for_test(); TestAppBuilder { - tracing_guard, config: simple_config(), index: None, build_job_runner: false, @@ -210,7 +205,6 @@ impl TestApp { } pub struct TestAppBuilder { - tracing_guard: DefaultGuard, config: config::Server, index: Option, build_job_runner: bool, @@ -297,7 +291,6 @@ impl TestAppBuilder { }; let test_app_inner = TestAppInner { - tracing_guard: self.tracing_guard, runtime, app, test_database, diff --git a/src/util/tracing.rs b/src/util/tracing.rs index f808fe1bc7e..e125882feac 100644 --- a/src/util/tracing.rs +++ b/src/util/tracing.rs @@ -1,5 +1,4 @@ use sentry::integrations::tracing::EventFilter; -use tracing::subscriber::DefaultGuard; use tracing::Level; use tracing::Metadata; use tracing_subscriber::filter::LevelFilter; @@ -47,17 +46,15 @@ pub fn event_filter(metadata: &Metadata<'_>) -> EventFilter { } /// Initializes the `tracing` logging framework for usage in tests. -pub fn init_for_test() -> DefaultGuard { +pub fn init_for_test() { let env_filter = EnvFilter::builder() .with_default_directive(LevelFilter::INFO.into()) .from_env_lossy(); - let subscriber = tracing_subscriber::fmt() + let _ = tracing_subscriber::fmt() .compact() .with_env_filter(env_filter) .without_time() .with_test_writer() - .finish(); - - tracing::subscriber::set_default(subscriber) + .try_init(); }