mirror of
https://github.com/servo/servo.git
synced 2025-08-07 06:25:32 +01:00
Differentiate console message behavior based on target OS (#37912)
Printing using log macro for Android and OhOS, while retaining original stderr behavior for other platforms. Fixes: #37877 Signed-off-by: abdelrahman1234567 <boudyalex321@gmail.com>
This commit is contained in:
parent
ee8bd14f3b
commit
3d4868592a
1 changed files with 19 additions and 5 deletions
|
@ -106,6 +106,7 @@ impl Console {
|
|||
// we're finished with stdout. Since the stderr lock is reentrant, there is
|
||||
// no risk of deadlock if the callback ends up trying to write to stderr for
|
||||
// any reason.
|
||||
#[cfg(not(any(target_os = "android", target_env = "ohos")))]
|
||||
fn with_stderr_lock<F>(f: F)
|
||||
where
|
||||
F: FnOnce(),
|
||||
|
@ -335,11 +336,24 @@ fn stringify_handle_values(messages: &[HandleValue]) -> DOMString {
|
|||
}
|
||||
|
||||
fn console_message(global: &GlobalScope, message: &DOMString) {
|
||||
with_stderr_lock(move || {
|
||||
let prefix = global.current_group_label().unwrap_or_default();
|
||||
let message = format!("{}{}", prefix, message);
|
||||
println!("{}", message);
|
||||
})
|
||||
let prefix = global.current_group_label().unwrap_or_default();
|
||||
let formatted_message = format!("{}{}", prefix, message);
|
||||
|
||||
// On ohos / android stdout and stderr don't go anywhere useful,
|
||||
// and are redirected in servoshell to the logger again by a
|
||||
// dedicated thread. Better to directly log to the system logger
|
||||
// on ohos / android to avoid this.
|
||||
#[cfg(any(target_os = "android", target_env = "ohos"))]
|
||||
{
|
||||
info!("{}", formatted_message);
|
||||
}
|
||||
|
||||
#[cfg(not(any(target_os = "android", target_env = "ohos")))]
|
||||
{
|
||||
with_stderr_lock(move || {
|
||||
println!("{}", formatted_message);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Eq, PartialEq)]
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue