diff options
Diffstat (limited to 'src/logger/qlogger.h')
-rw-r--r-- | src/logger/qlogger.h | 117 |
1 files changed, 117 insertions, 0 deletions
diff --git a/src/logger/qlogger.h b/src/logger/qlogger.h new file mode 100644 index 0000000..24943b2 --- /dev/null +++ b/src/logger/qlogger.h @@ -0,0 +1,117 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/ +** +** This file is part of the logger module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** GNU Lesser General Public License Usage +** This file may be used under the terms of the GNU Lesser General Public +** License version 2.1 as published by the Free Software Foundation and +** appearing in the file LICENSE.LGPL included in the packaging of this +** file. Please review the following information to ensure the GNU Lesser +** General Public License version 2.1 requirements will be met: +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU General +** Public License version 3.0 as published by the Free Software Foundation +** and appearing in the file LICENSE.GPL included in the packaging of this +** file. Please review the following information to ensure the GNU General +** Public License version 3.0 requirements will be met: +** http://www.gnu.org/copyleft/gpl.html. +** +** Other Usage +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QLOGGER_H +#define QLOGGER_H + +#include <QObject> +#include <QtLogger/qloggerglobal.h> + +QT_BEGIN_HEADER +QT_LOGGER_BEGIN_NAMESPACE + +namespace QLoggingCategories { + class Q_LOGGER_EXPORT QLoggingCategory { + public: + QLoggingCategory(const char *cat); + bool statusMessageType(const QtMsgType &type); + void setStatusMessageType(const QtMsgType &type, bool status); + bool _enabledDebug; + bool _enabledWarning; + bool _enabledCritical; + bool _registered; + const char *_category; + }; + Q_LOGGER_EXPORT QLoggingCategory& defaultCategory(); + Q_LOGGER_EXPORT bool isEnabled(QLoggingCategory &category, QtMsgType type); + Q_LOGGER_EXPORT bool isEnabled(); +} + +Q_LOGGER_EXPORT void qSetLoggingRules(const QByteArray &rules); +Q_LOGGER_EXPORT void qSetLoggingRulesFile(const QString &path); + +QT_END_HEADER +QT_LOGGER_END_NAMESPACE + +QT_LOGGER_USE_NAMESPACE + +#if defined(qDebug) +# undef qDebug +#endif + +#define qDebug if (QLoggingCategories::isEnabled() && !QLoggingCategories::isEnabled(QLoggingCategories::defaultCategory(), QtDebugMsg)) /*NOP*/; \ + else QMessageLogger(__FILE__, __LINE__, Q_FUNC_INFO).debug + +#if defined(qWarning) +# undef qWarning +#endif + +#define qWarning if (QLoggingCategories::isEnabled() && !QLoggingCategories::isEnabled(QLoggingCategories::defaultCategory(), QtWarningMsg)) /*NOP*/; \ + else QMessageLogger(__FILE__, __LINE__, Q_FUNC_INFO).warning + +#if defined(qCritical) +# undef qCritical +#endif + +#define qCritical if (QLoggingCategories::isEnabled() && !QLoggingCategories::isEnabled(QLoggingCategories::defaultCategory(), QtCriticalMsg)) /*NOP*/;\ + else QMessageLogger(__FILE__, __LINE__, Q_FUNC_INFO).critical + +#define QT_LOG_CATEGORY(categorytype, category) \ + namespace QtLogger { \ + namespace QLoggingCategories \ + { \ + static QLoggingCategory categorytype##_QLoggingCategory(category); \ + } \ + } + +#define qCDebug(category) \ + if (!QLoggingCategories::isEnabled() || !QLoggingCategories::isEnabled(QLoggingCategories::category##_QLoggingCategory, QtDebugMsg)) /*NOP*/; \ + else QMessageLogger(__FILE__, __LINE__, Q_FUNC_INFO).debug() << QLoggingCategories::category##_QLoggingCategory._category << ": " \ + +#define qCWarning(category) \ + if (QLoggingCategories::isEnabled() && !QLoggingCategories::isEnabled(QLoggingCategories::category##_QLoggingCategory, QtWarningMsg)) /*NOP*/; \ + else QMessageLogger(__FILE__, __LINE__, Q_FUNC_INFO).warning() << QLoggingCategories::category##_QLoggingCategory._category << ": " \ + +#define qCCritical(category) \ + if (QLoggingCategories::isEnabled() && !QLoggingCategories::isEnabled(QLoggingCategories::category##_QLoggingCategory, QtCriticalMsg)) /*NOP*/; \ + else QMessageLogger(__FILE__, __LINE__, Q_FUNC_INFO).critical() << QLoggingCategories::category##_QLoggingCategory._category << ": " \ + +#endif // QLOGGER_H |