Remote logging with Timber and Firebase Realtime Database.
Building Timber tree for tracking logs remotely & realtime.

Logging is an essential part of software development. It helps developers to see what the application code is really doing. Android SDK has a built in class called Log. It contains utility methods to log messages with different priorities. The problem with Log class is that every time we need to to provide a TAG for the log and we have to make sure that the log messages are disabled in production.
To overcome these issues many developers started using Timber , an open-source library which extends Android Log class and enhances the logging experience in Android. With Timber, we don’t need to provide TAG for log messages, it will automatically adds TAG based on class and function names. We can even plant different Timber trees for different configurations.
The Problem
We (the developers) have a practice of checking the logs to find & fix the bugs by connecting the device over ADB connection. If the tester has found some bugs on his device and if it is not happening in ours then also we used to do the same thing as a first step. But what if the tester is in some other place and there is no way to connect to his device? Then it will be difficult to check the logs and hence finding the bug will take much efforts.
In this article I will explain how to track logs remotely with the help of Timber and Firebase Realtime Database. At the end, you will be able to track the logs of your application in Firebase console.
Why Firebase Realtime Database?
The Firebase Realtime Database is a cloud-hosted NoSQL database that lets you store and sync data between your users in real time.
- It will automatically receive updates with the newest data. ie; When ever the application creates a log message, it will be automatically updated in Firebase console without refreshing.
- It stores the data in json format as trees and it will be easy to navigate b/w logs.
- Setting up the db very is simple, you can create and start using within minutes.
So rather than building a web application (with database and server setup), it is easy to go with Firebase Realtime Database.
Firebase Setup
- Create a Firebase project in the Firebase console.
- Register an app by clicking the android icon on the Project overview section.
- Download the
google-services.json
file and place it in your Android app module root directory. - Add Firebase SDK into your Android project.
build.gradle
build.gradle
5. Navigate to the Database section of the Firebase console. You’ll be prompted to select an existing Firebase project. Follow the database creation workflow.
6. Configure Realtime Database rules on the ‘Rules’ tab. Here I am setting the read write access to public, change as per your needs.
{
"rules": {
".read": true,
".write": true
}
}
Timber Setup
- Add Timber dependency in app-level
build.gradle
file.
implementation 'com.jakewharton.timber:timber:4.7.1'
2. Create a Timber tree for pushing logs in Firebase Realtime Database.
Before creating the Timber tree, we will create a data class
for structuring the log messages.
We can create a Timber tree by extending Timber.Tree
or Timber.DebugTree
. I am creating for the debug
version of the app, hence using Timber.DebugTree
.
The log
method is responsible for printing the logs, so will put our logic for pushing the logs to Firebase inside this method.
Remote logging will be enabled only if BuildConfig.REMOTE_LOG_ENABLED
is true
. You can enable this in build.gradle
while giving the app to the tester.
Logs will be pushed to logs/date/deviceId/timestamp/
node. There will be a node for every devices under each date, so that we can easily navigate through the nodes and check logs.
DeviceDetails
contains the details of device and will be pushed under logs/date/deviceId/
directly. This will be passed to the TimberRemoteTree
as constructor parameter.
3. Plant the Timber tree.
In your application class, create an instance of TimberRemoteTree
and plant the tree.
Here I am creating a device id by using Settings.Secure.ANDROID_ID
, which will act as a unique identifier for the device in the data tree. You can use your own logic for creating the device id.
Testing
We have completed the setup for both Timber and Firebase Realtime Database. Now it is time for testing!.
Go through your application pages, where you have added the logs (add some logs by using Timber utility methods, if you haven’t added yet) and check the Database section in your Firebase console, you can see that the logs are updating in console at real time 🤩.

Conclusion
By using Timber and Firebase Realtime Database, it is very easy to create a remote logging system for android application. Firebase is lightweight and has a minimum learning curve. The logs will be updated in Firebase console at realtime and we can perform live tracking of logs remotely.