I am having lots of logging statements to debug for example.
Log.v(TAG, "Message here");
Log.w(TAG, " WARNING HERE");
while deploying this application on device phone i want to turn off the verbose logging from where i can enable/disable logging.
The better way is to use SLF4J API + some of its implementation.
For Android applications you can use the following:
You should use
May be you can see this Log extension class: https://github.com/dbauduin/Android-Tools/tree/master/logs.
It enables you to have a fine control on logs. You can for example disable all logs or just the logs of some packages or classes.
Moreover, it adds some useful functionalities (for instance you don't have to pass a tag for each log).
There is a tiny drop-in replacement for the standard android Log class - https://github.com/zserge/log
Basically all you have to do is to replace imports from
android.util.Log
totrikita.log.Log
. Then in yourApplication.onCreate()
or in some static initalizer check for theBuilConfig.DEBUG
or any other flag and useLog.level(Log.D)
orLog.level(Log.E)
to change the minimal log level. You can useLog.useLog(false)
to disable logging at all.I took a simple route - creating a wrapper class that also makes use of variable parameter lists.
For me it is often useful being able to set different log levels for each TAG.
I am using this very simple wrapper class:
Now just set the log level per TAG at the beginning of each class: