LogCat is a great logging feature which is part of the core Android Developper Experience™. Most of us using an IDE use the DDMS tool to view the LogCat outputs. Some might also use directly the console with
adb logcat -v long, with maybe some
awk to enhance the result.
Well Jake Wharton (you know, the guy behind ActionBarSherlock) developped PidCat, a Python script to print the LogCat output in the console in a usefull way. Here's how it looks like.
After a couple of day, I find it better than DDMS LogCat view. And what's great is that it's Open Source, so I'll probably add some features in it myself. You can download it or fork it from PidCat Github Repository.
A couple of days ago, a question popped on StackOverflow, asking how to link a log line in LogCat to the source code, just like it happens when you Log an exception.
The first answers where to add a fake Exception. Naturally, there will be the line you want, but also a lot of noise in your LogCat.
Then someone proposed a method to simulated an exception Log, without the whole stacktrace (see the answer here).
The solution works fine, but can be quite verbose. With a little bit of try and error, I found out that the most important part is the "at (file.java:42)". It doesn't matter where it is in the message. You can even have mor than one, it only takes into account the last one.
So I worked out a LogLink class to use this systme anywhere and seamlessly. Here's an example of how it works :
// can be one of INSERT_FIRST, INSERT_LAST or INSERT_NONE
// default value is INSERT_LAST, and you can call it only once
// also exist as v, d, w, e and wtf
LogUtils.i("MyClass", "A message");
The previous code will output the following output
MyClass A message at (MyClass.java:42)
You can see and download the LogUtils class here