Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a way to replace the standard Log in Android?

Is there a way to somehow intercept calls to the standard Log in android and perform some other action?

In desktop Java one would usually get some logger so there are ways to install a different logging handler / implementation. However, Android seems to have a static call to Log, and I could not find any information about replacing the default behavior.

I realize I can monitor the device log through ADB, but I'd like to have a different behavior in running apps on a device who opt in (e.g., by executing a certain instruction when the program starts out).

like image 336
Uri Avatar asked Jul 18 '11 16:07

Uri


2 Answers

As AedonEtLIRA points out Log is final so you need to roll/borrow a new one. I've been using Prasanta Paul's "MLog": http://prasanta-paul.blogspot.com/2010/07/custom-logger-for-android.html

It makes it easy to save logs to a text file and/or disable logging completely. If it doesn't already do what you need, it is a good base for managing logging.

like image 197
Darrell Avatar answered Oct 24 '22 05:10

Darrell


I think your best solution would be to replace all the Log calls in your application with your own class, MyLog, then call Log if they don't opt-in, and call your special logging feature if they opt-in.

Replacing all the Log calls shouldn't be hard, just a find and replace.

like image 26
Amandeep Grewal Avatar answered Oct 24 '22 04:10

Amandeep Grewal