OHOS: Use new file logger. (#37690)

Hilog 0.2.1 allows us to additionally log to a file. This is sometimes
more convinient when
benchmarking.
Also added the new log domain of `script::dom::console`.

Testing: Tested on device.

Signed-off-by: Narfinger <Narfinger@users.noreply.github.com>
This commit is contained in:
Narfinger 2025-06-26 11:57:41 +02:00 committed by GitHub
parent 25a5f079ff
commit 6656a09f8c
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 30 additions and 3 deletions

View file

@ -87,7 +87,7 @@ backtrace = { workspace = true }
[target.'cfg(target_env = "ohos")'.dependencies]
env_filter = "0.1.3"
euclid = { workspace = true }
hilog = "0.2.1"
hilog = "0.2.2"
# force inprocess until we add multi-process support for ohos
ipc-channel = { workspace = true, features = ["force-inprocess"] }
napi-derive-ohos = "1.0.4"

View file

@ -507,6 +507,7 @@ static LOGGER: LazyLock<hilog::Logger> = LazyLock::new(|| {
"servoshell::egl::log",
// Show JS errors by default.
"script::dom::bindings::error",
"script::dom::console",
// Show GL errors by default.
"canvas::webgl_thread",
"compositing::compositor",

View file

@ -152,6 +152,14 @@ pub fn init(
},
};
if servoshell_preferences.log_to_file {
let mut servo_log = PathBuf::from(&native_values.cache_dir);
servo_log.push("servo.log");
if crate::egl::ohos::LOGGER.set_file_writer(servo_log).is_err() {
warn!("Could not set log file");
}
}
crate::init_tracing(servoshell_preferences.tracing_filter.as_deref());
#[cfg(target_env = "ohos")]
crate::egl::ohos::set_log_filter(servoshell_preferences.log_filter.as_deref());

View file

@ -62,6 +62,10 @@ pub(crate) struct ServoShellPreferences {
/// If a filter is passed, the logger should adjust accordingly.
#[cfg(target_env = "ohos")]
pub log_filter: Option<String>,
/// Log also to a file
#[cfg(target_env = "ohos")]
pub log_to_file: bool,
}
impl Default for ServoShellPreferences {
@ -82,6 +86,8 @@ impl Default for ServoShellPreferences {
userscripts_directory: None,
#[cfg(target_env = "ohos")]
log_filter: None,
#[cfg(target_env = "ohos")]
log_to_file: false,
}
}
}
@ -363,6 +369,13 @@ pub(crate) fn parse_command_line_arguments(args: Vec<String>) -> ArgumentParsing
"FILTER",
);
#[cfg(target_env = "ohos")]
opts.optflag(
"",
"log-to-file",
"Also log to a file (/data/app/el2/100/base/org.servo.servo/cache/servo.log)",
);
opts.optflag(
"",
"enable-experimental-web-platform-features",
@ -435,6 +448,9 @@ pub(crate) fn parse_command_line_arguments(args: Vec<String>) -> ArgumentParsing
log_filter
};
#[cfg(target_env = "ohos")]
let log_to_file = opt_match.opt_present("log-to-file");
let mut debug_options = DebugOptions::default();
for debug_string in opt_match.opt_strs("Z") {
if let Err(e) = debug_options.extend(debug_string) {
@ -648,6 +664,8 @@ pub(crate) fn parse_command_line_arguments(args: Vec<String>) -> ArgumentParsing
.map(PathBuf::from),
#[cfg(target_env = "ohos")]
log_filter,
#[cfg(target_env = "ohos")]
log_to_file,
..Default::default()
};