Skip to content

Logs are an essential part of understanding how apps behave on different OS and device platforms. By default, both Android and iOS are pushing lots of different relevant data (and sometimes just everything) to logs. Developers can also easily add and write custom log messages or just push the data in logs for later inspection.

As execution of apps with test automation produces tons of data, and especially when tests are executed simultaneously on a variety of devices, the real-time logging can be challenging. However, this is all possible and very easy to adopt while having your app and test running on devices on a cloud service.

realtime-data-logging

For instance, some of our users are using Loggly’s Logback extension to push all relevant log data to their cloud service using HTTP/HTTPS Event API. There are similar services available, but Loggly’s service is really nice and provides a very easy and straightforward way to push your data, stack traces with a properly formatted timestamp, method, class and so on to their service. As this gives you a way to monitor data flow in real time, this kind of combination can reveal what really matters and what areas you should focus on your app to get fixed.

Log and Review Android App Data in Real Time on Bitbar Testing

Okay, let’s start with a basic example for Android real-time data logging. I’ll be using Loggly as an example.

Step #1: Add Logback extension to your App

First, take a look at this Github repository for Logback extension for your app and test APK. We actually recommend that you include all these changes in your instrumentation APK (and not in your actual application APK).

In case you are using Maven, you can find the code snippets for other package managers. Next, add the following lines of code into the dependency section of your pom.xml file:

<dependency>
 <groupId>org.logback-extensions</groupId>
 <artifactId>logback-ext-loggly</artifactId>
 <version>0.1.4</version>
</dependency>

Execute mvn to install the extension:

mvn clean install

If you are using Android Studio and Gradle, you can simply add this in your pom.xml file:

'org.logback-extensions:logback-ext-loggly:0.1.4'

Step #2: Configure the Logback extension

Next, configure Logback with your TOKEN and you can use the following code snippet as a basis.

First, create or open (if the file exists) logback.xml configuration file and add the LogglyAppender. This example pattern will parse the Java log in Loggly:

<configuration debug="true">
   <appender name="loggly" class="ch.qos.logback.ext.loggly.LogglyAppender">
       <endpointUrl>https://logs-01.loggly.com/inputs/TOKEN/tag/logback</endpointUrl>
       <pattern>%d{"ISO8601", UTC}  %p %t %c{0}.%M - %m%n</pattern>
   </appender>
   <root level="info">
       <appender-ref ref="loggly" />
   </root>
</configuration>

Replace TOKEN with your token from the Loggly setup page.

Step #3: Add Code for Logging and Test Connection

Add code to construct a SLF4J Logger:

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
final static Logger logger = LoggerFactory.getLogger();
...
logger.info("{"message" : "Test Log Entry from Your App."}");

Now, you can run your app and it will send a text message/event to Loggly service. You should see this showing up at Loggly dashboard:

message: Test Log Entry from Your App.

Another good alternative for manual remote data logging is the manual testing service at Bitbar Testing. In addition to log data, you’ll also get other relevant info (e.g. screenshots) while you are running the app through on any of our devices.

Screen Shot 2015-12-16 at 3.13.30 PM

All right, that’s all to set up a data logging for your mobile app in real time!

Happy Logging!

Ville-Veikko Helppi

Mobile Testing Expert