Custom logging messages hard to distinguish from other logcat messages

39 Views Asked by At

In Android Studio's logcat window it is hard to distinguish my custom log messages (Log.d, Log.e...) from the other log messages. This still happens when setting package:mine.

See the image below:

enter image description here

1

There are 1 best solutions below

0
S. Gissel On

Best solution is to use Timber.

In MainApplication class set up a custom class extending Timber.Tree. Then Timber.plant it like this:

if (BuildConfig.DEBUG) {
    Timber.plant(new MyPersonalDebugTree());
} else {
    Timber.plant(new CrashReportingTree());
}

The custom Timber.Tree looks like following:

public class MyPersonalDebugTree extends Timber.DebugTree {
    @Override
    protected void log(int priority, String tag, @NonNull String message, Throwable t) {
        StringBuilder sb = new StringBuilder(message);
        sb.insert(0, "\uD83D\uDC99\uD83D\uDC99\uD83D\uDC99 - ");
        super.log(priority, tag, sb.toString(), t);
    }
}

Notice this:

sb.insert(0, "\uD83D\uDC99\uD83D\uDC99\uD83D\uDC99 - ");

It modifies your log messages and adds a prefix containing ❤️❤️❤️.

enter image description here