[OH] allow setting log_filter via prefs.json (#36916)

This PR allows us to set the `log_filter` via `prefs.json` as well as
commandline arguments.

Priority goes commandline > prefs.json > compile-time default.

Testing: I compiled and run servo on an OH device, and then checked the
logs:

```
hdc hilog | tee log | rg 'Set log_filter to'
```

```
05-08 15:25:59.389 55824 55993 D A00000/org.servo.servo/servoshell::prefs: Set log_filter to: Some("debug,geometry=trace")
```

Signed-off-by: Astraea Quinn Skoutelli <astraea.quinn.skoutelli@huawei.com>
This commit is contained in:
Astraea Quinn S 2025-05-08 18:10:30 +02:00 committed by GitHub
parent f58b0c6ad4
commit 8473946d11
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 8 additions and 1 deletions

View file

@ -236,6 +236,8 @@ pub struct Preferences {
/// The user-agent to use for Servo. This can also be set via [`UserAgentPlatform`] in
/// order to set the value to the default value for the given platform.
pub user_agent: String,
pub log_filter: String,
}
impl Preferences {
@ -398,6 +400,7 @@ impl Preferences {
threadpools_webrender_workers_max: 4,
webgl_testing_context_creation_error: false,
user_agent: String::new(),
log_filter: String::new(),
}
}
}

View file

@ -428,7 +428,11 @@ pub(crate) fn parse_command_line_arguments(args: Vec<String>) -> ArgumentParsing
#[cfg(target_env = "ohos")]
let log_filter = {
let filters = opt_match.opt_strs("log-filter").join(",");
(!filters.is_empty()).then_some(filters)
let log_filter = (!filters.is_empty()).then_some(filters).or_else(|| {
(!preferences.log_filter.is_empty()).then_some(preferences.log_filter.clone())
});
log::debug!("Set log_filter to: {:?}", log_filter);
log_filter
};
let mut debug_options = DebugOptions::default();