#include <QtCore/QObject>#include <QtCore/QAtomicPointer>#include <QtCore/QList>#include <QtCore/QReadWriteLock>#include "log4qt/helpers/logerror.h"#include "log4qt/helpers/classlogger.h"#include "log4qt/helpers/logobjectptr.h"#include "log4qt/level.h"Go to the source code of this file.
Namespaces | |
| namespace | Log4Qt |
Classes | |
| class | Log4Qt::Logger |
| The class Logger provides logging services. More... | |
Defines | |
| #define | LOG4QT_DECLARE_STATIC_LOGGER(FUNCTION, CLASS) |
| #define | LOG4QT_DECLARE_QCLASS_LOGGER |
| #define LOG4QT_DECLARE_QCLASS_LOGGER |
Value:
private: \ mutable Log4Qt::ClassLogger mLog4QtClassLogger; \ public: \ inline Log4Qt::Logger *logger() const \ { return mLog4QtClassLogger.logger(this); } \ private:
On the first invocation the Logger is requested by a call to Logger::logger(const char *pName). The pointer is stored to be returned on subsequent invocations.
The following example shows how to use the macro to define a logger to be used within a class derived from QObject.
#file: counter.h #include qobject.h #include logger.h class Counter : public QObject { Q_OBJECT LOG4QT_DECLARE_QCLASS_LOGGER public: Counter(); Counter(int preset); private: int mCount; }
#file: counter.cpp #include counter.h Counter::Counter() : mCount(0) {} void Counter::Counter(int preset) mCount(preset) { if (preset < 0) { logger()->warn("Invalid negative counter preset %1. Using 0 instead.", preset); mCount = 0; } }
| #define LOG4QT_DECLARE_STATIC_LOGGER | ( | FUNCTION, | |||
| CLASS | ) |
Value:
static Log4Qt::Logger *FUNCTION() \ { \ static QBasicAtomicPointer<Log4Qt::Logger > p_logger = \ Q_BASIC_ATOMIC_INITIALIZER(0); \ if (!p_logger) \ { \ p_logger.testAndSetOrdered(0, \ Log4Qt::Logger::logger( #CLASS )); \ } \ return p_logger; \ }
On the first invocation the Logger is requested by calling Logger::logger( #CLASS ). The pointer is stored to be returned on subsequent invocations.
The following example shows how to use the macro to define a logger to be used within a class not derived from QObject.
#file: counter.h #include logger.h class Counter { public: Counter(); Counter(int preset); private: int mCount; }
#file: counter.cpp #include counter.h LOG4QT_DECLARE_STATIC_LOGGER(logger, Counter) Counter::Counter() : mCount(0) {} void Counter::Counter(int preset) : mCount(preset) { if (preset < 0) { logger()->warn("Invalid negative counter preset %1. Using 0 instead.", preset); mCount = 0; } }
1.5.6