Forest is A lightweight Android-Kotlin first logging library. It is inspired by the Timber project. Although Timber is good and easy to use, but it's missing some features that can work better on an Android project.
Basic Usage
You will have to plant at least a Tree
to the Forest first so you can receive a log event from the Forest. By default, this library
comes with DebugTree, which print the logs to the logcat,
and we will be using this as an example on this page.
Step 1: Plant a Tree
// onCreate() of your application class or application entry point
Forest.plant(DebugTree())
Step 2: Create a Forest in any of your class
val forest = getForest(MyClass::class.java)
Step 3: Start logging!
forest.v("a message")
forest.d("a message")
forest.i("a message")
forest.w("a message")
forest.e("a message")
forest.f("a message")
Global Forest
You can optionally use the Global Forest to log event. The benefit of using the Global Forest is it's easy to use and you do not have to create a Forest on any of your class. You can just use the static methods to log event:
// onCreate() of your application class or application entry point
Forest.plant(DebugTree())
// Start logging!
Forest.v("a message")
Forest.d("a message")
Forest.i("a message")
Forest.w("a message")
Forest.e("a message")
Forest.f("a message")
Features
Features offer by this library includes:
- Log messages with a named logger. See Forest.
- Log message with a global logger. See Global Forest.
- Multiple log handlers. See Tree.
- Adding additional attributes to a log. See adding attributes.
- Share data globally with all the log handlers. See Forest Context.
- Pre-process a log. See pre-processing callback.
Next Step
- For more information on installation, see installation guide.
- For more information on basic usage, see basic usage guide
- For more information on Java usage, see Java guide.