Loading...
Home
  • Tech Blogs
  • Videos
  • Conferences
    • Droidcon News
    • Upcoming Conferences
    • Become a Partner
    • Past Events
    • Keep Me Informed
    • Diversity Scholarships
  • Community
    • droidcon Team
    • How to Hold a Droidcon
  • Android Careers
Sign In

Global CSS

 

Remote logging with Timber and Firebase Realtime Database

Building Timber tree for tracking logs remotely & realtime.

 

 
Vipin KT
Android Developer @ Handzap Inc.
Published: July 08, 2020
Tweet
Share
 

 

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? The 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

  1. Create a Firebase project in the Firebase console.
  2. Register an app by clicking the android icon on the Project overview section.
  3. Download the google-services.json file and place it in your Android app module root directory.
  4. Add Firebase SDK into your Android project.

 

Project-level build.gradle

 

App-level 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

  1. 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 TimberRemoteTreeas 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.


Thanks for reading! I hope you enjoyed this article. Please show your love by clicking on the👏 button. Follow me to get notified when I post new articles. If you have any feedback, feel free to reach me on Twitter | LinkedIn | Github.

Thanks to Mario Sanoguera de Lorenzo. 

 

 

Tags: Android, Logging, Timber, Firebase, AndroidDev

 

View original article at: 


 

Originally published: June 12, 2020

Android News
Evolution of Android Update SystemEvolution of Android Update System
Evolution of Android Update SystemEvolution of Android Update System

By Ivan Kuten

So, how can you update Android on mobile devices? While developing software for Smart TVs and Android-based set-top boxes, we’ve narrowed it down to four ways, discarding some very exotic options:

By ProAndroidDev -
Android News
Happy Railway
Happy Railway

By Hadi Lashkari Ghouchani

This post is on the tail of Railway Oriented Programming in Kotlin by Antony Harfield. So you need to read it first and continue here. As it’s obvious I really liked it and tried it out. It needs every process have a result like

By ProAndroidDev -
Android News
Unit Tests and Concurrency
Unit Tests and Concurrency

By Stojan Anastasov

Once Retrofit added RxJava support, RxJava became my go-to concurrency framework for writing Android apps. One of the great things about RxJava is the excellent testing support. It includes TestObserver, TestScheduler, RxJavaPlugins so you can switch your schedulers in tests.

By ProAndroidDev -
Android News
When Compat libraries will not save you
When Compat libraries will not save you

By Danny Preussler

And why you should avoid using the “NewApi” suppression! The idea of “Compat” libraries was probably one of the key aspects of Android dominating the mobile space. Other than with iOS, Android users often could not update their operating system after a new version launch, simply as their phones won’t allow them to, the Android problem of fragmentation.

 

By ProAndroidDev -
droidcon News

Tech Showcases,

Developer Resources &

Partners

/portal/rest/jcr/repository/collaboration/Groups/spaces/droidcon_hq/Documents/public/home-details/EmployerBrandingHeader
EmployerBrandingHeader
https://jobs.droidcon.com/
/portal/rest/jcr/repository/collaboration/Groups/spaces/droidcon_hq/Documents/public/employerbranding/jobs-droidcon/jobs.droidcon.com
jobs.droidcon.com

Latest Android Jobs

http://www.kotlinweekly.net/
/portal/rest/jcr/repository/collaboration/Groups/spaces/droidcon_hq/Documents/public/employerbranding/kotlin-weekly/Kotlin Weekly
Kotlin Weekly

Your weekly dose of Kotlin

https://proandroiddev.com/
/portal/rest/jcr/repository/collaboration/Groups/spaces/droidcon_hq/Documents/public/employerbranding/pad/ProAndroidDev
ProAndroidDev

Android Tech Blogs, Case Studies and Step-by-Step Coding

/detail?content-id=/repository/collaboration/Groups/spaces/droidcon_hq/Documents/public/employerbranding/Zalando/Zalando
/portal/rest/jcr/repository/collaboration/Groups/spaces/droidcon_hq/Documents/public/employerbranding/Zalando/Zalando
Zalando

Meet one of Berlin's top employers

/detail?content-id=/repository/collaboration/Groups/spaces/droidcon_hq/Documents/public/employerbranding/Academy for App Success/Academy for App Success
/portal/rest/jcr/repository/collaboration/Groups/spaces/droidcon_hq/Documents/public/employerbranding/Academy for App Success/Academy for App Success
Academy for App Success

Google Play resources tailored for the global droidcon community

Follow us

Team droidcon

Get in touch with us

Write us an Email

 

 

Quicklinks

> Code of Conduct

> Terms and Conditions

> How to hold a conference

> FAQs

> Imprint

Droidcon is a registered trademark of Mobile Seasons GmbH Copyright © 2020. All rights reserved.

powered by Breakpoint One