Skip to content

Redirect console output to logcat on Android #19999

Open

Description

@fabricedesre

The console output (components/script/dom/console.rs) is always sent to stdout. On Android, it should go to the logcat by using the android log service. Using the standard log macros does the right thing so it's an easy change.

What I'd like to get clarification on is how to organize this kind of platform dependent implementation. Should I:

  • Pepper the current console.rs with cfg(target_os = "android")] blocks.
  • Put the android implementation in dom/console_android.rs and select this file in dom/mod.rs.
  • Put the android implementation in dom/android/console.rs and select this module in dom/mod.rs.
  • ... something else?

Activity

  1. self-assigned this
    on Feb 8, 2018
  2. larsbergstrom commented on Feb 8, 2018

    @larsbergstrom
    Contributor

    I'm a little bit confused, as Servo on Android has redirected all stdout/stderr to Android logcat automatically ever since I first did the port. Did that change? We basically just spun up a background thread that redirected the handles.

    I think android_rs_glue has something similar, though rust-mobile/android-rs-glue@72be8df may no longer be relevant?

    In any case, we traditionally had just redirected all the random goop that goes to console to the android log, assuming that we'd be unable to get the myriad Rust dependencies to all unify their output to Rust logging components and redirect that to the android log facilities.

    cc @paulrouget

  3. fabricedesre commented on Feb 8, 2018

    @fabricedesre
    ContributorAuthor

    Ha, that's because my device is android-but-not-really, and so it's not using the redirection provided by the android glue.

    The standard log macros, when used with eg the android_logger crate do the right thing like setting the log level in the android subsystem so you can filter them properly. Actually most of Servo debug info ends up in logcat this way, just not the console logs.

    So improving the situation for console.log() would not change anything the android glue redirect of stdout, but would still be an improvement.

  4. paulrouget commented on Jul 31, 2018

    @paulrouget
    Contributor

    When #20912 lands, I think the right approach will be to delegate console printing to the embedder, the same way it's done for window.alert, and in the case of android, write to logcat via android_logger (see the change in the alert code in the PR).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions