Qt Reference Documentation

QLog Class

The QLog class provides an easy to use logging mechanism. More...

 #include <QLog>

Static Public Members

void setConfigFile(const QString &path)

Detailed Description

The QLog class provides an easy to use logging mechanism.

Overview

QLog is designed to provide a very flexible logging mechanism in a very efficent way.

Features

1. Logging in a file:

Instead having all logging information in the standard output QLog can write all log messages (including QDebug messages) into a specific output file.

2. Enable or disable logging without recompiling your project.

Logging can be activated by providing a QLog configuration file.

3. Logging with categories

Developer can create their own QLog categories.

Every category can be turned on or off for logging during runtime.

How to use

Creating a QLog configuration file

As mentioned above a QLog configuration file is needed to control the behaviour or QLog. The configuration file contains following keys:

KeyValueDescription
FunctionNametrue/falseWriting out the name of the function for each log entry
LineNumbertrue/falseWriting out the Line number where this log was made in each log entry
FileNametrue/falseWriting out the file name where this log was made for each log entry
outputFilefile pathOutput file for logging
category (e.g. MAIN_LOG)true/falseTurns on or of the category for logging

Here is an example of a QLog configuration file:

FunctionName = false
USB_LOG = false
MAIN_LOG = true
outputFile = /tmp/tst_log_output

QLog usage in you project

QLog provides a macro to create your QLog categories:

 QLOG_CATEGORY(MAIN_LOG)
 QLOG_CATEGORY(USB_LOG)

In this example a QLog category MAIN_LOG and USB_LOG is created.

Now you need to tell QLog where the QLog configuration file can be found.

     //Set the QLog configuration file
     QLog::setConfigFile("./logcfg.txt");

In this example the configuration file "log.txt" is in the current directory.

A logging can be done by using the qLog(<category>) macro.

     //Make a log with your category (MAIN_LOG)
     qLog(MAIN_LOG) << "Execute Application.";

Member Function Documentation

void QLog::setConfigFile(const QString &path) [static]

Set the config file with the given format, scope organization and application name. If the config file doesn't exist it will be created.