-
Notifications
You must be signed in to change notification settings - Fork 25
Description
I'd like to re-suggest adding tracing support. My current workaround whenever I write a cli is to add clap-verbosity-flag, tracing-log, and add a method which calls level_filter().as_trace() to the parser. This seems like code which should just be part of the verbosity flag and feature flagged in.
Previously:
- make tracing supported as first-class citizen #87 was closed suggested opening an issue.
- Add tracing support parity with log #44 was closed suggesting opening an issue.
- suggests feature flags
- Add optional support for
tracing
besideslog
#37 was closed as another PR had a demo of manually working around the problem
Questions previously raised (paraphrased):
- How mature is tracing?
Tracing 0.1 has the same order of magnitude daily / all time downloads as log / clap (200M vs 340M / 300M). While this is not a perfect indication of stability / maturity, it implies that making a breaking change would have large impact on a large portion of the rust ecosystem. Development of tracing happens on its master branch which tracks a long running yet to be released 0.2.x, with changes that are backwards compatible are backported to 0.1.x. The core LevelFilter and Level types are unchanged between the versions. Also, the tracing-core crate (where level and levelfilter ultimately live) contains the following in its readme:Application authors will typically not use this crate directly. Instead, they will use the tracing crate, which provides a much more fully-featured API. However, this crate’s API will change very infrequently, so it may be used when dependencies must be very stable.
- How should this support tracing 0.1, 0.2, .... Does doing so require this library to go to 2.0 to support the next version etc.
It's fairly common for libs that want to support multiple versions of libs to have versioned feature flags. E.g. here that would be tracing / tracing-0.1 / tracing-0.2 etc. The same question applies to log though. What happens when log 0.5 comes out? I'd recommend adding a tracing feature, and having that be mean the latest version of tracing, while adding a tracing-0.1 feature when tracing-0.2 comes out. You could pre-create a -01 feature and only use that. @epage you likely have much more insight into the right choice here than most people. Perhaps pick an approach that makes sense, or accept one that is good enough? - How do tracing users generally feel about still requiring log? If a breaking change is involved in the future, should we allow disabling it?
IMO, it should be in a feature flag enabled by default for backwards compatibility - For tracing, is it more appropriate to return Level or LevelFilter?
LevelFilter
isstruct LevelFilter(Option<Level>)
, andLevelFilter::OFF
isLevelFilter(None)
. It makes some sense to have both as there are two possible use cases for these settings - directly using the value to filter logs, or using the Level to perform further config from other sources (e.g. environment vars, config files, etc). The former is simplest with LevelFilter, the latter is simplest with Option. Having just one loses symmetry with the existing log crate Level/LevelFilter values. I'd recommend keeping both.
So:
- add a
tracing
feature flag - add a
log
feature flag - make
log
default - add
fn tracing_level() -> Option<tracing_core::metadata::Level>
- add
fn tracing_level_filter() -> tracing_core::metadata::LevelFilter()
- update CI to test these and examples to test both.
I'm going to open another PR that aligns with the recommendations above as the code to do this is much more concise / less ambiguous than the narrative above.