This post was originally published at Logging Within your Application

When logging activity within your application, you have a couple of options.  You can create your own logging system that writes activity out to a file.  However this isn’t ideal because it means constant writes to flash memory, which slows your application down and wears out flash memory.

The better option is to make use of the slogger2 API.  It uses in memory logging, but also provides a file you can access later to gather log statements made by your application.  The log file for your application can be found in /tmp/slogger2/<progname>.<pid>.

Logging in a Cascades Application

If you are creating a Cascades application, it’s even easier.  In a Cascades application qDebug and console.log is redirected to use slogger2.

Logging from C++ in a Cascades application.

Logging from QML in a Cascades application.

Logging in a non-Cascades Application

If you are creating a non Cascades application (pure Qt, C or C++) you can use the slogger2 API directly.  The first step is to initialize slogger2.

After initializing, you can create log entries like this:

Where to Find Your Log Files

Either method creates a file you can access later to view activity in your application.  It is useful to add a feature to your application that could email this file to your support team.  The log statements for your application are logged in /tmp/slogger2/<progname>.<pid>.  You can also view your application’s log file by executing this command:

image

More here:

This post was originally published at Logging Within your Application