Over a million developers have joined DZone.

How to Collect Mobile Crash Logs

Want to learn about collecting mobile crash logs? Here's an overview of collecting mobile crash logs from infrastructure setting to log cluster setting.

Download Forrester’s “Vendor Landscape, Application Performance Management” report that examines the evolving role of APM as a key driver of customer satisfaction and business success, brought to you in partnership with BMC.

For any company, the first task of processing big data appears when it starts to collect and analyze log files. This is a very important and time-consuming process. Error analysis allows you to make any application more qualitative and stable. The right choice of closure allows you to reduce response time to an incident and save resources involved in analyzing and solving some problem.

Most decisions on the market are siloed services that are intended only for specific types of platforms (mobile, js or server logs). This is not always convenient especially when a company develops a full stack of applications for all possible platforms. But there is a simple solution for assembling log files on a single platform.

LogPacker can collect and analyze any log files on any platforms. For example:

  • Server logs.
  • Mobile apps logs and crashes.
  • JavaScript errors.

At the same time most of them involve straight integration, the service automatically recognizes any types of log files, collect, aggregate and analyze them.

Let’s consider the main steps of the organization of the log management process by the example of dealing with mobile applications.

  • Infrastructure setup.
  • LogPacker setup for log and crash analysis.
  • Dashboards setup.
  • Library connection for Android/iOS/Windows Phone applications.

If we look at every point, it seems that the setting of the whole system takes a long time, but in our case, it’s quite the opposite. The service works out of the box and for the full setting we need to change some configuration files.

We are going to review every point in details, and let’s start with architecture configuration for storing and analyzing log files.

Infrastructure Setting

LogPacker Cluster stores and processes logs from mobile devices. It can consist of several linked LogPacker-servers or it can be a standalone application, installed on Linux-server. Several nodes in cluster allow handling load balancing and saving log concurrently to different types of storages.

We provide you with a free license with a limit of five servers. This means that you can build a cluster of five nodes for free that can endure any load.

First, let’s see how to run a cluster on all five nodes. After registration for downloading you will be able to use console daemon-application. It is necessary to install it on five servers. You can do it, for example, with the help of rpm/deb pack or to install it manually from tar-archive.

Let’s consider the install process for every way in details:

Install RPM:

sudo rpm -ihv logpacker-1.0_27_10_2015_03_45_30-1.x86_64.rpm

The daemon will be installed to the folder /opt/logpacker.

Install DEB:

sudo dpkg -i logpacker_1.0-27-10-2015_03-45-30_amd64.deb

Install from .tar archive allows you to install LogPacker-daemon to any directory and to have several daemons on one machine (if necessary):

tar -xvf logpacker-27-10-2015_03-45-30.tar.gz

Before run, we need to set up log storage. This is Elasticsearch by default, working on localhost:9200. LogPacker server supports the following storage types: file, Elasticsearch, MySQL, PostgreSQL, MongoDB, HBase, Influxdb, Kafka, tarantool, memcached. At the same time, it can save data concurrently to different storages.

We also need Supervisord for daemonizing LogPacker application. Let’s create /etc/supervisord.d/logpacker_daemon.ini file with the following content:

command=/opt/logpacker/logpacker_daemon --server

We inform Supervisord of a new program:

sudo supervisorctl reread

At the end we got the following architecture:

Infrastructure is ready and we can start LogPacker cluster setup.

Cluster Setting for Log and Crash Collection

Then we need to combine all five servers to the cluster. Each server has a configuration fileconfigs/server.ini that we need to set up.

For full configuration, we need to indicate other cluster nodes to only one server. This is an example of first server configuration:





In configuration file of the second server and the next one we need to change the following:


Let’s run all LogPacker nodes with the help of Supervisorctl:

sudo supervisorctl start logpacker_daemon

Now our cluster can receive logs, errors, etc. As messages can be received from different devices and networks, it is necessary to open API port, externally accessible. Proxy pass for local port in Nginx is ok for that:

