-
Notifications
You must be signed in to change notification settings - Fork 24
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
Add optional support for tracing
besides log
#37
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -30,6 +30,7 @@ codecov = { repository = "rust-cli/clap-verbosity-flag" } | |
[dependencies] | ||
log = "0.4.1" | ||
clap = { version = "3.0", default-features = false, features = ["std", "derive"] } | ||
tracing = { version = "0.1", default-features = false, optional = true } | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. How mature / stable is tracing for being a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
I'm only a very new user of There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
My concern is not with it disappearing but that when a tracing 0.2 comes out, to support it, we'd have to release clap-verbosity-flag 2.0. Ditto for each breaking release of tracing, regardless of whether the type looks the same. Rust will consider |
||
|
||
[dev-dependencies] | ||
env_logger = "0.9.0" |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -92,14 +92,22 @@ impl<L: LogLevel> Verbosity<L> { | |
} | ||
} | ||
|
||
/// Get the log level. | ||
/// Get the log level, as defined by the `log` crate. | ||
/// | ||
/// `None` means all output is disabled. | ||
pub fn log_level(&self) -> Option<log::Level> { | ||
level_enum(self.verbosity()) | ||
} | ||
|
||
/// Get the log level filter. | ||
/// Get the log level, as defined by the `tracing` crate. | ||
/// | ||
/// `None` means all output is disabled. | ||
#[cfg(feature = "tracing")] | ||
pub fn tracing_level(&self) -> Option<tracing::Level> { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For tracing, is it more appropriate to return There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. To be clear, I'm not saying "also" but "instead of" There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. They're very easily convertible to each other, and the equivalent of |
||
self.log_level().map(tracing_level_from_log_level) | ||
} | ||
|
||
/// Get the log level filter, as defined by the `log` crate. | ||
pub fn log_level_filter(&self) -> log::LevelFilter { | ||
level_enum(self.verbosity()) | ||
.map(|l| l.to_level_filter()) | ||
|
@@ -138,6 +146,17 @@ fn level_enum(verbosity: i8) -> Option<log::Level> { | |
} | ||
} | ||
|
||
#[cfg(feature = "tracing")] | ||
fn tracing_level_from_log_level(level: log::Level) -> tracing::Level { | ||
match level { | ||
log::Level::Error => tracing::Level::ERROR, | ||
log::Level::Warn => tracing::Level::WARN, | ||
log::Level::Info => tracing::Level::INFO, | ||
log::Level::Debug => tracing::Level::DEBUG, | ||
log::Level::Trace => tracing::Level::TRACE, | ||
} | ||
} | ||
|
||
use std::fmt; | ||
|
||
impl<L: LogLevel> fmt::Display for Verbosity<L> { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How do tracing users generally feel about still requiring
log
? If a breaking change is involved in the future, should we allow disabling it?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm only a very new user of
tracing
, so I don't know, but I note that the maintracing
README suggests that applications use the cratetracing_subscriber
, which already, as a default feature, depends onlog
and consumeslog
messages, and the maintracing
crate also interfaces withlog
as a non-default feature.I'm sure some users would consider the cost in compilation time of
log
to be too much, but would they be usingclap-derive
?