Painless Logcating


Recently I ran into a nice way to manage all my hundreds of logs that I am writing out while I am debugging my Android applications.
Although this is nothing that will move the world I find it an incredibly handy method of keeping everything together.


The Problem:

I really like to debug my applications with Log.d(TAG, message) or Log.e(TAG,message). And as well when you are used to the console, you usually will not work with logcat’s tagging system but rather mark your logs with a tag. For instance your typical log could look like this:

Log.d(“GPSActivity”,”=== Starting service ===”);

Which you then will filter out using grep:

$adb logcat | grep ‘===’

This already helps a lot filtering your custom messages on the console. Now what I started doing was creating are two functions per Class:

private void l(String msg){
Log.d(“ActLog”,”>==< "+msg+" >==<"); } private void e(String msg){ Log.e("ActLog",">==< "+msg+" >==<"); }

This will allow me to quickly log by calling a “one-letter” function and at the same time allows me to get rid of the debugging messages at roll-out by simply commenting the lines in the functions.

Leave a Reply

Your email address will not be published. Required fields are marked *


*