summaryrefslogtreecommitdiffstats
path: root/doc/src/index.qdoc
blob: 21313a38ed4514c00585c9578cc29a4e6e51b83c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
/****************************************************************************
**
** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
** Contact: http://www.qt-project.org/legal
**
** This file is part of the documentation of QtLogger
**
** $QT_BEGIN_LICENSE:FDL$
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and Digia.  For licensing terms and
** conditions see http://qt.digia.com/licensing.  For further information
** use the contact form at http://qt.digia.com/contact-us.
**
** GNU Free Documentation License Usage
** Alternatively, this file may be used under the terms of the GNU Free
** Documentation License version 1.3 as published by the Free Software
** Foundation and appearing in the file included in the packaging of
** this file.  Please review the following information to ensure
** the GNU Free Documentation License version 1.3 requirements
** will be met: http://www.gnu.org/copyleft/fdl.html.
** $QT_END_LICENSE$
**
****************************************************************************/

/*!
    \page index.html
    \title QLogger Reference
    \brief The Qt Logging API provides the application developer a categorized logging mechanism.

    \section1 Introduction

    The Qt Logging API provides the application developer a categorized logging mechanism.


    \section1 Overview

    The logging is designed to provide a flexible logging mechanism in an efficent manner.


    \section1 Features


    1. Enable or disable logging without recompiling your project.

    Logging can be activated by providing a logging rules file or providing a QByteArray that contains the
    \l {logging_rules} {rules}.


    2. Logging with categories

    Developer can create their own logging categories.

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

    Each category contains a subset of "debug", "warning" and "critical" subcategories.

    In the initialization logging will be performed for all "warning" and "critical" subcategories.

    See \l {Default settings} .


    \section1 How to Use

    \section2 Add QLogger to Your Project

    First you need to add the QLogger library dependency to your application:

    QT += logger

    In your application you need to include the QLogger header:

    #include <qlogger.h>

    Note: The current implementation re-defines qDebug, qWarning and qCritical by this header.


    \section2 Creating Logging Rules
    \target logging_rules

    As mentioned above logging rules are needed to control the behavior of the logging.

    The logging rules containing basically the categories and a true/false value for each category:


    Here is an example of some logging rules:


    \table
    \header
    \row    \li Nokia.driver.usb.debug = true
    \row    \li Nokia.driver.usb.warning = true
    \row    \li Nokia.driver.event = false
    \endtable

    Of course you could write Nokia.driver.usb = true, this will enable all subcategories (debug, warning and critical).

    Vice versa with Nokia.driver.usb = false.

    Wildcard (*) category definitions are possible as well.

    The order of the categories in your configuration is important. From top to bottom the category priority is low to high.

    e.g:

    \table
    \header
    \row    \li Nokia*=false
    \row    \li *Nokia=true
    \row    \li *Nokia*=true
    \endtable

    In this example all categories containing the word Nokia will be logged.

    Willdcard "*" can only apply to the beginning or/and to the end of your configuration category entry.

    The usage of qDebug(), qWarning() and qCrititcal results in the category "default".

    e.g.

    \table
    \header \li Macro     \li category
    \row    \li qDebug    \li "default.debug"
    \row    \li qWarning  \li "default.warning"
    \row    \li qCritical \li "default.critical"
    \endtable


    \section2 Create your Category Logging Object in your Project

    There are two different ways to create your own category object.


    1. Qt provides the \l QT_LOG_CATEGORY() macro to create your logging Categories:

    \snippet logger/main.cpp 1

    2. You can create your own \l QLoggingCategory object:

    \snippet logger/main.cpp 4


    \section2 Activate Logging Rules

    There are 3 three different way to activate the logging rules:

    \table
    \header
    \row \li 1. \li The application developer can set the rule file by using \l qSetLoggingRulesFile()
                \snippet logger/main.cpp 2

    \row \li 2. \li The application developer can set the rules directly using \l qSetLoggingRules().
                \snippet logger/main.cpp 5

    \row \li 3. \li The logging rule file can be defined by using the environment variable called \section2 QT_LOGGING_CONFIG

       The QT_LOGGING_CONFIG environment variable overrides both qSetLoggingRulesFile() and

       qSetLoggingRules() if it points to a file.

       If QT_LOGGING_CONFIG is relative, QStandardPaths::writeableLocation(QStandardPaths::ConfigLocation) will be prepended.
    \endtable

    If there is no loggin rules available, the \l {Default settings} will be used.

    In this example a logging category NOKIA_DRIVER_USB with a category string of "Nokia.driver.usb"

    and NOKIA_DRIVER_EVENT with a category string of "Nokia.driver.event" is created.

    In you configuration file you could write:

    \table
    \header
    \row    \li Nokia.driver.usb = true
    \row    \li Nokia.driver.event = true
    \row    \li or even: Nokia.driver.* = true
    \endtable


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

    For category-based logging statements, you need to use the \l qCDebug(), \l qCWarning() and \l qCCritical() macros.

    \snippet logger/main.cpp 3


    \section1 Default settings

    The defaults are as follows.

    \table
    \header \li Statement \li Default
    \row \li qDebug \li Enabled
    \row \li qWarning \li Enabled
    \row \li qCritical \li Enabled
    \row \li qCDebug \li Disabled
    \row \li qCWarning \li Enabled
    \row \li qCCritical \li Enabled
    \endtable

    In other words, only \l qCDebug() statements are hidden by default.

    \section1 Classes

    \annotatedlist qlogging_classes
*/