server {
   listen 80;
   server_name logpacker.mywebsite.com;

   location / {
       proxy_set_header   X-Real-IP $remote_addr;
       proxy_set_header   Host      $http_host;
       proxy_pass             http://localhost:9997;

It is possible to scale API on all five servers and install Load Balancer that distributes the load.

If you want to keep logs not only in ES but also, for example, in MySQL, you need to change the server configuration:



; Database will be created automatically if it's possible
; Table will be created automatically

It can be useful when you want to keep all data in ES/Database, and recent events to keep in cash.

Dashboard Setting

Now let’s turn to displaying of received data. Cluster has two standard ways of displaying logs:

Let’s consider the first one. For Kibana setting for logs displaying in real time we need:

This function has the following dashboards:

  • Server Logs.
  • JS Errors.
  • Mobile Logs.

Logs/crashes of mobile devices will be available in Mobile Logs dashboard. They will be divided for iOS / Android / Windows Phone in Kibana dashboard.

Setting for Android

LogPacker SDK for Android can be easily downloaded by logpackermobilesdk.aar. This is the .aar pack that can be imported to Java-project. This is an example for Android Studio:

  • File ➤New ➤New Module ➤Import .JAR or .AAR package
  • File ➤Project Structure ➤app ➤Dependencies ➤Add Module Dependency
  • Add import: import go.logpackermobilesdk.Logpackermobilesdk;

Then, we need to find out the cluster address. The following example contains the client generation and setting for message sending to LogPacker:

import go.logpackermobilesdk.Logpackermobilesdk;

// ...

try {
   client = Logpackermobilesdk.NewClient("https://logpacker.mywebsite.com", "dev", android.os.Build.MODEL);

   msg = client.NewMessage();
   msg.setMessage("Crash is here!");
   // Use another optional setters for msg object

   client.Send(msg); // Send will return Cluster response
} catch (Exception e) {
   // Cannot connect to Cluster or validation error

Also, we can setup Android application for log crashes dispatch to LogPacker:

// ...
import go.logpackermobilesdk.Logpackermobilesdk;

public class MyApplication extends Application {
   public void onCreate () {
       // Setup handler for uncaught exceptions.
       Thread.setDefaultUncaughtExceptionHandler (new Thread.UncaughtExceptionHandler() {
           public void uncaughtException (Thread thread, Throwable e) {
               // Paste here above code to send e.getMessage() to the LogPacker Cluster, use msg.setLogLevel(Logpackermobilesdk.FatalLogLevel)

Configuration for Android application is ready, let’s move to iOS.

Setting for iOS

Library is working for both Objective-C and Swift. First, let’s see how to import library to Xcode:

  • Download Logpackermobilesdk.framework.tar and unpack the archive.
  • Drag the Logpacker.framework folder to Xcode file browser.
  • Add import *#import "Logpackermobilesdk/Logpackermobilesdk.h"*.

#import "ViewController.h"
#import "Logpackermobilesdk/Logpackermobilesdk.h"

@interface ViewController ()


@implementation ViewController

- (void)viewDidLoad {
   [super viewDidLoad];
   GoLogpackermobilesdkClient *client;
   NSError *error;
   GoLogpackermobilesdkNewClient(@"https://logpacker.mywebsite.com", @"dev", [[UIDevice currentDevice] systemVersion], &client, &error);
   GoLogpackermobilesdkMessage *msg;
   msg = client.newMessage;
   msg.message = @"Crash is here!";
   // Use another optional setters for msg object
   GoLogpackermobilesdkResult *result;
   [client send:(msg) ret0_:(&result) error:(&error)];

Then, we need to setup dispatch exceptions and signals to the LogPacker cluster:

void InstallUncaughtExceptionHandler()
   signal(SIGABRT, SignalHandler);
   signal(SIGILL, SignalHandler);
   signal(SIGSEGV, SignalHandler);
   signal(SIGFPE, SignalHandler);
   signal(SIGBUS, SignalHandler);
   signal(SIGPIPE, SignalHandler);

void HandleException(NSException *exception) {
   // Paste here above code to send [exception reason] to the LogPacker Cluster, use msg.logLevel = GoLogpackermobilesdk.fatalLogLevel

static void SignalHandler(int signo) {
   // The same

Setting for Windows Phone

LogPacker has an SDK for Windows Phone applications written in C#. How to install it:

  1. Download and untar logpackermobilesdk.dll.tar
  2. Project ➤Edit Preferences
  3. .Net Assembly ➤Browse ➤Find logpackermobilesdk.dll file
  4. Add import into .cs file *using logpackermobilesdk;*
using System;
using logpackermobilesdk;

namespace test
    class MainClass
        public static void Main (string[] args)
            try {
                Client c = new Client ("https://logpacker.mywebsite.com", "dev", System.Environment.MachineName);
                Event e = new Event ("Crash is here!", "modulename", Event.FatalLogLevel, "1000", "John");
                c.Send (e);
            } catch {
                // Handle connection error here

For crashes/exception you can use SendException method:

using System;
using logpackermobilesdk;

namespace test
    class MainClass
        public static void Main (string[] args)
            try {
                // Exception thrown here
            } catch (Exception e) {
                Client c = new Client ("https://logpacker.mywebsite.com", "dev", System.Environment.MachineName);
                c.SendException (e);

Eventually, in a short time, we have set up the system for log collection and analysis for mobile apps. Also, with a little effort, we can add to this system services for analyzing Javascript errors and collecting log files from all our servers. System support is easy and doesn’t require lots of resources. LogPacker Cluster can be easily scaled horizontally by adding new nodes. At the same time, service has full load control and it reports all possible issues.

Efficiency with minimal resources involvement is the number one issue in solving any problem with big data. As we can see, LogPacker totally succeeds with this task.

Register and install LogPacker Cluster for free!

See Forrester’s Report, “Vendor Landscape, Application Performance Management” to identify the right vendor to help IT deliver better service at a lower cost, brought to you in partnership with BMC.

log management,log analysis,log parsing,logs,android app development,ios app development,windows phone development,log analytics,crash report

Published at DZone with permission of Vladislav Chernov. See the original article here.

Opinions expressed by DZone contributors are their own.

The best of DZone straight to your inbox.

Please provide a valid email address.

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}