HyperLog: Android Remote Logger Library for Debugging

HyperLog, a utility logger library for Android on top of standard Android Log class for debugging purpose.

It is not easy to debug live mobile apps or libraries, or create every possible environment in which your end users use your app because of the variety of Android devices and variety of Android versions. It is very difficult to replicate every possible configuration and reproduce every single bug that could possibly occur when millions of users use your app. During mobile app development, we often find that logcat (for debugging) in Android Studio gets clear when an app reinstalls. However, this isn't a good approach as you are going to be get lots of log statement in your logcat and logcat doesn't maintain a history. Logging across multiple testing devices is hard.

Mobile developers are usually familiar with tools such as Google Analytics or Fabric.io but they are analytics or crashlytics systems, and not full-fledged logging solutions. Remote logging can be used to debug issues in both development and production. It makes debugging a much simpler and smoother process.

At HyperTrack, logs are the medium through which HyperTrack SDK speaks with us. It gives us end-to-end visibility. It helps us debug issues while developer using the HyperTrack SDK sit on the other side of the world. HyperTrack SDK pushes logs to the HyperTrack server, and the HyperTrack server uses ELK stack to process the logs and visualize them on Kibana. We have discussed our logging approach in more detail in an earlier blog.

There are many Logger libraries available for developers, e.g., Android-Logger and Timber. But these libraries print logs message on logcat in Android Studio that doesn't help to get the behavior of app in production, which means that these logs message aren't accessible to the developers. Remote logging is the solution that helps debug the problem. Remote logging the right set of information could provide valuable information that is otherwise difficult to gather, and could help unveil unexpected behaviors and bugs. Remote Logging increases accountability and gives you confidence. When someone has experienced a use-case that you haven't thought of, saying "We will investigate" is not great accountability. Saying "We have the logs and we know the exact line of code where the error occurred" is accountability.

Introducing HyperLog

HyperLog is a utility logger library for Android on top of standard Android Log class for debugging purpose. This is a simple library that will allow Android apps or library to store log message into the database so that developer can pull the logs from the database into the file or push the logs to your server for debugging from the database as a file. The Demo App will help you see the library in action.

Download

The library is available on mavenCentral and jcenter. In your app level build.gradle, add the following code snippet and run the gradle-sync. You can alternatively follow the steps as highlighted here.

dependencies {
    ...
    compile 'com.hypertrack:hyperlog:0.0.7'
    ...
}

Once this is done, you can start recording log messages and smartly push them to your server for debugging.

Initialize and Usage

Inside onCreate of Application class or Launcher Activity initialize the library.

HyperLog.initialize(this);
HyperLog.setLogLevel(Log.VERBOSE);
HyperLog.d(TAG,"Debug Log");

Push Logs File to the Server

Developers can push logs to their server whenever they want. They can achieve this by multiple ways such as by pushing an FCM Notification to their app. Call HyperLog.pushLogs or create a scheduled job when the notification is received. Call HyperLog.pushLogs when the job is scheduled, so it will push a text file or gzip compressed file to your remote-server.

Set the API Endpoint URL HyperLog.setURL before calling HyperLog.pushLogs method otherwise exception will be thrown.

HyperLog.setURL("API URL");
HyperLog.pushLogs(this, false, new HLCallback() {
            @Override
            public void onSuccess(@NonNull Object response) {

            }

            @Override
            public void onError(@NonNull VolleyError errorResponse) {

            }
});

Have issues or feature requests? Use issues tracker. We’d love to see your pull requests, so send them in! Have questions, suggestions? Join the discussion on Slack.

Like what we are doing? Sign up for HyperTrack and build movement-aware applications!