ateiob
ateiob

Reputation: 9106

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);

Upvotes: 6

Views: 167

Answers (3)

not2qubit
not2qubit

Reputation: 17037

A better way is to color from the other end. Just color selected logcat messages. See: Modifying the Android logcat stream for full-color debugging That is a Python script that you can easily mod to your own pleasure.

Upvotes: 0

Joachim Sauer
Joachim Sauer

Reputation: 308239

You can use Log.println():

Log.println(isOK ? Log.INFO : Log.VERBOSE, TAG, stringVarContentOfMessage);

Upvotes: 3

Edward Dale
Edward Dale

Reputation: 30143

Create a helper method:

private void conditionalLog(boolean flag, String tag, String message);

Upvotes: 3

Related Questions