diff --git a/中电项目/QsLog-master/.gitignore b/中电项目/QsLog-master/.gitignore new file mode 100644 index 0000000..6fdeb0e --- /dev/null +++ b/中电项目/QsLog-master/.gitignore @@ -0,0 +1,2 @@ +*.pro.user +build-* diff --git a/中电项目/QsLog-master/LICENSE.txt b/中电项目/QsLog-master/LICENSE.txt new file mode 100644 index 0000000..af90342 --- /dev/null +++ b/中电项目/QsLog-master/LICENSE.txt @@ -0,0 +1,24 @@ +Copyright (c) 2014, 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. diff --git a/中电项目/QsLog-master/QsLog.cpp b/中电项目/QsLog-master/QsLog.cpp new file mode 100644 index 0000000..d96ba72 --- /dev/null +++ b/中电项目/QsLog-master/QsLog.cpp @@ -0,0 +1,278 @@ +// Copyright (c) 2013, 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. + +#include "QsLog.h" +#include "QsLogDest.h" +#ifdef QS_LOG_SEPARATE_THREAD +#include +#include +#endif +#include +#include +#include +#include +#include +#include + +namespace QsLogging +{ +typedef QVector DestinationList; + +static const char TraceString[] = "TRACE"; +static const char DebugString[] = "DEBUG"; +static const char InfoString[] = "INFO "; +static const char WarnString[] = "WARN "; +static const char ErrorString[] = "ERROR"; +static const char FatalString[] = "FATAL"; + +// not using Qt::ISODate because we need the milliseconds too +static const QString fmtDateTime("yyyy-MM-ddThh:mm:ss.zzz"); + +static Logger* sInstance = 0; + +static const char* LevelToText(Level theLevel) +{ + switch (theLevel) { + case TraceLevel: + return TraceString; + case DebugLevel: + return DebugString; + case InfoLevel: + return InfoString; + case WarnLevel: + return WarnString; + case ErrorLevel: + return ErrorString; + case FatalLevel: + return FatalString; + case OffLevel: + return ""; + default: { + Q_ASSERT(!"bad log level"); + return InfoString; + } + } +} + +#ifdef QS_LOG_SEPARATE_THREAD +class LogWriterRunnable : public QRunnable +{ +public: + LogWriterRunnable(QString message, Level level); + virtual void run(); + +private: + QString mMessage; + Level mLevel; +}; +#endif + +class LoggerImpl +{ +public: + LoggerImpl(); + +#ifdef QS_LOG_SEPARATE_THREAD + QThreadPool threadPool; +#endif + QMutex logMutex; + Level level; + DestinationList destList; + bool includeTimeStamp; + bool includeLogLevel; +}; + +#ifdef QS_LOG_SEPARATE_THREAD +LogWriterRunnable::LogWriterRunnable(QString message, Level level) + : QRunnable() + , mMessage(message) + , mLevel(level) +{ +} + +void LogWriterRunnable::run() +{ + Logger::instance().write(mMessage, mLevel); +} +#endif + + +LoggerImpl::LoggerImpl() + : level(InfoLevel) + , includeTimeStamp(true) + , includeLogLevel(true) +{ + // assume at least file + console + destList.reserve(2); +#ifdef QS_LOG_SEPARATE_THREAD + threadPool.setMaxThreadCount(1); + threadPool.setExpiryTimeout(-1); +#endif +} + + +Logger::Logger() + : d(new LoggerImpl) +{ +} + +Logger& Logger::instance() +{ + if (!sInstance) + sInstance = new Logger; + + return *sInstance; +} + +void Logger::destroyInstance() +{ + delete sInstance; + sInstance = 0; +} + +// tries to extract the level from a string log message. If available, conversionSucceeded will +// contain the conversion result. +Level Logger::levelFromLogMessage(const QString& logMessage, bool* conversionSucceeded) +{ + if (conversionSucceeded) + *conversionSucceeded = true; + + if (logMessage.startsWith(QLatin1String(TraceString))) + return TraceLevel; + if (logMessage.startsWith(QLatin1String(DebugString))) + return DebugLevel; + if (logMessage.startsWith(QLatin1String(InfoString))) + return InfoLevel; + if (logMessage.startsWith(QLatin1String(WarnString))) + return WarnLevel; + if (logMessage.startsWith(QLatin1String(ErrorString))) + return ErrorLevel; + if (logMessage.startsWith(QLatin1String(FatalString))) + return FatalLevel; + + if (conversionSucceeded) + *conversionSucceeded = false; + return OffLevel; +} + +Logger::~Logger() +{ +#ifdef QS_LOG_SEPARATE_THREAD + d->threadPool.waitForDone(); +#endif + delete d; + d = 0; +} + +void Logger::addDestination(DestinationPtr destination) +{ + Q_ASSERT(destination.data()); + d->destList.push_back(destination); +} + +void Logger::setLoggingLevel(Level newLevel) +{ + d->level = newLevel; +} + +Level Logger::loggingLevel() const +{ + return d->level; +} + +void Logger::setIncludeTimestamp(bool e) +{ + d->includeTimeStamp = e; +} + +bool Logger::includeTimestamp() const +{ + return d->includeTimeStamp; +} + +void Logger::setIncludeLogLevel(bool l) +{ + d->includeLogLevel = l; +} + +bool Logger::includeLogLevel() const +{ + return d->includeLogLevel; +} + +//! creates the complete log message and passes it to the logger +void Logger::Helper::writeToLog() +{ + const char* const levelName = LevelToText(level); + QString completeMessage; + Logger &logger = Logger::instance(); + if (logger.includeLogLevel()) { + completeMessage. + append(levelName). + append(' '); + } + if (logger.includeTimestamp()) { + completeMessage. + append(QDateTime::currentDateTime().toString(fmtDateTime)). + append(' '); + } + completeMessage.append(buffer); + Logger::instance().enqueueWrite(completeMessage, level); +} + +Logger::Helper::~Helper() +{ + try { + writeToLog(); + } + catch(std::exception&) { + // you shouldn't throw exceptions from a sink + Q_ASSERT(!"exception in logger helper destructor"); + } +} + +//! directs the message to the task queue or writes it directly +void Logger::enqueueWrite(const QString& message, Level level) +{ +#ifdef QS_LOG_SEPARATE_THREAD + LogWriterRunnable *r = new LogWriterRunnable(message, level); + d->threadPool.start(r); +#else + write(message, level); +#endif +} + +//! Sends the message to all the destinations. The level for this message is passed in case +//! it's useful for processing in the destination. +void Logger::write(const QString& message, Level level) +{ + QMutexLocker lock(&d->logMutex); + for (DestinationList::iterator it = d->destList.begin(), + endIt = d->destList.end();it != endIt;++it) { + (*it)->write(message, level); + } +} + +} // end namespace diff --git a/中电项目/QsLog-master/QsLog.h b/中电项目/QsLog-master/QsLog.h new file mode 100644 index 0000000..c1beae2 --- /dev/null +++ b/中电项目/QsLog-master/QsLog.h @@ -0,0 +1,146 @@ +// Copyright (c) 2013, 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. + +#ifndef QSLOG_H +#define QSLOG_H + +#include "QsLogLevel.h" +#include "QsLogDest.h" +#include +#include + +#define QS_LOG_VERSION "2.0b3" + +namespace QsLogging +{ +class Destination; +class LoggerImpl; // d pointer + +class QSLOG_SHARED_OBJECT Logger +{ +public: + static Logger& instance(); + static void destroyInstance(); + static Level levelFromLogMessage(const QString& logMessage, bool* conversionSucceeded = 0); + + ~Logger(); + + //! Adds a log message destination. Don't add null destinations. + void addDestination(DestinationPtr destination); + //! Logging at a level < 'newLevel' will be ignored + void setLoggingLevel(Level newLevel); + //! The default level is INFO + Level loggingLevel() const; + //! Set to false to disable timestamp inclusion in log messages + void setIncludeTimestamp(bool e); + //! Default value is true. + bool includeTimestamp() const; + //! Set to false to disable log level inclusion in log messages + void setIncludeLogLevel(bool l); + //! Default value is true. + bool includeLogLevel() const; + + //! The helper forwards the streaming to QDebug and builds the final + //! log message. + 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&); // not available + Logger& operator=(const Logger&); // not available + + void enqueueWrite(const QString& message, Level level); + void write(const QString& message, Level level); + + LoggerImpl* d; + + friend class LogWriterRunnable; +}; + +} // end namespace + +//! Logging macros: define QS_LOG_LINE_NUMBERS to get the file and line number +//! in the log output. +#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() << __FILE__ << '@' << __LINE__ +#define QLOG_DEBUG() \ + if (QsLogging::Logger::instance().loggingLevel() > QsLogging::DebugLevel) {} \ + else QsLogging::Logger::Helper(QsLogging::DebugLevel).stream() << __FILE__ << '@' << __LINE__ +#define QLOG_INFO() \ + if (QsLogging::Logger::instance().loggingLevel() > QsLogging::InfoLevel) {} \ + else QsLogging::Logger::Helper(QsLogging::InfoLevel).stream() << __FILE__ << '@' << __LINE__ +#define QLOG_WARN() \ + if (QsLogging::Logger::instance().loggingLevel() > QsLogging::WarnLevel) {} \ + else QsLogging::Logger::Helper(QsLogging::WarnLevel).stream() << __FILE__ << '@' << __LINE__ +#define QLOG_ERROR() \ + if (QsLogging::Logger::instance().loggingLevel() > QsLogging::ErrorLevel) {} \ + else QsLogging::Logger::Helper(QsLogging::ErrorLevel).stream() << __FILE__ << '@' << __LINE__ +#define QLOG_FATAL() \ + if (QsLogging::Logger::instance().loggingLevel() > QsLogging::FatalLevel) {} \ + else QsLogging::Logger::Helper(QsLogging::FatalLevel).stream() << __FILE__ << '@' << __LINE__ +#endif + +#ifdef QS_LOG_DISABLE +#include "QsLogDisableForThisFile.h" +#endif + +#endif // QSLOG_H diff --git a/中电项目/QsLog-master/QsLog.pri b/中电项目/QsLog-master/QsLog.pri new file mode 100644 index 0000000..0dc60db --- /dev/null +++ b/中电项目/QsLog-master/QsLog.pri @@ -0,0 +1,22 @@ +INCLUDEPATH += $$PWD +#DEFINES += QS_LOG_LINE_NUMBERS # automatically writes the file and line for each log message +#DEFINES += QS_LOG_DISABLE # logging code is replaced with a no-op +#DEFINES += QS_LOG_SEPARATE_THREAD # messages are queued and written from a separate thread +SOURCES += $$PWD/QsLogDest.cpp \ + $$PWD/QsLog.cpp \ + $$PWD/QsLogDestConsole.cpp \ + $$PWD/QsLogDestFile.cpp \ + $$PWD/QsLogDestFunctor.cpp + +HEADERS += $$PWD/QsLogDest.h \ + $$PWD/QsLog.h \ + $$PWD/QsLogDestConsole.h \ + $$PWD/QsLogLevel.h \ + $$PWD/QsLogDestFile.h \ + $$PWD/QsLogDisableForThisFile.h \ + $$PWD/QsLogDestFunctor.h + +OTHER_FILES += \ + $$PWD/QsLogChanges.txt \ + $$PWD/QsLogReadme.txt \ + $$PWD/LICENSE.txt diff --git a/中电项目/QsLog-master/QsLogChanges.txt b/中电项目/QsLog-master/QsLogChanges.txt new file mode 100644 index 0000000..75d7a3d --- /dev/null +++ b/中电项目/QsLog-master/QsLogChanges.txt @@ -0,0 +1,45 @@ +------------------- +QsLog version 2.0b4 +Fixes: +Fixed file name case error for Linux. + +Misc: +* Moved to separate git repository. + +------------------- +QsLog version 2.0b3 + +Changes: +* added functor logging destination (thanks to Omar Carey for providing a patch) + +------------------- +QsLog version 2.0b2 + +Changes: +* function signature redefinition for file destination creation +* added shared library build configuration. Credit goes to Xavier Lamien +for the Linux-specific config. +* removed Symbian support +* this version does not guarantee support for Nokia N9 devices, although it should in theory still +work with them +* workaround for Issue 8 - when used from an executable and a plugin QsLog only logs from the +executable. +* utility function to parse the level from an existing log message + +Known issues: +* The current version will crash at program exit when using QS_LOG_SEPARATE_THREAD and linking +with QsLog dynamically. + +------------------- +QsLog version 2.0b1 + +Changes: +* destination pointers use shared pointer semantics +* the file destination supports log rotation. As a consequence, log files are encoded as UTF-8 and +the log appends rather than truncating on every startup when rotation is enabled. +* added the posibility of disabling logging either at run time or compile time. +* added the possibility of using a separate thread for writing to the log destinations. + +Fixes: +* renamed the main.cpp example to avoid QtCreator confusion +* offer a way to check if the destination creation has failed (for e.g files) diff --git a/中电项目/QsLog-master/QsLogDest.cpp b/中电项目/QsLog-master/QsLogDest.cpp new file mode 100644 index 0000000..ff38807 --- /dev/null +++ b/中电项目/QsLog-master/QsLogDest.cpp @@ -0,0 +1,70 @@ +// Copyright (c) 2013, 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. + +#include "QsLogDest.h" +#include "QsLogDestConsole.h" +#include "QsLogDestFile.h" +#include "QsLogDestFunctor.h" +#include + +namespace QsLogging +{ + +Destination::~Destination() +{ +} + +//! destination factory +DestinationPtr DestinationFactory::MakeFileDestination(const QString& filePath, + LogRotationOption rotation, const MaxSizeBytes &sizeInBytesToRotateAfter, + const MaxOldLogCount &oldLogsToKeep) +{ + if (EnableLogRotation == rotation) { + QScopedPointer logRotation(new SizeRotationStrategy); + logRotation->setMaximumSizeInBytes(sizeInBytesToRotateAfter.size); + logRotation->setBackupCount(oldLogsToKeep.count); + + return DestinationPtr(new FileDestination(filePath, RotationStrategyPtr(logRotation.take()))); + } + + return DestinationPtr(new FileDestination(filePath, RotationStrategyPtr(new NullRotationStrategy))); +} + +DestinationPtr DestinationFactory::MakeDebugOutputDestination() +{ + return DestinationPtr(new DebugOutputDestination); +} + +DestinationPtr DestinationFactory::MakeFunctorDestination(QsLogging::Destination::LogFunction f) +{ + return DestinationPtr(new FunctorDestination(f)); +} + +DestinationPtr DestinationFactory::MakeFunctorDestination(QObject *receiver, const char *member) +{ + return DestinationPtr(new FunctorDestination(receiver, member)); +} + +} // end namespace diff --git a/中电项目/QsLog-master/QsLogDest.h b/中电项目/QsLog-master/QsLogDest.h new file mode 100644 index 0000000..4ed6157 --- /dev/null +++ b/中电项目/QsLog-master/QsLogDest.h @@ -0,0 +1,99 @@ +// Copyright (c) 2013, 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. + +#ifndef QSLOGDEST_H +#define QSLOGDEST_H + +#include "QsLogLevel.h" +#include +#include +class QString; +class QObject; + +#ifdef QSLOG_IS_SHARED_LIBRARY +#define QSLOG_SHARED_OBJECT Q_DECL_EXPORT +#elif QSLOG_IS_SHARED_LIBRARY_IMPORT +#define QSLOG_SHARED_OBJECT Q_DECL_IMPORT +#else +#define QSLOG_SHARED_OBJECT +#endif + +namespace QsLogging +{ + +class QSLOG_SHARED_OBJECT Destination +{ +public: + typedef void (*LogFunction)(const QString &message, Level level); + +public: + virtual ~Destination(); + virtual void write(const QString& message, Level level) = 0; + virtual bool isValid() = 0; // returns whether the destination was created correctly +}; +typedef QSharedPointer DestinationPtr; + + +// a series of "named" paramaters, to make the file destination creation more readable +enum LogRotationOption +{ + DisableLogRotation = 0, + EnableLogRotation = 1 +}; + +struct QSLOG_SHARED_OBJECT MaxSizeBytes +{ + MaxSizeBytes() : size(0) {} + explicit MaxSizeBytes(qint64 size_) : size(size_) {} + qint64 size; +}; + +struct QSLOG_SHARED_OBJECT MaxOldLogCount +{ + MaxOldLogCount() : count(0) {} + explicit MaxOldLogCount(int count_) : count(count_) {} + int count; +}; + + +//! Creates logging destinations/sinks. The caller shares ownership of the destinations with the logger. +//! After being added to a logger, the caller can discard the pointers. +class QSLOG_SHARED_OBJECT DestinationFactory +{ +public: + static DestinationPtr MakeFileDestination(const QString& filePath, + LogRotationOption rotation = DisableLogRotation, + const MaxSizeBytes &sizeInBytesToRotateAfter = MaxSizeBytes(), + const MaxOldLogCount &oldLogsToKeep = MaxOldLogCount()); + static DestinationPtr MakeDebugOutputDestination(); + // takes a pointer to a function + static DestinationPtr MakeFunctorDestination(Destination::LogFunction f); + // takes a QObject + signal/slot + static DestinationPtr MakeFunctorDestination(QObject *receiver, const char *member); +}; + +} // end namespace + +#endif // QSLOGDEST_H diff --git a/中电项目/QsLog-master/QsLogDestConsole.cpp b/中电项目/QsLog-master/QsLogDestConsole.cpp new file mode 100644 index 0000000..bfd9828 --- /dev/null +++ b/中电项目/QsLog-master/QsLogDestConsole.cpp @@ -0,0 +1,55 @@ +// Copyright (c) 2013, 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. + +#include "QsLogDestConsole.h" +#include +#include + +#if defined(Q_OS_WIN) +#define WIN32_LEAN_AND_MEAN +#include +void QsDebugOutput::output( const QString& message ) +{ + OutputDebugStringW(reinterpret_cast(message.utf16())); + OutputDebugStringW(L"\n"); +} +#elif defined(Q_OS_UNIX) +#include +void QsDebugOutput::output( const QString& message ) +{ + fprintf(stderr, "%s\n", qPrintable(message)); + fflush(stderr); +} +#endif + +void QsLogging::DebugOutputDestination::write(const QString& message, Level) +{ + QsDebugOutput::output(message); +} + +bool QsLogging::DebugOutputDestination::isValid() +{ + return true; +} diff --git a/中电项目/QsLog-master/QsLogDestConsole.h b/中电项目/QsLog-master/QsLogDestConsole.h new file mode 100644 index 0000000..d422c23 --- /dev/null +++ b/中电项目/QsLog-master/QsLogDestConsole.h @@ -0,0 +1,52 @@ +// Copyright (c) 2013, 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. + +#ifndef QSLOGDESTCONSOLE_H +#define QSLOGDESTCONSOLE_H + +#include "QsLogDest.h" + +class QString; + +class QsDebugOutput +{ +public: + static void output(const QString& a_message); +}; + +namespace QsLogging +{ + +// debugger sink +class DebugOutputDestination : public Destination +{ +public: + virtual void write(const QString& message, Level level); + virtual bool isValid(); +}; + +} + +#endif // QSLOGDESTCONSOLE_H diff --git a/中电项目/QsLog-master/QsLogDestFile.cpp b/中电项目/QsLog-master/QsLogDestFile.cpp new file mode 100644 index 0000000..d2982b1 --- /dev/null +++ b/中电项目/QsLog-master/QsLogDestFile.cpp @@ -0,0 +1,165 @@ +// Copyright (c) 2013, 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. + +#include "QsLogDestFile.h" +#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) +#include +#endif +#include +#include +#include + +#if QT_VERSION < QT_VERSION_CHECK(5, 14, 0) +namespace Qt { +static const QTextStreamFunction endl = ::endl; +} +#endif + +const int QsLogging::SizeRotationStrategy::MaxBackupCount = 10; + +QsLogging::RotationStrategy::~RotationStrategy() +{ +} + +QsLogging::SizeRotationStrategy::SizeRotationStrategy() + : mCurrentSizeInBytes(0) + , mMaxSizeInBytes(0) + , mBackupsCount(0) +{ +} + +void QsLogging::SizeRotationStrategy::setInitialInfo(const QFile &file) +{ + mFileName = file.fileName(); + mCurrentSizeInBytes = file.size(); +} + +void QsLogging::SizeRotationStrategy::includeMessageInCalculation(const QString &message) +{ + mCurrentSizeInBytes += message.toUtf8().size(); +} + +bool QsLogging::SizeRotationStrategy::shouldRotate() +{ + return mCurrentSizeInBytes > mMaxSizeInBytes; +} + +// Algorithm assumes backups will be named filename.X, where 1 <= X <= mBackupsCount. +// All X's will be shifted up. +void QsLogging::SizeRotationStrategy::rotate() +{ + if (!mBackupsCount) { + if (!QFile::remove(mFileName)) + std::cerr << "QsLog: backup delete failed " << qPrintable(mFileName); + return; + } + + // 1. find the last existing backup than can be shifted up + const QString logNamePattern = mFileName + QString::fromUtf8(".%1"); + int lastExistingBackupIndex = 0; + for (int i = 1;i <= mBackupsCount;++i) { + const QString backupFileName = logNamePattern.arg(i); + if (QFile::exists(backupFileName)) + lastExistingBackupIndex = qMin(i, mBackupsCount - 1); + else + break; + } + + // 2. shift up + for (int i = lastExistingBackupIndex;i >= 1;--i) { + const QString oldName = logNamePattern.arg(i); + const QString newName = logNamePattern.arg(i + 1); + QFile::remove(newName); + const bool renamed = QFile::rename(oldName, newName); + if (!renamed) { + std::cerr << "QsLog: could not rename backup " << qPrintable(oldName) + << " to " << qPrintable(newName); + } + } + + // 3. rename current log file + const QString newName = logNamePattern.arg(1); + if (QFile::exists(newName)) + QFile::remove(newName); + if (!QFile::rename(mFileName, newName)) { + std::cerr << "QsLog: could not rename log " << qPrintable(mFileName) + << " to " << qPrintable(newName); + } +} + +QIODevice::OpenMode QsLogging::SizeRotationStrategy::recommendedOpenModeFlag() +{ + return QIODevice::Append; +} + +void QsLogging::SizeRotationStrategy::setMaximumSizeInBytes(qint64 size) +{ + Q_ASSERT(size >= 0); + mMaxSizeInBytes = size; +} + +void QsLogging::SizeRotationStrategy::setBackupCount(int backups) +{ + Q_ASSERT(backups >= 0); + mBackupsCount = qMin(backups, SizeRotationStrategy::MaxBackupCount); +} + + +QsLogging::FileDestination::FileDestination(const QString& filePath, RotationStrategyPtr rotationStrategy) + : mRotationStrategy(rotationStrategy) +{ + mFile.setFileName(filePath); + if (!mFile.open(QFile::WriteOnly | QFile::Text | mRotationStrategy->recommendedOpenModeFlag())) + std::cerr << "QsLog: could not open log file " << qPrintable(filePath); + mOutputStream.setDevice(&mFile); +#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) + mOutputStream.setCodec(QTextCodec::codecForName("UTF-8")); +#endif + + mRotationStrategy->setInitialInfo(mFile); +} + +void QsLogging::FileDestination::write(const QString& message, Level) +{ + mRotationStrategy->includeMessageInCalculation(message); + if (mRotationStrategy->shouldRotate()) { + mOutputStream.setDevice(NULL); + mFile.close(); + mRotationStrategy->rotate(); + if (!mFile.open(QFile::WriteOnly | QFile::Text | mRotationStrategy->recommendedOpenModeFlag())) + std::cerr << "QsLog: could not reopen log file " << qPrintable(mFile.fileName()); + mRotationStrategy->setInitialInfo(mFile); + mOutputStream.setDevice(&mFile); + } + + mOutputStream << message << Qt::endl; + mOutputStream.flush(); +} + +bool QsLogging::FileDestination::isValid() +{ + return mFile.isOpen(); +} + diff --git a/中电项目/QsLog-master/QsLogDestFile.h b/中电项目/QsLog-master/QsLogDestFile.h new file mode 100644 index 0000000..ee7b523 --- /dev/null +++ b/中电项目/QsLog-master/QsLogDestFile.h @@ -0,0 +1,101 @@ +// Copyright (c) 2013, 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. + +#ifndef QSLOGDESTFILE_H +#define QSLOGDESTFILE_H + +#include "QsLogDest.h" +#include +#include +#include +#include + +namespace QsLogging +{ +class RotationStrategy +{ +public: + virtual ~RotationStrategy(); + + virtual void setInitialInfo(const QFile &file) = 0; + virtual void includeMessageInCalculation(const QString &message) = 0; + virtual bool shouldRotate() = 0; + virtual void rotate() = 0; + virtual QIODevice::OpenMode recommendedOpenModeFlag() = 0; +}; + +// Never rotates file, overwrites existing file. +class NullRotationStrategy : public RotationStrategy +{ +public: + virtual void setInitialInfo(const QFile &) {} + virtual void includeMessageInCalculation(const QString &) {} + virtual bool shouldRotate() { return false; } + virtual void rotate() {} + virtual QIODevice::OpenMode recommendedOpenModeFlag() { return QIODevice::Truncate; } +}; + +// Rotates after a size is reached, keeps a number of <= 10 backups, appends to existing file. +class SizeRotationStrategy : public RotationStrategy +{ +public: + SizeRotationStrategy(); + static const int MaxBackupCount; + + virtual void setInitialInfo(const QFile &file); + virtual void includeMessageInCalculation(const QString &message); + virtual bool shouldRotate(); + virtual void rotate(); + virtual QIODevice::OpenMode recommendedOpenModeFlag(); + + void setMaximumSizeInBytes(qint64 size); + void setBackupCount(int backups); + +private: + QString mFileName; + qint64 mCurrentSizeInBytes; + qint64 mMaxSizeInBytes; + int mBackupsCount; +}; + +typedef QSharedPointer RotationStrategyPtr; + +// file message sink +class FileDestination : public Destination +{ +public: + FileDestination(const QString& filePath, RotationStrategyPtr rotationStrategy); + virtual void write(const QString& message, Level level); + virtual bool isValid(); + +private: + QFile mFile; + QTextStream mOutputStream; + QSharedPointer mRotationStrategy; +}; + +} + +#endif // QSLOGDESTFILE_H diff --git a/中电项目/QsLog-master/QsLogDestFunctor.cpp b/中电项目/QsLog-master/QsLogDestFunctor.cpp new file mode 100644 index 0000000..601139d --- /dev/null +++ b/中电项目/QsLog-master/QsLogDestFunctor.cpp @@ -0,0 +1,57 @@ +// Copyright (c) 2014, Razvan Petru +// Copyright (c) 2014, Omar Carey +// 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. + +#include "QsLogDestFunctor.h" +#include +#include + +QsLogging::FunctorDestination::FunctorDestination(LogFunction f) + : QObject(NULL) + , mLogFunction(f) +{ +} + +QsLogging::FunctorDestination::FunctorDestination(QObject *receiver, const char *member) + : QObject(NULL) + , mLogFunction(NULL) +{ + connect(this, SIGNAL(logMessageReady(QString,int)), receiver, member, Qt::QueuedConnection); +} + + +void QsLogging::FunctorDestination::write(const QString &message, QsLogging::Level level) +{ + if (mLogFunction) + mLogFunction(message, level); + + if (level > QsLogging::TraceLevel) + emit logMessageReady(message, static_cast(level)); +} + +bool QsLogging::FunctorDestination::isValid() +{ + return true; +} diff --git a/中电项目/QsLog-master/QsLogDestFunctor.h b/中电项目/QsLog-master/QsLogDestFunctor.h new file mode 100644 index 0000000..e34631f --- /dev/null +++ b/中电项目/QsLog-master/QsLogDestFunctor.h @@ -0,0 +1,59 @@ +// Copyright (c) 2014, Razvan Petru +// Copyright (c) 2014, Omar Carey +// 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. + +#ifndef QSLOGDESTFUNCTOR_H +#define QSLOGDESTFUNCTOR_H + +#include "QsLogDest.h" +#include + +namespace QsLogging +{ +// Offers various types of function-like sinks. +// This is an advanced destination type. Depending on your configuration, LogFunction might be +// called from a different thread or even a different binary. You should not access QsLog from +// inside LogFunction and should not perform any time-consuming operations. +// logMessageReady is connected through a queued connection and trace messages are not included +class FunctorDestination : public QObject, public Destination +{ + Q_OBJECT +public: + explicit FunctorDestination(LogFunction f); + FunctorDestination(QObject *receiver, const char *member); + + virtual void write(const QString &message, Level level); + virtual bool isValid(); + +protected: + // int used to avoid registering a new enum type + Q_SIGNAL void logMessageReady(const QString &message, int level); + +private: + LogFunction mLogFunction; +}; +} + +#endif // QSLOGDESTFUNCTOR_H diff --git a/中电项目/QsLog-master/QsLogDisableForThisFile.h b/中电项目/QsLog-master/QsLogDisableForThisFile.h new file mode 100644 index 0000000..c70af10 --- /dev/null +++ b/中电项目/QsLog-master/QsLogDisableForThisFile.h @@ -0,0 +1,22 @@ +#ifndef QSLOGDISABLEFORTHISFILE_H +#define QSLOGDISABLEFORTHISFILE_H + +#include +// When included AFTER QsLog.h, this file will disable logging in that C++ file. When included +// before, it will lead to compiler warnings or errors about macro redefinitions. + +#undef QLOG_TRACE +#undef QLOG_DEBUG +#undef QLOG_INFO +#undef QLOG_WARN +#undef QLOG_ERROR +#undef QLOG_FATAL + +#define QLOG_TRACE() if (1) {} else qDebug() +#define QLOG_DEBUG() if (1) {} else qDebug() +#define QLOG_INFO() if (1) {} else qDebug() +#define QLOG_WARN() if (1) {} else qDebug() +#define QLOG_ERROR() if (1) {} else qDebug() +#define QLOG_FATAL() if (1) {} else qDebug() + +#endif // QSLOGDISABLEFORTHISFILE_H diff --git a/中电项目/QsLog-master/QsLogLevel.h b/中电项目/QsLog-master/QsLogLevel.h new file mode 100644 index 0000000..5032f27 --- /dev/null +++ b/中电项目/QsLog-master/QsLogLevel.h @@ -0,0 +1,45 @@ +// Copyright (c) 2013, 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. + +#ifndef QSLOGLEVEL_H +#define QSLOGLEVEL_H + +namespace QsLogging +{ + +enum Level +{ + TraceLevel = 0, + DebugLevel, + InfoLevel, + WarnLevel, + ErrorLevel, + FatalLevel, + OffLevel +}; + +} + +#endif // QSLOGLEVEL_H diff --git a/中电项目/QsLog-master/QsLogReadme.txt b/中电项目/QsLog-master/QsLogReadme.txt new file mode 100644 index 0000000..a7a50e0 --- /dev/null +++ b/中电项目/QsLog-master/QsLogReadme.txt @@ -0,0 +1,65 @@ +QsLog - the simple Qt logger +------------------------------------------------------------------------------- +QsLog is an easy to use logger that is based on Qt's QDebug class. + +Features +------------------------------------------------------------------------------- + * Six logging levels (from trace to fatal) + * Logging level threshold configurable at runtime. + * Minimum overhead when logging is turned off. + * Multiple destinations, comes with file and debug destinations. + * Thread-safe + * Logging of common Qt types out of the box. + * Immediate logging or queueing messages in a separate thread. + * Small dependency: just drop it in your project directly. + +Usage +------------------------------------------------------------------------------- +By directly including QsLog in your project: + 1. Include QsLog.pri in your pro file + 2. Include QsLog.h in your C++ files. Include QsLogDest.h only where you create/add destinations. + 3. Get the instance of the logger by calling QsLogging::Logger::instance(); + 4. Optionally set the logging level. Info is default. + 5. Create as many destinations as you want by using the QsLogging::DestinationFactory. + 6. Add the destinations to the logger instance by calling addDestination. + 7. Start logging! + Note: when you want to use QsLog both from an executable and a shared library you have to + link dynamically with QsLog due to a limitation with static variables. + +By linking to QsLog dynamically: + 1. Build QsLog using the QsLogSharedLibrary.pro. + 2. Add the QsLog shared library to your LIBS project dependencies. + 3. Follow the steps in "directly including QsLog in your project" starting with step 2. + +Configuration +------------------------------------------------------------------------------- +QsLog has several configurable parameters: + * defining QS_LOG_LINE_NUMBERS in the .pri file enables writing the file and line number + automatically for each logging call + * defining QS_LOG_SEPARATE_THREAD will route all log messages to a separate thread. + +Sometimes it's necessary to turn off logging. This can be done in several ways: + * globally, at compile time, by enabling the QS_LOG_DISABLE macro in the .pri file. + * globally, at run time, by setting the log level to "OffLevel". + * per file, at compile time, by including QsLogDisableForThisFile.h in the target file. + +Thread safety +------------------------------------------------------------------------------- +The Qt docs say: A thread-safe function can be called simultaneously from multiple threads, +even when the invocations use shared data, because all references to the shared data are serialized. +A reentrant function can also be called simultaneously from multiple threads, but only if each +invocation uses its own data. + +Since sending the log message to the destinations is protected by a mutex, the logging macros are +thread-safe provided that the log has been initialized - i.e: instance() has been called. +The instance function and the setup functions (e.g: setLoggingLevel, addDestination) are NOT +thread-safe and are NOT reentrant. + +IMPORTANT: when using a separate thread for logging, your program might crash at exit time on some + operating systems if you won't call Logger::destroyInstance() before your program exits. + This function can be called either before returning from main in a console app or + inside QCoreApplication::aboutToQuit in a Qt GUI app. + The reason is that the logging thread is still running as some objects are destroyed by + the OS. Calling destroyInstance will wait for the thread to finish. + Nothing will happen if you forget to call the function when not using a separate thread + for logging. diff --git a/中电项目/QsLog-master/QsLogSharedLibrary.pro b/中电项目/QsLog-master/QsLogSharedLibrary.pro new file mode 100644 index 0000000..5132068 --- /dev/null +++ b/中电项目/QsLog-master/QsLogSharedLibrary.pro @@ -0,0 +1,35 @@ +# This pro file will build QsLog as a shared library +include(QsLog.pri) + +TARGET = QsLog +VERSION = "2.0.0" +QT -= gui +CONFIG -= console +CONFIG -= app_bundle +CONFIG += shared +TEMPLATE = lib + +DESTDIR = $$PWD/build-QsLogShared +OBJECTS_DIR = $$DESTDIR/obj +MOC_DIR = $$DESTDIR/moc + +win32 { + DEFINES += QSLOG_IS_SHARED_LIBRARY +} + +unix:!macx { + # make install will install the shared object in the appropriate folders + headers.files = QsLog.h QsLogDest.h QsLogLevel.h + headers.path = /usr/include/$(QMAKE_TARGET) + + other_files.files = *.txt + other_files.path = /usr/local/share/$(QMAKE_TARGET) + + contains(QT_ARCH, x86_64) { + target.path = /usr/lib64 + } else { + target.path = /usr/lib + } + + INSTALLS += headers target other_files +} diff --git a/中电项目/QsLog-master/QsLogSharedLibrary.pro.user.832f845 b/中电项目/QsLog-master/QsLogSharedLibrary.pro.user.832f845 new file mode 100644 index 0000000..2fbc222 --- /dev/null +++ b/中电项目/QsLog-master/QsLogSharedLibrary.pro.user.832f845 @@ -0,0 +1,319 @@ + + + + + + EnvironmentId + {832f845a-955b-483b-abd8-c34cca3bf53f} + + + ProjectExplorer.Project.ActiveTarget + 0 + + + ProjectExplorer.Project.EditorSettings + + true + false + true + + Cpp + + CppGlobal + + + + QmlJS + + QmlJSGlobal + + + 2 + UTF-8 + false + 4 + false + 80 + true + true + 1 + true + false + 0 + true + true + 0 + 8 + true + 1 + true + true + true + false + + + + ProjectExplorer.Project.PluginSettings + + + -fno-delayed-template-parsing + + true + + + + ProjectExplorer.Project.Target.0 + + Desktop Qt 5.14.2 MinGW 64-bit + Desktop Qt 5.14.2 MinGW 64-bit + qt.qt5.5142.win64_mingw73_kit + 0 + 0 + 0 + + F:/build-QsLogSharedLibrary-Desktop_Qt_5_14_2_MinGW_64_bit-Debug + + + true + QtProjectManager.QMakeBuildStep + true + + false + false + false + + + true + Qt4ProjectManager.MakeStep + + false + + + false + + 2 + Build + Build + ProjectExplorer.BuildSteps.Build + + + + true + Qt4ProjectManager.MakeStep + + true + clean + + false + + 1 + Clean + Clean + ProjectExplorer.BuildSteps.Clean + + 2 + false + + Debug + Qt4ProjectManager.Qt4BuildConfiguration + 2 + + + F:/build-QsLogSharedLibrary-Desktop_Qt_5_14_2_MinGW_64_bit-Release + + + true + QtProjectManager.QMakeBuildStep + false + + false + false + true + + + true + Qt4ProjectManager.MakeStep + + false + + + false + + 2 + Build + Build + ProjectExplorer.BuildSteps.Build + + + + true + Qt4ProjectManager.MakeStep + + true + clean + + false + + 1 + Clean + Clean + ProjectExplorer.BuildSteps.Clean + + 2 + false + + Release + Qt4ProjectManager.Qt4BuildConfiguration + 0 + + + F:/build-QsLogSharedLibrary-Desktop_Qt_5_14_2_MinGW_64_bit-Profile + + + true + QtProjectManager.QMakeBuildStep + true + + false + true + true + + + true + Qt4ProjectManager.MakeStep + + false + + + false + + 2 + Build + Build + ProjectExplorer.BuildSteps.Build + + + + true + Qt4ProjectManager.MakeStep + + true + clean + + false + + 1 + Clean + Clean + ProjectExplorer.BuildSteps.Clean + + 2 + false + + Profile + Qt4ProjectManager.Qt4BuildConfiguration + 0 + + 3 + + + 0 + Deploy + Deploy + ProjectExplorer.BuildSteps.Deploy + + 1 + ProjectExplorer.DefaultDeployConfiguration + + 1 + + + dwarf + + cpu-cycles + + + 250 + + -e + cpu-cycles + --call-graph + dwarf,4096 + -F + 250 + + -F + true + 4096 + false + false + 1000 + + true + + false + false + false + false + true + 0.01 + 10 + true + kcachegrind + 1 + 25 + + 1 + true + false + true + valgrind + + 0 + 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 + 11 + 12 + 13 + 14 + + 2 + + + ProjectExplorer.CustomExecutableRunConfiguration + + + false + + false + true + false + false + true + + + + 1 + + + + ProjectExplorer.Project.TargetCount + 1 + + + ProjectExplorer.Project.Updater.FileVersion + 22 + + + Version + 22 + + diff --git a/中电项目/QsLog-master/QsLogSharedLibrary.pro.user.ffb6814 b/中电项目/QsLog-master/QsLogSharedLibrary.pro.user.ffb6814 new file mode 100644 index 0000000..70bf866 --- /dev/null +++ b/中电项目/QsLog-master/QsLogSharedLibrary.pro.user.ffb6814 @@ -0,0 +1,557 @@ + + + + + + EnvironmentId + {ffb6814f-0577-4285-afc1-3bc2718550c3} + + + ProjectExplorer.Project.ActiveTarget + 1 + + + ProjectExplorer.Project.EditorSettings + + true + false + true + + Cpp + + CppGlobal + + + + QmlJS + + QmlJSGlobal + + + 2 + UTF-8 + false + 4 + false + 80 + true + true + 1 + true + false + 0 + true + true + 0 + 8 + true + 1 + true + true + true + false + + + + ProjectExplorer.Project.PluginSettings + + + + ProjectExplorer.Project.Target.0 + + Desktop Qt 5.14.2 MSVC2017 64bit + Desktop Qt 5.14.2 MSVC2017 64bit + qt.qt5.5142.win64_msvc2017_64_kit + 0 + 0 + 0 + + F:/build-QsLogSharedLibrary-Desktop_Qt_5_14_2_MSVC2017_64bit-Debug + + + true + QtProjectManager.QMakeBuildStep + true + + false + false + false + + + true + Qt4ProjectManager.MakeStep + + false + + + false + + 2 + Build + Build + ProjectExplorer.BuildSteps.Build + + + + true + Qt4ProjectManager.MakeStep + + true + clean + + false + + 1 + Clean + Clean + ProjectExplorer.BuildSteps.Clean + + 2 + false + + Debug + Qt4ProjectManager.Qt4BuildConfiguration + 2 + + + F:/build-QsLogSharedLibrary-Desktop_Qt_5_14_2_MSVC2017_64bit-Release + + + true + QtProjectManager.QMakeBuildStep + false + + false + false + true + + + true + Qt4ProjectManager.MakeStep + + false + + + false + + 2 + Build + Build + ProjectExplorer.BuildSteps.Build + + + + true + Qt4ProjectManager.MakeStep + + true + clean + + false + + 1 + Clean + Clean + ProjectExplorer.BuildSteps.Clean + + 2 + false + + Release + Qt4ProjectManager.Qt4BuildConfiguration + 0 + + + F:/build-QsLogSharedLibrary-Desktop_Qt_5_14_2_MSVC2017_64bit-Profile + + + true + QtProjectManager.QMakeBuildStep + true + + false + true + true + + + true + Qt4ProjectManager.MakeStep + + false + + + false + + 2 + Build + Build + ProjectExplorer.BuildSteps.Build + + + + true + Qt4ProjectManager.MakeStep + + true + clean + + false + + 1 + Clean + Clean + ProjectExplorer.BuildSteps.Clean + + 2 + false + + Profile + Qt4ProjectManager.Qt4BuildConfiguration + 0 + + 3 + + + 0 + Deploy + Deploy + ProjectExplorer.BuildSteps.Deploy + + 1 + ProjectExplorer.DefaultDeployConfiguration + + 1 + + + dwarf + + cpu-cycles + + + 250 + + -e + cpu-cycles + --call-graph + dwarf,4096 + -F + 250 + + -F + true + 4096 + false + false + 1000 + + true + + false + false + false + false + true + 0.01 + 10 + true + kcachegrind + 1 + 25 + + 1 + true + false + true + valgrind + + 0 + 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 + 11 + 12 + 13 + 14 + + 2 + + + ProjectExplorer.CustomExecutableRunConfiguration + + + false + + false + true + false + false + true + + + + 1 + + + + ProjectExplorer.Project.Target.1 + + Desktop Qt 5.14.2 MinGW 64-bit + Desktop Qt 5.14.2 MinGW 64-bit + qt.qt5.5142.win64_mingw73_kit + 1 + 0 + 0 + + F:/build-QsLogSharedLibrary-Desktop_Qt_5_14_2_MinGW_64_bit-Debug + + + true + QtProjectManager.QMakeBuildStep + true + + false + false + false + + + true + Qt4ProjectManager.MakeStep + + false + + + false + + 2 + Build + Build + ProjectExplorer.BuildSteps.Build + + + + true + Qt4ProjectManager.MakeStep + + true + clean + + false + + 1 + Clean + Clean + ProjectExplorer.BuildSteps.Clean + + 2 + false + + Debug + Qt4ProjectManager.Qt4BuildConfiguration + 2 + + + F:/build-QsLogSharedLibrary-Desktop_Qt_5_14_2_MinGW_64_bit-Release + + + true + QtProjectManager.QMakeBuildStep + false + + false + false + true + + + true + Qt4ProjectManager.MakeStep + + false + + + false + + 2 + Build + Build + ProjectExplorer.BuildSteps.Build + + + + true + Qt4ProjectManager.MakeStep + + true + clean + + false + + 1 + Clean + Clean + ProjectExplorer.BuildSteps.Clean + + 2 + false + + Release + Qt4ProjectManager.Qt4BuildConfiguration + 0 + + + F:/build-QsLogSharedLibrary-Desktop_Qt_5_14_2_MinGW_64_bit-Profile + + + true + QtProjectManager.QMakeBuildStep + true + + false + true + true + + + true + Qt4ProjectManager.MakeStep + + false + + + false + + 2 + Build + Build + ProjectExplorer.BuildSteps.Build + + + + true + Qt4ProjectManager.MakeStep + + true + clean + + false + + 1 + Clean + Clean + ProjectExplorer.BuildSteps.Clean + + 2 + false + + Profile + Qt4ProjectManager.Qt4BuildConfiguration + 0 + + 3 + + + 0 + Deploy + Deploy + ProjectExplorer.BuildSteps.Deploy + + 1 + ProjectExplorer.DefaultDeployConfiguration + + 1 + + + dwarf + + cpu-cycles + + + 250 + + -e + cpu-cycles + --call-graph + dwarf,4096 + -F + 250 + + -F + true + 4096 + false + false + 1000 + + true + + false + false + false + false + true + 0.01 + 10 + true + kcachegrind + 1 + 25 + + 1 + true + false + true + valgrind + + 0 + 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 + 11 + 12 + 13 + 14 + + 2 + + + ProjectExplorer.CustomExecutableRunConfiguration + + + false + + false + true + false + false + true + + + + 1 + + + + ProjectExplorer.Project.TargetCount + 2 + + + ProjectExplorer.Project.Updater.FileVersion + 22 + + + Version + 22 + + diff --git a/中电项目/QsLog-master/Qslog/bin/QsLog2.dll b/中电项目/QsLog-master/Qslog/bin/QsLog2.dll new file mode 100644 index 0000000..39a58e7 Binary files /dev/null and b/中电项目/QsLog-master/Qslog/bin/QsLog2.dll differ diff --git a/中电项目/QsLog-master/Qslog/bin/libQsLog2.a b/中电项目/QsLog-master/Qslog/bin/libQsLog2.a new file mode 100644 index 0000000..247f871 Binary files /dev/null and b/中电项目/QsLog-master/Qslog/bin/libQsLog2.a differ diff --git a/中电项目/QsLog-master/Qslog/include/QsLog.h b/中电项目/QsLog-master/Qslog/include/QsLog.h new file mode 100644 index 0000000..c1beae2 --- /dev/null +++ b/中电项目/QsLog-master/Qslog/include/QsLog.h @@ -0,0 +1,146 @@ +// Copyright (c) 2013, 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. + +#ifndef QSLOG_H +#define QSLOG_H + +#include "QsLogLevel.h" +#include "QsLogDest.h" +#include +#include + +#define QS_LOG_VERSION "2.0b3" + +namespace QsLogging +{ +class Destination; +class LoggerImpl; // d pointer + +class QSLOG_SHARED_OBJECT Logger +{ +public: + static Logger& instance(); + static void destroyInstance(); + static Level levelFromLogMessage(const QString& logMessage, bool* conversionSucceeded = 0); + + ~Logger(); + + //! Adds a log message destination. Don't add null destinations. + void addDestination(DestinationPtr destination); + //! Logging at a level < 'newLevel' will be ignored + void setLoggingLevel(Level newLevel); + //! The default level is INFO + Level loggingLevel() const; + //! Set to false to disable timestamp inclusion in log messages + void setIncludeTimestamp(bool e); + //! Default value is true. + bool includeTimestamp() const; + //! Set to false to disable log level inclusion in log messages + void setIncludeLogLevel(bool l); + //! Default value is true. + bool includeLogLevel() const; + + //! The helper forwards the streaming to QDebug and builds the final + //! log message. + 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&); // not available + Logger& operator=(const Logger&); // not available + + void enqueueWrite(const QString& message, Level level); + void write(const QString& message, Level level); + + LoggerImpl* d; + + friend class LogWriterRunnable; +}; + +} // end namespace + +//! Logging macros: define QS_LOG_LINE_NUMBERS to get the file and line number +//! in the log output. +#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() << __FILE__ << '@' << __LINE__ +#define QLOG_DEBUG() \ + if (QsLogging::Logger::instance().loggingLevel() > QsLogging::DebugLevel) {} \ + else QsLogging::Logger::Helper(QsLogging::DebugLevel).stream() << __FILE__ << '@' << __LINE__ +#define QLOG_INFO() \ + if (QsLogging::Logger::instance().loggingLevel() > QsLogging::InfoLevel) {} \ + else QsLogging::Logger::Helper(QsLogging::InfoLevel).stream() << __FILE__ << '@' << __LINE__ +#define QLOG_WARN() \ + if (QsLogging::Logger::instance().loggingLevel() > QsLogging::WarnLevel) {} \ + else QsLogging::Logger::Helper(QsLogging::WarnLevel).stream() << __FILE__ << '@' << __LINE__ +#define QLOG_ERROR() \ + if (QsLogging::Logger::instance().loggingLevel() > QsLogging::ErrorLevel) {} \ + else QsLogging::Logger::Helper(QsLogging::ErrorLevel).stream() << __FILE__ << '@' << __LINE__ +#define QLOG_FATAL() \ + if (QsLogging::Logger::instance().loggingLevel() > QsLogging::FatalLevel) {} \ + else QsLogging::Logger::Helper(QsLogging::FatalLevel).stream() << __FILE__ << '@' << __LINE__ +#endif + +#ifdef QS_LOG_DISABLE +#include "QsLogDisableForThisFile.h" +#endif + +#endif // QSLOG_H diff --git a/中电项目/QsLog-master/Qslog/include/QsLogDest.h b/中电项目/QsLog-master/Qslog/include/QsLogDest.h new file mode 100644 index 0000000..4ed6157 --- /dev/null +++ b/中电项目/QsLog-master/Qslog/include/QsLogDest.h @@ -0,0 +1,99 @@ +// Copyright (c) 2013, 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. + +#ifndef QSLOGDEST_H +#define QSLOGDEST_H + +#include "QsLogLevel.h" +#include +#include +class QString; +class QObject; + +#ifdef QSLOG_IS_SHARED_LIBRARY +#define QSLOG_SHARED_OBJECT Q_DECL_EXPORT +#elif QSLOG_IS_SHARED_LIBRARY_IMPORT +#define QSLOG_SHARED_OBJECT Q_DECL_IMPORT +#else +#define QSLOG_SHARED_OBJECT +#endif + +namespace QsLogging +{ + +class QSLOG_SHARED_OBJECT Destination +{ +public: + typedef void (*LogFunction)(const QString &message, Level level); + +public: + virtual ~Destination(); + virtual void write(const QString& message, Level level) = 0; + virtual bool isValid() = 0; // returns whether the destination was created correctly +}; +typedef QSharedPointer DestinationPtr; + + +// a series of "named" paramaters, to make the file destination creation more readable +enum LogRotationOption +{ + DisableLogRotation = 0, + EnableLogRotation = 1 +}; + +struct QSLOG_SHARED_OBJECT MaxSizeBytes +{ + MaxSizeBytes() : size(0) {} + explicit MaxSizeBytes(qint64 size_) : size(size_) {} + qint64 size; +}; + +struct QSLOG_SHARED_OBJECT MaxOldLogCount +{ + MaxOldLogCount() : count(0) {} + explicit MaxOldLogCount(int count_) : count(count_) {} + int count; +}; + + +//! Creates logging destinations/sinks. The caller shares ownership of the destinations with the logger. +//! After being added to a logger, the caller can discard the pointers. +class QSLOG_SHARED_OBJECT DestinationFactory +{ +public: + static DestinationPtr MakeFileDestination(const QString& filePath, + LogRotationOption rotation = DisableLogRotation, + const MaxSizeBytes &sizeInBytesToRotateAfter = MaxSizeBytes(), + const MaxOldLogCount &oldLogsToKeep = MaxOldLogCount()); + static DestinationPtr MakeDebugOutputDestination(); + // takes a pointer to a function + static DestinationPtr MakeFunctorDestination(Destination::LogFunction f); + // takes a QObject + signal/slot + static DestinationPtr MakeFunctorDestination(QObject *receiver, const char *member); +}; + +} // end namespace + +#endif // QSLOGDEST_H diff --git a/中电项目/QsLog-master/Qslog/include/QsLogDestConsole.h b/中电项目/QsLog-master/Qslog/include/QsLogDestConsole.h new file mode 100644 index 0000000..d422c23 --- /dev/null +++ b/中电项目/QsLog-master/Qslog/include/QsLogDestConsole.h @@ -0,0 +1,52 @@ +// Copyright (c) 2013, 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. + +#ifndef QSLOGDESTCONSOLE_H +#define QSLOGDESTCONSOLE_H + +#include "QsLogDest.h" + +class QString; + +class QsDebugOutput +{ +public: + static void output(const QString& a_message); +}; + +namespace QsLogging +{ + +// debugger sink +class DebugOutputDestination : public Destination +{ +public: + virtual void write(const QString& message, Level level); + virtual bool isValid(); +}; + +} + +#endif // QSLOGDESTCONSOLE_H diff --git a/中电项目/QsLog-master/Qslog/include/QsLogDestFile.h b/中电项目/QsLog-master/Qslog/include/QsLogDestFile.h new file mode 100644 index 0000000..ee7b523 --- /dev/null +++ b/中电项目/QsLog-master/Qslog/include/QsLogDestFile.h @@ -0,0 +1,101 @@ +// Copyright (c) 2013, 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. + +#ifndef QSLOGDESTFILE_H +#define QSLOGDESTFILE_H + +#include "QsLogDest.h" +#include +#include +#include +#include + +namespace QsLogging +{ +class RotationStrategy +{ +public: + virtual ~RotationStrategy(); + + virtual void setInitialInfo(const QFile &file) = 0; + virtual void includeMessageInCalculation(const QString &message) = 0; + virtual bool shouldRotate() = 0; + virtual void rotate() = 0; + virtual QIODevice::OpenMode recommendedOpenModeFlag() = 0; +}; + +// Never rotates file, overwrites existing file. +class NullRotationStrategy : public RotationStrategy +{ +public: + virtual void setInitialInfo(const QFile &) {} + virtual void includeMessageInCalculation(const QString &) {} + virtual bool shouldRotate() { return false; } + virtual void rotate() {} + virtual QIODevice::OpenMode recommendedOpenModeFlag() { return QIODevice::Truncate; } +}; + +// Rotates after a size is reached, keeps a number of <= 10 backups, appends to existing file. +class SizeRotationStrategy : public RotationStrategy +{ +public: + SizeRotationStrategy(); + static const int MaxBackupCount; + + virtual void setInitialInfo(const QFile &file); + virtual void includeMessageInCalculation(const QString &message); + virtual bool shouldRotate(); + virtual void rotate(); + virtual QIODevice::OpenMode recommendedOpenModeFlag(); + + void setMaximumSizeInBytes(qint64 size); + void setBackupCount(int backups); + +private: + QString mFileName; + qint64 mCurrentSizeInBytes; + qint64 mMaxSizeInBytes; + int mBackupsCount; +}; + +typedef QSharedPointer RotationStrategyPtr; + +// file message sink +class FileDestination : public Destination +{ +public: + FileDestination(const QString& filePath, RotationStrategyPtr rotationStrategy); + virtual void write(const QString& message, Level level); + virtual bool isValid(); + +private: + QFile mFile; + QTextStream mOutputStream; + QSharedPointer mRotationStrategy; +}; + +} + +#endif // QSLOGDESTFILE_H diff --git a/中电项目/QsLog-master/Qslog/include/QsLogDestFunctor.h b/中电项目/QsLog-master/Qslog/include/QsLogDestFunctor.h new file mode 100644 index 0000000..e34631f --- /dev/null +++ b/中电项目/QsLog-master/Qslog/include/QsLogDestFunctor.h @@ -0,0 +1,59 @@ +// Copyright (c) 2014, Razvan Petru +// Copyright (c) 2014, Omar Carey +// 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. + +#ifndef QSLOGDESTFUNCTOR_H +#define QSLOGDESTFUNCTOR_H + +#include "QsLogDest.h" +#include + +namespace QsLogging +{ +// Offers various types of function-like sinks. +// This is an advanced destination type. Depending on your configuration, LogFunction might be +// called from a different thread or even a different binary. You should not access QsLog from +// inside LogFunction and should not perform any time-consuming operations. +// logMessageReady is connected through a queued connection and trace messages are not included +class FunctorDestination : public QObject, public Destination +{ + Q_OBJECT +public: + explicit FunctorDestination(LogFunction f); + FunctorDestination(QObject *receiver, const char *member); + + virtual void write(const QString &message, Level level); + virtual bool isValid(); + +protected: + // int used to avoid registering a new enum type + Q_SIGNAL void logMessageReady(const QString &message, int level); + +private: + LogFunction mLogFunction; +}; +} + +#endif // QSLOGDESTFUNCTOR_H diff --git a/中电项目/QsLog-master/Qslog/include/QsLogDisableForThisFile.h b/中电项目/QsLog-master/Qslog/include/QsLogDisableForThisFile.h new file mode 100644 index 0000000..c70af10 --- /dev/null +++ b/中电项目/QsLog-master/Qslog/include/QsLogDisableForThisFile.h @@ -0,0 +1,22 @@ +#ifndef QSLOGDISABLEFORTHISFILE_H +#define QSLOGDISABLEFORTHISFILE_H + +#include +// When included AFTER QsLog.h, this file will disable logging in that C++ file. When included +// before, it will lead to compiler warnings or errors about macro redefinitions. + +#undef QLOG_TRACE +#undef QLOG_DEBUG +#undef QLOG_INFO +#undef QLOG_WARN +#undef QLOG_ERROR +#undef QLOG_FATAL + +#define QLOG_TRACE() if (1) {} else qDebug() +#define QLOG_DEBUG() if (1) {} else qDebug() +#define QLOG_INFO() if (1) {} else qDebug() +#define QLOG_WARN() if (1) {} else qDebug() +#define QLOG_ERROR() if (1) {} else qDebug() +#define QLOG_FATAL() if (1) {} else qDebug() + +#endif // QSLOGDISABLEFORTHISFILE_H diff --git a/中电项目/QsLog-master/Qslog/include/QsLogLevel.h b/中电项目/QsLog-master/Qslog/include/QsLogLevel.h new file mode 100644 index 0000000..5032f27 --- /dev/null +++ b/中电项目/QsLog-master/Qslog/include/QsLogLevel.h @@ -0,0 +1,45 @@ +// Copyright (c) 2013, 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. + +#ifndef QSLOGLEVEL_H +#define QSLOGLEVEL_H + +namespace QsLogging +{ + +enum Level +{ + TraceLevel = 0, + DebugLevel, + InfoLevel, + WarnLevel, + ErrorLevel, + FatalLevel, + OffLevel +}; + +} + +#endif // QSLOGLEVEL_H diff --git a/中电项目/QsLog-master/README.md b/中电项目/QsLog-master/README.md new file mode 100644 index 0000000..94cc283 --- /dev/null +++ b/中电项目/QsLog-master/README.md @@ -0,0 +1,39 @@ +## QsLog - the simple Qt logger ## +QsLog is an easy to use logger that is based on Qt's QDebug class. QsLog is released as open source, under the MIT license. + +###Contribution policy### +Bug fixes are welcome, larger changes however are not encouraged at this point due to the lack of time on my side for reviewing and integrating them. Your best bet in this case would be to open a ticket for your change or forking the project and implementing your change there, with the possibility of having it integrated in the future. +All contributions will be credited, license of the contributions should be MIT. + +### Features ### +* Six logging levels (from trace to fatal) +* Logging level threshold configurable at runtime. +* Minimum overhead when logging is turned off. +* Supports multiple destinations, comes with file and debug destinations. +* Thread-safe +* Supports logging of common Qt types out of the box. +* Small dependency: just drop it in your project directly. + +### Usage ### +* Include QsLog.h. Include QsLogDest.h only where you create/add destinations. +* Get the instance of the logger by calling QsLogging::Logger::instance(); +* Optionally set the logging level. Info is default. +* Create as many destinations as you want by using the QsLogging::DestinationFactory. +* Add the destinations to the logger instance by calling addDestination. + +**Note**: The logger does not take ownership of the destinations. Make sure that the destinations still exist when you call one of the logging macros. A good place to create the destinations is the program's main function. + +### Disabling logging ### +Sometimes it's necessary to turn off logging. This can be done in several ways: + +* globally, at compile time, by enabling the QS_LOG_DISABLE macro in the supplied .pri file. +* globally, at run time, by setting the log level to "OffLevel". +* per file, at compile time, by including QsLogDisableForThisFile.h in the target file. + +### Thread safety ### +The Qt docs say: +A **thread-safe** function can be called simultaneously from multiple threads, even when the invocations use shared data, because all references to the shared data are serialized. +A **reentrant** function can also be called simultaneously from multiple threads, but only if each invocation uses its own data. + +Since sending the log message to the destinations is protected by a mutex, the logging macros are thread-safe provided that the log has been initialized - i.e: instance() has been called. +The instance function and the setup functions (e.g: setLoggingLevel, addDestination) are NOT thread-safe and are NOT reentrant. \ No newline at end of file diff --git a/中电项目/QsLog-master/example/log_example.pro b/中电项目/QsLog-master/example/log_example.pro new file mode 100644 index 0000000..1d4be35 --- /dev/null +++ b/中电项目/QsLog-master/example/log_example.pro @@ -0,0 +1,6 @@ +TEMPLATE = subdirs +CONFIG += ordered + +SUBDIRS = ../QsLogSharedLibrary.pro \ + log_example_shared.pro \ + log_example_main.pro diff --git a/中电项目/QsLog-master/example/log_example_main.cpp b/中电项目/QsLog-master/example/log_example_main.cpp new file mode 100644 index 0000000..35a09a1 --- /dev/null +++ b/中电项目/QsLog-master/example/log_example_main.cpp @@ -0,0 +1,98 @@ +// Copyright (c) 2013, 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. + +#include "QsLog.h" +#include "QsLogDest.h" +#include "log_example_shared.h" +#include +#include +#include +#include + +void logFunction(const QString &message, QsLogging::Level level) +{ + std::cout << "From log function: " << qPrintable(message) << " " << static_cast(level) + << std::endl; +} + +// This small example shows how QsLog can be used inside a project. +int main(int argc, char *argv[]) +{ + QCoreApplication a(argc, argv); + + using namespace QsLogging; + + // 1. init the logging mechanism + Logger& logger = Logger::instance(); + logger.setLoggingLevel(QsLogging::TraceLevel); + const QString sLogPath(QDir(a.applicationDirPath()).filePath("log.txt")); + + // 2. add two destinations + DestinationPtr fileDestination(DestinationFactory::MakeFileDestination( + sLogPath, EnableLogRotation, MaxSizeBytes(512), MaxOldLogCount(2))); + DestinationPtr debugDestination(DestinationFactory::MakeDebugOutputDestination()); + DestinationPtr functorDestination(DestinationFactory::MakeFunctorDestination(&logFunction)); + logger.addDestination(debugDestination); + logger.addDestination(fileDestination); + logger.addDestination(functorDestination); + + // 3. start logging + QLOG_INFO() << "Program started"; + QLOG_INFO() << "Built with Qt" << QT_VERSION_STR << "running on" << qVersion(); + + QLOG_TRACE() << "Here's a" << QString::fromUtf8("trace") << "message"; + QLOG_DEBUG() << "Here's a" << static_cast(QsLogging::DebugLevel) << "message"; + QLOG_WARN() << "Uh-oh!"; + qDebug() << "This message won't be picked up by the logger"; + QLOG_ERROR() << "An error has occurred"; + qWarning() << "Neither will this one"; + QLOG_FATAL() << "Fatal error!"; + + logger.setLoggingLevel(QsLogging::OffLevel); + for (int i = 0;i < 10000000;++i) { + QLOG_ERROR() << QString::fromUtf8("this message should not be visible"); + } + logger.setLoggingLevel(QsLogging::TraceLevel); + + // 4. log from a shared library - should automatically share the same log instance as above + QLibrary myLib("log_example_shared"); + typedef LogExampleShared* (*LogExampleGetter)(); + typedef void(*LogExampleDeleter)(LogExampleShared*); + LogExampleGetter fLogCreator = (LogExampleGetter) myLib.resolve("createExample"); + LogExampleDeleter fLogDeleter = (LogExampleDeleter)myLib.resolve("destroyExample"); + LogExampleShared *logFromShared = 0; + if (fLogCreator && fLogDeleter) { + logFromShared = fLogCreator(); + logFromShared->logSomething(); + fLogDeleter(logFromShared); + } else if (!fLogCreator || !fLogDeleter) { + QLOG_ERROR() << "could not resolve shared library function(s)"; + } + + QLOG_DEBUG() << "Program ending"; + + QsLogging::Logger::destroyInstance(); + return 0; +} diff --git a/中电项目/QsLog-master/example/log_example_main.pro b/中电项目/QsLog-master/example/log_example_main.pro new file mode 100644 index 0000000..f7a990b --- /dev/null +++ b/中电项目/QsLog-master/example/log_example_main.pro @@ -0,0 +1,21 @@ +#This project links with QsLog dynamically and outputs an executable file. + +QT -= gui +TARGET = log_example +CONFIG += console +CONFIG -= app_bundle +TEMPLATE = app +SOURCES += log_example_main.cpp +INCLUDEPATH += $$PWD/../ +DEFINES += QSLOG_IS_SHARED_LIBRARY_IMPORT + +LIBS += -L$$PWD/../build-QsLogShared +win32 { + LIBS += -lQsLog2 +} else { + LIBS += -lQsLog +} +LIBS += -L$$PWD/../build-QsLogExample -llog_example_shared + +DESTDIR = $$PWD/../build-QsLogExample +OBJECTS_DIR = $$DESTDIR/obj diff --git a/中电项目/QsLog-master/example/log_example_shared.cpp b/中电项目/QsLog-master/example/log_example_shared.cpp new file mode 100644 index 0000000..8128a62 --- /dev/null +++ b/中电项目/QsLog-master/example/log_example_shared.cpp @@ -0,0 +1,43 @@ +// Copyright (c) 2013, 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. + +#include "log_example_shared.h" +#include "QsLog.h" + +void LogExampleShared::logSomething() +{ + QLOG_INFO() << "this message is comming from a shared library"; +} + +LogExampleShared* createExample() +{ + return new LogExampleShared(); +} + + +void destroyExample(LogExampleShared *example) +{ + delete example; +} diff --git a/中电项目/QsLog-master/example/log_example_shared.h b/中电项目/QsLog-master/example/log_example_shared.h new file mode 100644 index 0000000..b3e8573 --- /dev/null +++ b/中电项目/QsLog-master/example/log_example_shared.h @@ -0,0 +1,48 @@ +// Copyright (c) 2013, 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. + +#ifndef LOGEXAMPLESHARED_H +#define LOGEXAMPLESHARED_H + +#include + +#ifdef EXAMPLE_IS_SHARED_LIBRARY +#define EXAMPLE_SHARED_OBJECT Q_DECL_IMPORT +#else +#define EXAMPLE_SHARED_OBJECT Q_DECL_EXPORT +#endif + +class EXAMPLE_SHARED_OBJECT LogExampleShared +{ +public: + void logSomething(); +}; + +extern "C" { + LogExampleShared *createExample(); + void destroyExample(LogExampleShared *example); +} + +#endif // LOGEXAMPLESHARED_H diff --git a/中电项目/QsLog-master/example/log_example_shared.pro b/中电项目/QsLog-master/example/log_example_shared.pro new file mode 100644 index 0000000..f4fdee7 --- /dev/null +++ b/中电项目/QsLog-master/example/log_example_shared.pro @@ -0,0 +1,22 @@ +#This project file links with QsLog dynamically and outputs a shared object. + +QT -= gui + +TARGET = log_example_shared +TEMPLATE = lib + +DEFINES += EXAMPLE_IS_SHARED_LIBRARY QSLOG_IS_SHARED_LIBRARY_IMPORT +SOURCES += log_example_shared.cpp +HEADERS += log_example_shared.h +INCLUDEPATH += $$PWD/../ +DESTDIR = $$PWD/../build-QsLogExample +OBJECTS_DIR = $$DESTDIR/obj + +LIBS += -L$$PWD/../build-QsLogShared +win32 { + LIBS += -lQsLog2 +} else { + LIBS += -lQsLog +} + + diff --git a/中电项目/QsLog-master/unittest/QtTestUtil/QtTestUtil.h b/中电项目/QsLog-master/unittest/QtTestUtil/QtTestUtil.h new file mode 100644 index 0000000..cb5352f --- /dev/null +++ b/中电项目/QsLog-master/unittest/QtTestUtil/QtTestUtil.h @@ -0,0 +1,31 @@ +/* + * Copyright (C) 2008 Remko Troncon + * Licensed under the MIT license. + * See COPYING for license details. + */ + +#ifndef QtTestUtil_H +#define QtTestUtil_H + +#include +#include +#include "QtTestUtil/TestRegistration.h" + +/** + * A macro to register a test class. + * + * This macro will create a static variable which registers the + * testclass with the TestRegistry, and creates an instance of the + * test class. + * + * Execute this macro in the body of your unit test's .cpp file, e.g. + * class MyTest { + * ... + * }; + * + * QTTESTUTIL_REGISTER_TEST(MyTest) + */ +#define QTTESTUTIL_REGISTER_TEST(TestClass) \ + static QtTestUtil::TestRegistration TestClass##Registration + +#endif diff --git a/中电项目/QsLog-master/unittest/QtTestUtil/SimpleChecker.cpp b/中电项目/QsLog-master/unittest/QtTestUtil/SimpleChecker.cpp new file mode 100644 index 0000000..ab8ffd0 --- /dev/null +++ b/中电项目/QsLog-master/unittest/QtTestUtil/SimpleChecker.cpp @@ -0,0 +1,17 @@ +/* + * Copyright (C) 2008 Remko Troncon + * Licensed under the MIT license. + * See COPYING for license details. + */ + +#include + +#include "QtTestUtil/TestRegistry.h" + +/** + * Runs all tests registered with the QtTestUtil registry. + */ +int main(int argc, char* argv[]) { + QCoreApplication application(argc, argv); + return QtTestUtil::TestRegistry::getInstance()->runTests(argc, argv); +} diff --git a/中电项目/QsLog-master/unittest/QtTestUtil/TestRegistration.h b/中电项目/QsLog-master/unittest/QtTestUtil/TestRegistration.h new file mode 100644 index 0000000..d228751 --- /dev/null +++ b/中电项目/QsLog-master/unittest/QtTestUtil/TestRegistration.h @@ -0,0 +1,38 @@ +/* + * Copyright (C) 2008 Remko Troncon + * Licensed under the MIT license. + * See COPYING for license details. + */ + +#ifndef QtTestUtil_TestRegistration_H +#define QtTestUtil_TestRegistration_H + +#include "QtTestUtil/TestRegistry.h" + +namespace QtTestUtil { + + /** + * A wrapper class around a test to manage registration and static + * creation of an instance of the test class. + * This class is used by QTTESTUTIL_REGISTER_TEST(), and you should not + * use this class directly. + */ + template + class TestRegistration { + public: + TestRegistration() { + test_ = new TestClass(); + TestRegistry::getInstance()->registerTest(test_); + } + + ~TestRegistration() { + delete test_; + } + + private: + TestClass* test_; + }; + +} + +#endif diff --git a/中电项目/QsLog-master/unittest/QtTestUtil/TestRegistry.cpp b/中电项目/QsLog-master/unittest/QtTestUtil/TestRegistry.cpp new file mode 100644 index 0000000..5460f40 --- /dev/null +++ b/中电项目/QsLog-master/unittest/QtTestUtil/TestRegistry.cpp @@ -0,0 +1,30 @@ +/* + * Copyright (C) 2008 Remko Troncon + * Licensed under the MIT license. + * See COPYING for license details. + */ + +#include "QtTestUtil/TestRegistry.h" + +#include + +namespace QtTestUtil { + +TestRegistry* TestRegistry::getInstance() { + static TestRegistry registry; + return ®istry; +} + +void TestRegistry::registerTest(QObject* test) { + tests_ += test; +} + +int TestRegistry::runTests(int argc, char* argv[]) { + int result = 0; + foreach(QObject* test, tests_) { + result |= QTest::qExec(test, argc, argv); + } + return result; +} + +} diff --git a/中电项目/QsLog-master/unittest/QtTestUtil/TestRegistry.h b/中电项目/QsLog-master/unittest/QtTestUtil/TestRegistry.h new file mode 100644 index 0000000..d91bd9e --- /dev/null +++ b/中电项目/QsLog-master/unittest/QtTestUtil/TestRegistry.h @@ -0,0 +1,49 @@ +/* + * Copyright (C) 2008 Remko Troncon + * Licensed under the MIT license. + * See COPYING for license details. + */ + +#ifndef QtTestUtil_TestRegistry_H +#define QtTestUtil_TestRegistry_H + +#include + +class QObject; + +namespace QtTestUtil { + + /** + * A registry of QtTest test classes. + * All test classes registered with QTTESTUTIL_REGISTER_TEST add + * themselves to this registry. All registered tests can then be run at + * once using runTests(). + */ + class TestRegistry { + public: + /** + * Retrieve the single instance of the registry. + */ + static TestRegistry* getInstance(); + + /** + * Register a QtTest test. + * This method is called by QTTESTUTIL_REGISTER_TEST, and you should + * not use this method directly. + */ + void registerTest(QObject*); + + /** + * Run all registered tests using QTest::qExec() + */ + int runTests(int argc, char* argv[]); + + private: + TestRegistry() {} + + private: + QList tests_; + }; +} + +#endif diff --git a/中电项目/QsLog-master/unittest/TestLog.cpp b/中电项目/QsLog-master/unittest/TestLog.cpp new file mode 100644 index 0000000..4c07311 --- /dev/null +++ b/中电项目/QsLog-master/unittest/TestLog.cpp @@ -0,0 +1,202 @@ +#include "QtTestUtil/QtTestUtil.h" +#include "QsLog.h" +#include "QsLogDest.h" +#include +#include +#include + +// A destination that tracks log messages +class MockDestination : public QsLogging::Destination +{ +public: + virtual void write(const QString &message, QsLogging::Level level) + { + Message m; + m.text = message; + m.level = level; + mMessages.push_back(m); + ++mCountByLevel[level]; + } + + virtual bool isValid() + { + return true; + } + + struct Message + { + Message() : level(QsLogging::TraceLevel) {} + QString text; + QsLogging::Level level; + }; + + void clear() + { + mMessages.clear(); + mCountByLevel.clear(); + } + + int messageCount() const + { + return mMessages.count(); + } + + int messageCountForLevel(QsLogging::Level level) const + { + return mCountByLevel.value(level); + } + + bool hasMessage(const QString &messageContent, QsLogging::Level level) const + { + Q_FOREACH (const Message &m, mMessages) { + if (m.level == level && m.text.contains(messageContent)) + return true; + } + + return false; + } + + const Message& messageAt(int index) + { + Q_ASSERT(index >= 0 && index < messageCount()); + return mMessages.at(index); + } + +private: + QHash mCountByLevel; + QList mMessages; +}; + +// Autotests for QsLog +class TestLog : public QObject +{ + Q_OBJECT +public: + TestLog() + : mockDest1(new MockDestination) + , mockDest2(new MockDestination) + { + } + +private slots: + void initTestCase(); + void testAllLevels(); + void testMessageText(); + void testLevelChanges(); + void testLevelParsing(); + void cleanupTestCase(); + +private: + QSharedPointer mockDest1; + QSharedPointer mockDest2; +}; + +void TestLog::initTestCase() +{ + using namespace QsLogging; + QCOMPARE(Logger::instance().loggingLevel(), InfoLevel); + Logger::instance().setLoggingLevel(TraceLevel); + QCOMPARE(Logger::instance().loggingLevel(), TraceLevel); + Logger::instance().addDestination(mockDest1); + Logger::instance().addDestination(mockDest2); +} + +void TestLog::testAllLevels() +{ + mockDest1->clear(); + mockDest2->clear(); + + QLOG_TRACE() << "trace level"; + QLOG_DEBUG() << "debug level"; + QLOG_INFO() << "info level"; + QLOG_WARN() << "warn level"; + QLOG_ERROR() << "error level"; + QLOG_FATAL() << "fatal level"; + + using namespace QsLogging; + QCOMPARE(mockDest1->messageCount(), 6); + QCOMPARE(mockDest1->messageCountForLevel(TraceLevel), 1); + QCOMPARE(mockDest1->messageCountForLevel(DebugLevel), 1); + QCOMPARE(mockDest1->messageCountForLevel(InfoLevel), 1); + QCOMPARE(mockDest1->messageCountForLevel(WarnLevel), 1); + QCOMPARE(mockDest1->messageCountForLevel(ErrorLevel), 1); + QCOMPARE(mockDest1->messageCountForLevel(FatalLevel), 1); + QCOMPARE(mockDest2->messageCount(), 6); + QCOMPARE(mockDest2->messageCountForLevel(TraceLevel), 1); + QCOMPARE(mockDest2->messageCountForLevel(DebugLevel), 1); + QCOMPARE(mockDest2->messageCountForLevel(InfoLevel), 1); + QCOMPARE(mockDest2->messageCountForLevel(WarnLevel), 1); + QCOMPARE(mockDest2->messageCountForLevel(ErrorLevel), 1); + QCOMPARE(mockDest2->messageCountForLevel(FatalLevel), 1); +} + +void TestLog::testMessageText() +{ + mockDest1->clear(); + + QLOG_DEBUG() << "foobar"; + QLOG_WARN() << "eiszeit"; + QLOG_FATAL() << "ruh-roh!"; + using namespace QsLogging; + QVERIFY(mockDest1->hasMessage("foobar", DebugLevel)); + QVERIFY(mockDest1->hasMessage("eiszeit", WarnLevel)); + QVERIFY(mockDest1->hasMessage("ruh-roh!", FatalLevel)); + QCOMPARE(mockDest1->messageCount(), 3); +} + +void TestLog::testLevelChanges() +{ + mockDest1->clear(); + mockDest2->clear(); + + using namespace QsLogging; + Logger::instance().setLoggingLevel(WarnLevel); + QCOMPARE(Logger::instance().loggingLevel(), WarnLevel); + + QLOG_TRACE() << "one"; + QLOG_DEBUG() << "two"; + QLOG_INFO() << "three"; + QCOMPARE(mockDest1->messageCount(), 0); + QCOMPARE(mockDest2->messageCount(), 0); + + QLOG_WARN() << "warning"; + QLOG_ERROR() << "error"; + QLOG_FATAL() << "fatal"; + QCOMPARE(mockDest1->messageCountForLevel(WarnLevel), 1); + QCOMPARE(mockDest1->messageCountForLevel(ErrorLevel), 1); + QCOMPARE(mockDest1->messageCountForLevel(FatalLevel), 1); + QCOMPARE(mockDest1->messageCount(), 3); + QCOMPARE(mockDest2->messageCountForLevel(WarnLevel), 1); + QCOMPARE(mockDest2->messageCountForLevel(ErrorLevel), 1); + QCOMPARE(mockDest2->messageCountForLevel(FatalLevel), 1); + QCOMPARE(mockDest2->messageCount(), 3); +} + +void TestLog::testLevelParsing() +{ + mockDest1->clear(); + + QLOG_TRACE() << "one"; + QLOG_DEBUG() << "two"; + QLOG_INFO() << "three"; + QLOG_WARN() << "warning"; + QLOG_ERROR() << "error"; + QLOG_FATAL() << "fatal"; + + using namespace QsLogging; + for(int i = 0;i < mockDest1->messageCount();++i) { + bool conversionOk = false; + const MockDestination::Message& m = mockDest1->messageAt(i); + QCOMPARE(Logger::levelFromLogMessage(m.text, &conversionOk), m.level); + QCOMPARE(Logger::levelFromLogMessage(m.text), m.level); + QCOMPARE(conversionOk, true); + } +} + +void TestLog::cleanupTestCase() +{ + QsLogging::Logger::destroyInstance(); +} + +QTTESTUTIL_REGISTER_TEST(TestLog); +#include "TestLog.moc" diff --git a/中电项目/QsLog-master/unittest/unittest.pro b/中电项目/QsLog-master/unittest/unittest.pro new file mode 100644 index 0000000..e5c39ce --- /dev/null +++ b/中电项目/QsLog-master/unittest/unittest.pro @@ -0,0 +1,21 @@ +QT += core + +TARGET = QsLogUnitTest +CONFIG += console qtestlib +CONFIG -= app_bundle +TEMPLATE = app + +# test-case sources +SOURCES += TestLog.cpp + +# component sources +include(../QsLog.pri) + +SOURCES += \ + ./QtTestUtil/TestRegistry.cpp \ + ./QtTestUtil/SimpleChecker.cpp + +HEADERS += \ + ./QtTestUtil/TestRegistry.h \ + ./QtTestUtil/TestRegistration.h \ + ./QtTestUtil/QtTestUtil.h