Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Terser Coloring of a LogCat Message?

To speed up my debugging, I color certain messages for instant spotting, like this:

if (isOK)
    Log.i(TAG, stringVarContentOfMessage);
else
    Log.v(TAG, stringVarContentOfMessage);

It works, but viewing this source code over and over again, where the only justification for occupying 4 precious lines is one different character only (Log.i vs. Log.v) is an eyesore for me.

Any suggestions for avoiding this eyesore without resorting to the following?

isOK ? Log.i(TAG, stringVarContentOfMessage) : Log.v(TAG, stringVarContentOfMessage);
like image 941
ateiob Avatar asked Sep 08 '11 13:09

ateiob


2 Answers

You can use Log.println():

Log.println(isOK ? Log.INFO : Log.VERBOSE, TAG, stringVarContentOfMessage);
like image 161
Joachim Sauer Avatar answered Nov 03 '22 07:11

Joachim Sauer


Create a helper method:

private void conditionalLog(boolean flag, String tag, String message);
like image 21
Edward Dale Avatar answered Nov 03 '22 07:11

Edward Dale