summaryrefslogtreecommitdiffstats
path: root/logger/QsLog.h
diff options
context:
space:
mode:
authorPetr Mrázek <peterix@gmail.com>2013-10-06 01:13:40 +0200
committerPetr Mrázek <peterix@gmail.com>2013-10-06 01:13:40 +0200
commitf83119ce7ec3d11a903901b8eff762d2b0a9f635 (patch)
tree5c30d7b9fff0f9417e7f2cd79d8ad9ea56d7f056 /logger/QsLog.h
parenteba9b3d759dbf6e402e91ab897059f1d274aef90 (diff)
downloadMultiMC-f83119ce7ec3d11a903901b8eff762d2b0a9f635.tar
MultiMC-f83119ce7ec3d11a903901b8eff762d2b0a9f635.tar.gz
MultiMC-f83119ce7ec3d11a903901b8eff762d2b0a9f635.tar.lz
MultiMC-f83119ce7ec3d11a903901b8eff762d2b0a9f635.tar.xz
MultiMC-f83119ce7ec3d11a903901b8eff762d2b0a9f635.zip
Added file logger
Diffstat (limited to 'logger/QsLog.h')
-rw-r--r--logger/QsLog.h130
1 files changed, 130 insertions, 0 deletions
diff --git a/logger/QsLog.h b/logger/QsLog.h
new file mode 100644
index 00000000..a18c08de
--- /dev/null
+++ b/logger/QsLog.h
@@ -0,0 +1,130 @@
+// Copyright (c) 2010, Razvan Petru
+// All rights reserved.
+
+// Redistribution and use in source and binary forms, with or without modification,
+// are permitted provided that the following conditions are met:
+
+// * Redistributions of source code must retain the above copyright notice, this
+// list of conditions and the following disclaimer.
+// * Redistributions in binary form must reproduce the above copyright notice, this
+// list of conditions and the following disclaimer in the documentation and/or other
+// materials provided with the distribution.
+// * The name of the contributors may not be used to endorse or promote products
+// derived from this software without specific prior written permission.
+
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+// ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+// IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
+// INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+// BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
+// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
+// OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
+// OF THE POSSIBILITY OF SUCH DAMAGE.
+
+#pragma once
+
+#include <QDebug>
+#include <QString>
+
+namespace QsLogging
+{
+class Destination;
+enum Level
+{
+ TraceLevel = 0,
+ DebugLevel,
+ InfoLevel,
+ WarnLevel,
+ ErrorLevel,
+ FatalLevel,
+ UnknownLevel
+};
+
+class LoggerImpl; // d pointer
+class Logger
+{
+public:
+ static Logger &instance()
+ {
+ static Logger staticLog;
+ return staticLog;
+ }
+
+ //! Adds a log message destination. Don't add null destinations.
+ void addDestination(Destination *destination);
+ //! Logging at a level < 'newLevel' will be ignored
+ void setLoggingLevel(Level newLevel);
+ //! The default level is INFO
+ Level loggingLevel() const;
+
+ //! The helper forwards the streaming to QDebug and builds the final
+ //! log message.
+ class Helper
+ {
+ public:
+ explicit Helper(Level logLevel);
+ ~Helper();
+ QDebug &stream()
+ {
+ return qtDebug;
+ }
+
+ private:
+ void writeToLog();
+
+ Level level;
+ QString buffer;
+ QDebug qtDebug;
+ };
+
+private:
+ Logger();
+ Logger(const Logger &);
+ Logger &operator=(const Logger &);
+ ~Logger();
+
+ void write(const QString &message);
+
+ LoggerImpl *d;
+};
+
+} // end namespace
+
+#define QLOG_TRACE() \
+ if (QsLogging::Logger::instance().loggingLevel() <= QsLogging::TraceLevel) \
+ QsLogging::Logger::Helper(QsLogging::TraceLevel).stream()
+#define QLOG_DEBUG() \
+ if (QsLogging::Logger::instance().loggingLevel() <= QsLogging::DebugLevel) \
+ QsLogging::Logger::Helper(QsLogging::DebugLevel).stream()
+#define QLOG_INFO() \
+ if (QsLogging::Logger::instance().loggingLevel() <= QsLogging::InfoLevel) \
+ QsLogging::Logger::Helper(QsLogging::InfoLevel).stream()
+#define QLOG_WARN() \
+ if (QsLogging::Logger::instance().loggingLevel() <= QsLogging::WarnLevel) \
+ QsLogging::Logger::Helper(QsLogging::WarnLevel).stream()
+#define QLOG_ERROR() \
+ if (QsLogging::Logger::instance().loggingLevel() <= QsLogging::ErrorLevel) \
+ QsLogging::Logger::Helper(QsLogging::ErrorLevel).stream()
+#define QLOG_FATAL() QsLogging::Logger::Helper(QsLogging::FatalLevel).stream()
+
+/*
+#define QLOG_TRACE() \
+ if (QsLogging::Logger::instance().loggingLevel() <= QsLogging::TraceLevel) \
+ QsLogging::Logger::Helper(QsLogging::TraceLevel).stream() << __FILE__ << '@' << __LINE__
+#define QLOG_DEBUG() \
+ if (QsLogging::Logger::instance().loggingLevel() <= QsLogging::DebugLevel) \
+ QsLogging::Logger::Helper(QsLogging::DebugLevel).stream() << __FILE__ << '@' << __LINE__
+#define QLOG_INFO() \
+ if (QsLogging::Logger::instance().loggingLevel() <= QsLogging::InfoLevel) \
+ QsLogging::Logger::Helper(QsLogging::InfoLevel).stream() << __FILE__ << '@' << __LINE__
+#define QLOG_WARN() \
+ if (QsLogging::Logger::instance().loggingLevel() <= QsLogging::WarnLevel) \
+ QsLogging::Logger::Helper(QsLogging::WarnLevel).stream() << __FILE__ << '@' << __LINE__
+#define QLOG_ERROR() \
+ if (QsLogging::Logger::instance().loggingLevel() <= QsLogging::ErrorLevel) \
+ QsLogging::Logger::Helper(QsLogging::ErrorLevel).stream() << __FILE__ << '@' << __LINE__
+#define QLOG_FATAL() \
+ QsLogging::Logger::Helper(QsLogging::FatalLevel).stream() << __FILE__ << '@' << __LINE__
+*/ \ No newline at end of file