Skip to content
This repository has been archived by the owner on May 1, 2023. It is now read-only.

Console Logging #41

Closed
yesitskev opened this issue Feb 19, 2015 · 2 comments
Closed

Console Logging #41

yesitskev opened this issue Feb 19, 2015 · 2 comments

Comments

@yesitskev
Copy link

Is there an example or some functionality to do with redirecting logging to the chrome console instead of to logcat or wherever?

If not, lets get something like this implemented?

@yesitskev
Copy link
Author

I did a dirty hack to get logging functionality (i used Timber by Jake Wharton).

It appears that extending Console was a problem. I can only assume that the classname is being used to hookup the class and methods to chrome's handles. I recommend perhaps using a class annotation to allow for multiple handlers for each of chromes handles.

Here is a little hack example in case anyone else runs into this: StethoTree

@jasta
Copy link
Contributor

jasta commented Feb 19, 2015

There is a pretty straight forward way to make this work using ChromePeerManager and hacking Stetho itself just a little bit (patches welcome grin). Specifically, something like:

public class Console ... {
  private final ConsolePeerManager mConsolePeerManager = ConsolePeerManager.getInstance();

  @ChromeDevtoolsMethod
  public void enable(...) {
    mConsolePeerManager.addPeer(peer);
  }
}

public final class ConsolePeerManager extends ChromePeerManager { ... }

With that change, you can now track all peers that are aware of console updates and can dispatch to them easily using CLog:

CLog.writeToConsole(ConsolePeerManager.getInstance(), ...);

We wanted to encapsulate this for you, allowing for CLog itself to guess ConsolePeerManager.getInstnace() by default as well so that callers could just invoke:

CLog.writeToConsole(MessageLevel.WARNING, MessageSource.NETWORK, "foo");

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants