Getting Started

Before you get started, make sure you have install this library by following this installation guide.

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")

Core Concepts

Let's first understand 2 important classes in this library and their purposes:

  • Forest - Serves as a logger, in which you will use it to log an event.
  • Tree - Serves as a log handler, in which you will use it to handle the log event sent by Forest.

There are 2 types of Forest, Forest and Global Forest. For simplicity, unless specify, the code examples use on this wiki will be using Forest.

Next Step

Forest has many features to help you log an event much easily. Checkout the following features by visiting the link below:

  • Create your own log handler. See Tree.
  • In-depth understanding of the Forest object. See Forest.
  • Different types of log levels. See Log Levels.
  • Adding attributes to your log event. See Adding Attributes.
  • Sharing data across all loggers. See Forest Context.
  • Pre-process a log event to modify or filter the log event. See Pre-process Log.