Wednesday, 2 November 2011

Android - Colored logcat

With the introduction of Android, the concept of Logcat was also introduced. Basically it is a set of logs  printed in the console, like the method println() of Java do, but a bit more sophisticated. Here you can find more information:

The main problem with them is, if we compared them with the LogCat perspective included in the SDK for eclipse, they don't have any color. While messages like warning or error have very colorful characters in eclipse and thus, easy to see, in the terminal every message seems like the same.

Searching in the Internet, I found several scripts to add new lines to the logcat command and then, make them more colorful.

Linux and Mac os
For all the unix systems, there is a script done by Jeff Sharkey which could be executed in the terminal. You can find it here:

You should download it and change the extension of the file by .py
After it, execute the command:
adb logcat | ./coloredlogcat.py

Windows
Adrian Vintu, inspired by Jeff Sharkey, has created a translator to execute the code of Jeff Sharkey and show it in the windows console.

You can find it here:

The steps to execute it are:
1. Download the file
2. Unzip the file. It contains:
  • color_console.py: A python script done by Adrian Vintu
  • coloredlogcat.py: The original python script done by Jeff Sharkey
  • logcat.bat: a console executable file which do the translation
3. Copy it into the platform-tool folder of Android SDK. For example:
C:\android-sdk-windows\platform-tools\logcat.bat
4. Running the program by write
logcat
in the console

Conclusion
Normally I code with my laptop, which only has 13" inch of screen. After using those scripts, the pid, tag and the colors uses at least 1/3 part of my screen, which make it not so useful. If you have larger screen, it could be fine. But for my case, I prefer to use some tricks like adding several symbols (------------) at the begging of the important messages, which could make me easily distinguish them.

4 comments:

  1. where do you execute the command ? terminal says commands not found on machos thxxx

    ReplyDelete
    Replies
    1. You should have it in your actual directory or have the directory of the file in the environment variable of the system.

      You might see how to add a directory in the PATH.

      Delete
  2. On Windows this isn't outputting anything.
    I have done python console redirection on Windows before and I think it required a few tweaks unique to Windows.
    Is this code confirmed to work w/ Windows, or do you think it will need a few tweaks?

    ReplyDelete
    Replies
    1. Yes, you are right. The program does not output anything. In fact, this has been reported on the developer's page:
      http://adrianvintu.com/blogengine/post/Colored-Logcat-Script-for-Windows.aspx

      The good news is he know it, the bad news is he switched to another tool and I think he won't fix it.
      http://www.baremetalsoft.com/baretail/

      Since I am really busy, I don't have time to fix it neither. Sorry about it.

      Delete