123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142 |
- #ifndef QSLOG_H
- #define QSLOG_H
- #include "QsLogLevel.h"
- #include "QsLogDest.h"
- #include <QDebug>
- #include <QString>
- #include <QFileInfo>
- #define QS_LOG_VERSION "2.0b3"
- namespace QsLogging
- {
- class Destination;
- class LoggerImpl;
- typedef void (*ProcessingCallback)(QString& message);
- class QSLOG_SHARED_OBJECT Logger
- {
- public:
- static Logger& instance();
- static void destroyInstance();
- static Level levelFromLogMessage(const QString& logMessage, bool* conversionSucceeded = 0);
- ~Logger();
-
- void addDestination(DestinationPtr destination);
-
- void setLoggingLevel(Level newLevel);
-
- Level loggingLevel() const;
-
- void setProcessingCallback(ProcessingCallback cb);
-
-
- class QSLOG_SHARED_OBJECT Helper
- {
- public:
- explicit Helper(Level logLevel) :
- level(logLevel),
- qtDebug(&buffer) {}
- ~Helper();
- QDebug& stream(){ return qtDebug; }
- private:
- void writeToLog();
- Level level;
- QString buffer;
- QDebug qtDebug;
- };
- private:
- Logger();
- Logger(const Logger&);
- Logger& operator=(const Logger&);
- void enqueueWrite(QString message, Level level);
- void write(const QString& message, Level level);
- LoggerImpl* d;
- friend class LogWriterRunnable;
- };
- }
- #ifndef QS_LOG_LINE_NUMBERS
- #define QLOG_TRACE() \
- if (QsLogging::Logger::instance().loggingLevel() > QsLogging::TraceLevel) {} \
- else QsLogging::Logger::Helper(QsLogging::TraceLevel).stream()
- #define QLOG_DEBUG() \
- if (QsLogging::Logger::instance().loggingLevel() > QsLogging::DebugLevel) {} \
- else QsLogging::Logger::Helper(QsLogging::DebugLevel).stream()
- #define QLOG_INFO() \
- if (QsLogging::Logger::instance().loggingLevel() > QsLogging::InfoLevel) {} \
- else QsLogging::Logger::Helper(QsLogging::InfoLevel).stream()
- #define QLOG_WARN() \
- if (QsLogging::Logger::instance().loggingLevel() > QsLogging::WarnLevel) {} \
- else QsLogging::Logger::Helper(QsLogging::WarnLevel).stream()
- #define QLOG_ERROR() \
- if (QsLogging::Logger::instance().loggingLevel() > QsLogging::ErrorLevel) {} \
- else QsLogging::Logger::Helper(QsLogging::ErrorLevel).stream()
- #define QLOG_FATAL() \
- if (QsLogging::Logger::instance().loggingLevel() > QsLogging::FatalLevel) {} \
- else QsLogging::Logger::Helper(QsLogging::FatalLevel).stream()
- #else
- #define QLOG_TRACE() \
- if (QsLogging::Logger::instance().loggingLevel() > QsLogging::TraceLevel) {} \
- else QsLogging::Logger::Helper(QsLogging::TraceLevel).stream() << qPrintable(QFileInfo(__FILE__).fileName()) << '@' << __LINE__ << "-"
- #define QLOG_DEBUG() \
- if (QsLogging::Logger::instance().loggingLevel() > QsLogging::DebugLevel) {} \
- else QsLogging::Logger::Helper(QsLogging::DebugLevel).stream() << qPrintable(QFileInfo(__FILE__).fileName()) << '@' << __LINE__ << "-"
- #define QLOG_INFO() \
- if (QsLogging::Logger::instance().loggingLevel() > QsLogging::InfoLevel) {} \
- else QsLogging::Logger::Helper(QsLogging::InfoLevel).stream() << qPrintable(QFileInfo(__FILE__).fileName()) << '@' << __LINE__ << "-"
- #define QLOG_WARN() \
- if (QsLogging::Logger::instance().loggingLevel() > QsLogging::WarnLevel) {} \
- else QsLogging::Logger::Helper(QsLogging::WarnLevel).stream() << qPrintable(QFileInfo(__FILE__).fileName()) << '@' << __LINE__ << "-"
- #define QLOG_ERROR() \
- if (QsLogging::Logger::instance().loggingLevel() > QsLogging::ErrorLevel) {} \
- else QsLogging::Logger::Helper(QsLogging::ErrorLevel).stream() << qPrintable(QFileInfo(__FILE__).fileName()) << '@' << __LINE__ << "-"
- #define QLOG_FATAL() \
- if (QsLogging::Logger::instance().loggingLevel() > QsLogging::FatalLevel) {} \
- else QsLogging::Logger::Helper(QsLogging::FatalLevel).stream() << qPrintable(QFileInfo(__FILE__).fileName()) << '@' << __LINE__ << "-"
- #endif
- #ifdef QS_LOG_DISABLE
- #include "QsLogDisableForThisFile.h"
- #endif
- #endif
|