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).
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With