00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 #ifndef LOG4QT_LOG4QTEVENT_H
00026 #define LOG4QT_LOG4QTEVENT_H
00027
00028
00029
00030
00031
00032
00033 #include <QtCore/QDateTime>
00034 #include <QtCore/QHash>
00035 #include <QtCore/QMetaType>
00036 #include <QtCore/QStringList>
00037 #include "log4qt/level.h"
00038
00039
00040
00041
00042
00043
00044 namespace Log4Qt
00045 {
00046
00047 class Logger;
00048
00057 class LoggingEvent
00058 {
00059 public:
00060 LoggingEvent();
00061 LoggingEvent(const Logger *pLogger,
00062 Level level,
00063 const QString &rMessage);
00064 LoggingEvent(const Logger *pLogger,
00065 Level level,
00066 const QString &rMessage,
00067 qint64 timeStamp);
00068 LoggingEvent(const Logger *pLogger,
00069 Level level,
00070 const QString &rMessage,
00071 const QString &rNdc,
00072 const QHash<QString, QString> &rProperties,
00073 const QString &rThreadName,
00074 qint64 timeStamp);
00075
00076
00077
00078
00079
00080 Level level() const;
00081
00082 const Logger *logger() const;
00083 QString message() const;
00084 QHash<QString, QString> mdc() const;
00085 QString ndc() const;
00086 QHash<QString, QString> properties() const;
00087 qint64 sequenceNumber() const;
00088 QString threadName() const;
00089
00090 qint64 timeStamp() const;
00091
00092
00093 QString loggerName() const;
00094 QString property(const QString &rKey) const;
00095 QStringList propertyKeys() const;
00096 void setProperty(const QString &rKey, const QString &rValue);
00097
00098 QString toString() const;
00099 static qint64 sequenceCount();
00100 static qint64 startTime();
00101
00102 private:
00103 void setThreadNameToCurrent();
00104 static qint64 nextSequenceNumber();
00105
00106 private:
00107 Level mLevel;
00108 const Logger *mpLogger;
00109 QString mMessage;
00110 QString mNdc;
00111 QHash<QString, QString> mProperties;
00112 qint64 mSequenceNumber;
00113 QString mThreadName;
00114 qint64 mTimeStamp;
00115 static qint64 msSequenceCount;
00116
00117 #ifndef QT_NO_DATASTREAM
00118
00119 friend QDataStream &operator<<(QDataStream &rStream,
00120 const LoggingEvent &rLoggingEvent);
00121 friend QDataStream &operator>>(QDataStream &rStream,
00122 LoggingEvent &rLoggingEvent);
00123 #endif // QT_NO_DATASTREAM
00124 };
00125
00126
00127
00128
00129
00130
00131 #ifndef QT_NO_DATASTREAM
00132
00138 QDataStream &operator<<(QDataStream &rStream,
00139 const LoggingEvent &rLoggingEvent);
00140
00147 QDataStream &operator>>(QDataStream &rStream,
00148 LoggingEvent &rLoggingEvent);
00149 #endif // QT_NO_DATASTREAM
00150
00151 #ifndef QT_NO_DEBUG_STREAM
00152
00168 QDebug operator<<(QDebug debug,
00169 const LoggingEvent &rLoggingEvent);
00170 #endif // QT_NO_DEBUG_STREAM
00171
00172
00173
00174
00175
00176
00177 inline Level LoggingEvent::level() const
00178 { return mLevel; }
00179
00180 inline const Logger *LoggingEvent::logger() const
00181 { return mpLogger; }
00182
00183 inline QString LoggingEvent::message() const
00184 { return mMessage; }
00185
00186 inline QHash<QString, QString> LoggingEvent::mdc() const
00187 { return mProperties; }
00188
00189 inline QString LoggingEvent::ndc() const
00190 { return mNdc; }
00191
00192 inline QHash<QString, QString> LoggingEvent::properties() const
00193 { return mProperties; }
00194
00195 inline qint64 LoggingEvent::sequenceNumber() const
00196 { return mSequenceNumber; }
00197
00198 inline QString LoggingEvent::threadName() const
00199 { return mThreadName; }
00200
00201 inline qint64 LoggingEvent::timeStamp() const
00202 { return mTimeStamp; }
00203
00204 inline QString LoggingEvent::property(const QString &rKey) const
00205 { return mProperties.value(rKey); }
00206
00207 inline QStringList LoggingEvent::propertyKeys() const
00208 { return QStringList(mProperties.keys()); }
00209
00210 inline void LoggingEvent::setProperty(const QString &rKey, const QString &rValue)
00211 { mProperties.insert(rKey, rValue); }
00212
00213
00214 }
00215
00216
00217 Q_DECLARE_METATYPE(Log4Qt::LoggingEvent)
00218 Q_DECLARE_TYPEINFO(Log4Qt::LoggingEvent, Q_MOVABLE_TYPE);
00219
00220
00221 #endif // LOG4QT_LOG4QTEVENT_H