I have Timber library for logging and cooperation with crash-reporting services and I have both Crashlytics and Loggly services in my app.
Thus, I had to plant two trees:
Timber.plant(new CrashlyticsTree());
Timber.plant(new LogglyTree(BuildConfig.LOGGLY_TOKEN));
Now, each time I call:
Timber.e("bla bla");
I get all the logs in Loggly, but I want some of them to go to Loggly and some of them to go to Crashlytics, so how do I do that?
Turns out every call to
.e
or.w
for example, iterates through all planted trees and calls their respective.e
and.w
implementations.This means that if I wanted to separate Library A and Library B I needed to use different logging priority for each.
So I chose to use
.e
for Library A and.w
for Library B.In order to do that, I had to create custom trees that inherit from Timber.HollowTree and only implement the needed log call, and leave the rest of them hollow.
Now in my code, if I want to log something via LibraryA, I do this:
and if I wanted to use Library B's logging utilities I do this: