Skip to content

Commit

Permalink
fix(utils/tracing): use correct formatting on Windows
Browse files Browse the repository at this point in the history
  • Loading branch information
M0dEx committed Apr 1, 2024
1 parent 1ee2d79 commit af915c3
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 7 deletions.
14 changes: 12 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 6 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "quincy"
version = "0.9.1"
version = "0.9.2"
authors = ["Jakub Kubík <[email protected]>"]
license = "MIT"
description = "QUIC-based VPN"
Expand Down Expand Up @@ -84,6 +84,11 @@ once_cell = "^1.17"
[target.'cfg(not(target_env = "msvc"))'.dependencies]
jemallocator = "0.5"

# Windows formatting
[target.'cfg(windows)'.dependencies]
tracing-subscriber = { version = "^0.3.17", features = ["env-filter", "ansi"] }
nu-ansi-term = "^0.50.0"

[dev-dependencies]
rstest = "^0.18.0"
tracing-test = { version = "^0.2.4", features = ["no-env-filter"] }
16 changes: 12 additions & 4 deletions src/utils/tracing.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,23 @@
use tracing::Subscriber;
use tracing_subscriber::layer::SubscriberExt;
use tracing_subscriber::fmt::SubscriberBuilder;
use tracing_subscriber::EnvFilter;

/// Returns a new `tracing` subscriber with the specified log level.
///
/// ### Arguments
/// - `log_level` - the log level to use
pub fn log_subscriber(log_level: &str) -> impl Subscriber {
let registry = tracing_subscriber::Registry::default();
let fmt_layer = tracing_subscriber::fmt::Layer::new();
// Enable ANSI color support on Windows.
#[cfg(windows)]
let with_ansi = nu_ansi_term::enable_ansi_support().is_ok();

#[cfg(not(windows))]
let with_ansi = false;

Check warning on line 16 in src/utils/tracing.rs

View check run for this annotation

Codecov / codecov/patch

src/utils/tracing.rs#L10-L16

Added lines #L10 - L16 were not covered by tests
let filter_layer = EnvFilter::try_new(log_level).unwrap();

registry.with(filter_layer).with(fmt_layer)
SubscriberBuilder::default()
.with_env_filter(filter_layer)
.with_ansi(with_ansi)
.finish()

Check warning on line 22 in src/utils/tracing.rs

View check run for this annotation

Codecov / codecov/patch

src/utils/tracing.rs#L19-L22

Added lines #L19 - L22 were not covered by tests
}

0 comments on commit af915c3

Please sign in to comment.