The QLog class provides an easy to use logging mechanism. More...
#include <QLog>
| void | setConfigFile(const QString &path) |
The QLog class provides an easy to use logging mechanism.
QLog is designed to provide a very flexible logging mechanism in a very efficent way.
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.
As mentioned above a QLog configuration file is needed to control the behaviour or QLog. The configuration file contains following keys:
| Key | Value | Description |
|---|---|---|
| FunctionName | true/false | Writing out the name of the function for each log entry |
| LineNumber | true/false | Writing out the Line number where this log was made in each log entry |
| FileName | true/false | Writing out the file name where this log was made for each log entry |
| outputFile | file path | Output file for logging |
| category (e.g. MAIN_LOG) | true/false | Turns 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 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.";
Set the config file with the given format, scope organization and application name. If the config file doesn't exist it will be created.