2

After search a lot in the stackoverflow and via google about how to intercept the logs in my application. The solution that I found is executing the command logcat -v time in the runtime but this solution print all the logs and I just want to intercept all the calls to the Log.d/w/e methods inside my application.

Question

Is there some solution like attaching a listener to one class that report me all the logs?

For example

Get the Logger.getGlobal() and add some handler or listener to the main logger to receive all the logs.

Any information about this would be great!

joselufo
  • 3,393
  • 3
  • 23
  • 37
  • AspectJ might do what you want. I'm afraid I haven't used it so can't offer any examples or provide a link. :-( – Christopher Schneider Feb 02 '16 at 19:29
  • Possible duplicate of [Is there a way to replace the standard Log in Android?](https://stackoverflow.com/questions/6736320/is-there-a-way-to-replace-the-standard-log-in-android) – TheIT Feb 28 '18 at 00:56

1 Answers1

1

The solution that I found is executing the command logcat -v time

That is not documented and not supported.

Is there some solution like attaching a listener to one class that report me all the logs?

Only if you use your own logging wrapper. There are various libraries available that give you more flexible logging options.

CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491
  • You can execute "Runtime.getRuntime().exec("logcat -v time");" for example. My problem is is that I can't use a logging wrapper because the application fully coupled with the Log.d/e/w. Thanks!! – joselufo Feb 02 '16 at 18:39
  • 1
    Well, if you're on linux, you could do a find/replace through all the files and point to your wrapper instead (not sure about the windows variant, though), e.g.: grep -rl 'android.utils.Logger' ./ | xargs sed -i 's/android.utils.Logger/com.myapp.utils.Logger/g' where you replace com.myapp.utils.Logger with your Logger wrapper class, that just mimics the same calls to Log.d/e/w and can trigger some callback – Cruceo Feb 02 '16 at 20:46