Home » Android » Timber Android in an Android Library project-Exceptionshub

Timber Android in an Android Library project-Exceptionshub

Posted by: admin February 26, 2020 Leave a comment

Questions:

I am wondering if is there any way to use Timber Android in an Android library project, without initiate it in onCreate() in Application Class ?

How to&Answers:

So it depends when you want to initialize your library. You can plant a DebugTree for example in your Library init class and if your library is initialized in your Application class or the better way would be to abstract it a little bit and make it possible to give your library a logger instance for example so that in debug builds it would be possible to pass some logger. So it is recommended to plant the tree as early as possible but this is not a must but you may be too late for some important logs

Behavior is added through Tree instances. You can install an instance by calling Timber.plant. Installation of Trees should be done as early as possible. The onCreate of your application is the most logical choice. https://github.com/JakeWharton/timber/blob/master/README.md

So like i already said you need to decide when and how you want to do enable logs for your lib (only debug etc..) and when your library will be instantiated.