Log levels are:
Verbose 2
Debug 3
Info 4
Warn 5
Error 6
Assert 7
The default log level set by the Android OS is 4 and above. Its the reverse for the levels of detail
in that verbose is the most detailed log level you can use. And debug is compield but stripped out
at runtime and obvoously you do not want Verbose triggered in your producition application.
At bare minimum to get debug and verbose to show you have to set it, which you can do via:
$adb setprops log.tag. DEBUG
Quick question, if you do this what log levels show in logcat? The log level you have sset and
everything above that log level shows in logcat. Thus if you want everything to show you set Verbose log level.
Okay so where does it show up? The Android OS by default logs to logcat four ‘log streams’;
Main
Radio
Events
System
Logs of levels Verbose through Assert are sent to the Main Log stream, in other words all application logging.
Thus, how do we prevent verbose and debug from being triggered in the produciton application but have it
triggered in the application we are debugging without changing any code?
You wrap the log calls with isLogable, for example in log wrapper class:
public static void debug(final Class myClass, final String tag,
final String msg) {
if (Log.isLoggable(tag, Log.DEBUG)) {
Log.d(tag, myClass.getSimpleName() + “:” + msg);
}
}
In this case if setprops is not used to set either Verbose or debug than log debug never gets executed
because android OS defaults to INFO log level and above if not set via setprops. if you use log calls
wrapped by isLoggable than you never have to worry about removing log calls to Debug or Verbose
as the isLoggable if statements ensure its not executed if not set to Loggable.
One of the best coding practices for Android Java Application Development is code wrapper classes that
make your code development easier by saving steps. Cdoing a log wrapper class should one of your
first steps in best coding practices.