mirror of
https://github.com/servo/servo.git
synced 2025-08-07 22:45:34 +01:00
Add cli option for tracing-filter (#35370)
Using environment variables is not really an option on ohos/android, so add a CLI option to configure tracing. Making it a `pref`, so that we can persist the filter might also be desirable. Signed-off-by: Jonathan Schwender <schwenderjonathan@gmail.com>
This commit is contained in:
parent
39c1e5d5d6
commit
654df4c8b7
5 changed files with 44 additions and 8 deletions
|
@ -44,7 +44,13 @@ pub fn init_crypto() {
|
|||
.expect("Error initializing crypto provider");
|
||||
}
|
||||
|
||||
pub fn init_tracing() {
|
||||
pub fn init_tracing(filter_directives: Option<&str>) {
|
||||
#[cfg(not(feature = "tracing"))]
|
||||
{
|
||||
if filter_directives.is_some() {
|
||||
log::debug!("The tracing feature was not selected - ignoring trace filter directives");
|
||||
}
|
||||
}
|
||||
#[cfg(feature = "tracing")]
|
||||
{
|
||||
use tracing_subscriber::layer::SubscriberExt;
|
||||
|
@ -69,10 +75,16 @@ pub fn init_tracing() {
|
|||
|
||||
// Filter events and spans by the directives in SERVO_TRACING, using EnvFilter as a global filter.
|
||||
// <https://docs.rs/tracing-subscriber/0.3.18/tracing_subscriber/layer/index.html#global-filtering>
|
||||
let filter = tracing_subscriber::EnvFilter::builder()
|
||||
.with_default_directive(tracing::level_filters::LevelFilter::OFF.into())
|
||||
.with_env_var("SERVO_TRACING")
|
||||
.from_env_lossy();
|
||||
let filter_builder = tracing_subscriber::EnvFilter::builder()
|
||||
.with_default_directive(tracing::level_filters::LevelFilter::OFF.into());
|
||||
let filter = if let Some(filters) = &filter_directives {
|
||||
filter_builder.parse_lossy(filters)
|
||||
} else {
|
||||
filter_builder
|
||||
.with_env_var("SERVO_TRACING")
|
||||
.from_env_lossy()
|
||||
};
|
||||
|
||||
let subscriber = subscriber.with(filter);
|
||||
|
||||
// Same as SubscriberInitExt::init, but avoids initialising the tracing-log compat layer,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue