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?
Face the tree to be measured and hold the stick vertically at a distance of 25 inches from your eye (Figure 4). Be sure that the scale "Number of 16-foot logs" is facing you. As with measuring diameter, this distance of 25 inches is critical to obtain accurate measurements.
Logging, or commercial logging, involves cutting trees for sale as timber or pulp. The timber is used to build homes, furniture, etc and the pulp is used to make paper and paper products. Logging is generally categorized into two categories: selective and clear-cutting.
Timber is an open-source logging library developed by Jake Wharton, which provides additional features on top of Android's normal Log class.
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.
public class LibraryATree extends Timber.HollowTree {
@Override
public void e(Args){
// Do something
}
}
public class LibraryBTree extends Timber.HollowTree {
@Override
public void w(Args){
// Do something
}
}
Timber.plant(new LibraryATree())
Timber.plant(new LibraryBTree())
Now in my code, if I want to log something via LibraryA, I do this:
Timber.e("Test Library A"); // calls LibraryA's Tree's `.e` method
and if I wanted to use Library B's logging utilities I do this:
Timber.w("Test Library B"); // calls LibraryB's Tree's `.w` method
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With