diff --git a/include/DtkCore/DLog b/include/DtkCore/DLog index 7888357..0c4a85a 100644 --- a/include/DtkCore/DLog +++ b/include/DtkCore/DLog @@ -1,9 +1,9 @@ -#include "RollingFileAppender.h" -#include "Logger.h" -#include "LogManager.h" -#include "FileAppender.h" -#include "ConsoleAppender.h" -#include "AbstractStringAppender.h" -#include "AbstractAppender.h" -#include "JournalAppender.h" -#include "dloghelper.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include diff --git a/include/log/AbstractAppender.h b/include/log/AbstractAppender.h deleted file mode 100644 index 9435da3..0000000 --- a/include/log/AbstractAppender.h +++ /dev/null @@ -1,40 +0,0 @@ -// SPDX-FileCopyrightText: 2022 UnionTech Software Technology Co., Ltd. -// -// SPDX-License-Identifier: LGPL-3.0-or-later - -#ifndef ABSTRACTAPPENDER_H -#define ABSTRACTAPPENDER_H - -#include "dtkcore_global.h" -#include - -#include - -DCORE_BEGIN_NAMESPACE - -class LIBDTKCORESHARED_EXPORT AbstractAppender -{ -public: - AbstractAppender(); - virtual ~AbstractAppender(); - - Logger::LogLevel detailsLevel() const; - void setDetailsLevel(Logger::LogLevel level); - void setDetailsLevel(const QString &level); - - void write(const QDateTime &time, Logger::LogLevel level, const char *file, int line, - const char *func, const QString &category, const QString &msg); - -protected: - virtual void append(const QDateTime &time, Logger::LogLevel level, const char *file, int line, - const char *func, const QString &category, const QString &msg) = 0; - -private: - QMutex m_writeMutex; - - Logger::LogLevel m_detailsLevel; - mutable QMutex m_detailsLevelMutex; -}; - -DCORE_END_NAMESPACE -#endif // ABSTRACTAPPENDER_H diff --git a/include/log/AbstractStringAppender.h b/include/log/AbstractStringAppender.h deleted file mode 100644 index d8cb34c..0000000 --- a/include/log/AbstractStringAppender.h +++ /dev/null @@ -1,37 +0,0 @@ -// SPDX-FileCopyrightText: 2022 UnionTech Software Technology Co., Ltd. -// -// SPDX-License-Identifier: LGPL-3.0-or-later - -#ifndef ABSTRACTSTRINGAPPENDER_H -#define ABSTRACTSTRINGAPPENDER_H - -#include "AbstractAppender.h" - -#include -#include - -DCORE_BEGIN_NAMESPACE - -class LIBDTKCORESHARED_EXPORT AbstractStringAppender : public AbstractAppender -{ -public: - AbstractStringAppender(); - virtual QString format() const; - void setFormat(const QString &format); - - static QString stripFunctionName(const char *name); -protected: - QString formattedString(const QDateTime &time, Logger::LogLevel level, const char *file, int line, - const char *func, const QString &category, const QString &msg) const; - QString formattedString(const QDateTime &time, Logger::LogLevel level, const char *file, int line, - const char *func, const QString &category, const QString &msg, bool withcolor) const; - -private: - static QByteArray qCleanupFuncinfo(const char*); - - QString m_format; - mutable QReadWriteLock m_formatLock; -}; - -DCORE_END_NAMESPACE -#endif // ABSTRACTSTRINGAPPENDER_H diff --git a/include/log/ConsoleAppender.h b/include/log/ConsoleAppender.h deleted file mode 100644 index be63061..0000000 --- a/include/log/ConsoleAppender.h +++ /dev/null @@ -1,30 +0,0 @@ -// SPDX-FileCopyrightText: 2022 UnionTech Software Technology Co., Ltd. -// -// SPDX-License-Identifier: LGPL-3.0-or-later - -#ifndef CONSOLEAPPENDER_H -#define CONSOLEAPPENDER_H - -#include "dtkcore_global.h" -#include - -DCORE_BEGIN_NAMESPACE - -class LIBDTKCORESHARED_EXPORT ConsoleAppender : public AbstractStringAppender -{ -public: - ConsoleAppender(); - virtual QString format() const; - void ignoreEnvironmentPattern(bool ignore); - -protected: - virtual void append(const QDateTime &time, Logger::LogLevel level, const char *file, int line, - const char *func, const QString &category, const QString &msg); - -private: - bool m_ignoreEnvPattern; -}; - -DCORE_END_NAMESPACE - -#endif // CONSOLEAPPENDER_H diff --git a/include/log/FileAppender.h b/include/log/FileAppender.h deleted file mode 100644 index 9f5e378..0000000 --- a/include/log/FileAppender.h +++ /dev/null @@ -1,43 +0,0 @@ -// SPDX-FileCopyrightText: 2022 UnionTech Software Technology Co., Ltd. -// -// SPDX-License-Identifier: LGPL-3.0-or-later - -#ifndef FILEAPPENDER_H -#define FILEAPPENDER_H - -// Logger -#include "dtkcore_global.h" -#include - -// Qt -#include -#include - -DCORE_BEGIN_NAMESPACE - -class LIBDTKCORESHARED_EXPORT FileAppender : public AbstractStringAppender -{ -public: - FileAppender(const QString &fileName = QString()); - ~FileAppender(); - - QString fileName() const; - void setFileName(const QString &s); - - qint64 size() const; - -protected: - virtual void append(const QDateTime &time, Logger::LogLevel level, const char *file, int line, - const char *func, const QString &category, const QString &msg); - bool openFile(); - void closeFile(); - -private: - QFile m_logFile; - QTextStream m_logStream; - mutable QMutex m_logFileMutex; -}; - -DCORE_END_NAMESPACE - -#endif // FILEAPPENDER_H diff --git a/include/log/JournalAppender.h b/include/log/JournalAppender.h deleted file mode 100644 index 5f089e8..0000000 --- a/include/log/JournalAppender.h +++ /dev/null @@ -1,38 +0,0 @@ -// SPDX-FileCopyrightText: 2023 UnionTech Software Technology Co., Ltd. -// -// SPDX-License-Identifier: LGPL-3.0-or-later - -#ifndef JOURNALAPPENDER_H -#define JOURNALAPPENDER_H - -#include "dtkcore_global.h" -#include - -DCORE_BEGIN_NAMESPACE - -class LIBDTKCORESHARED_EXPORT JournalAppender : public AbstractAppender -{ -public: - JournalAppender() - : AbstractAppender() - { - } - ~JournalAppender() override = default; - using JournalPriority = int; - -protected: - virtual void append(const QDateTime &time, - Logger::LogLevel level, - const char *file, - int line, - const char *func, - const QString &category, - const QString &msg) override; - -private: - bool m_ignoreEnvPattern; -}; - -DCORE_END_NAMESPACE - -#endif // JOURNALAPPENDER_H diff --git a/include/log/Logger.h b/include/log/Logger.h deleted file mode 100644 index a2888d1..0000000 --- a/include/log/Logger.h +++ /dev/null @@ -1,66 +0,0 @@ -// SPDX-FileCopyrightText: 2022 UnionTech Software Technology Co., Ltd. -// -// SPDX-License-Identifier: LGPL-3.0-or-later -#ifndef LOGGER_H -#define LOGGER_H - -#include -#include -#include - -#include "dloggerdefs.h" - -DCORE_BEGIN_NAMESPACE - -class AbstractAppender; -class LoggerPrivate; -class LIBDTKCORESHARED_EXPORT Logger -{ - Q_DISABLE_COPY(Logger) -public: - //!@~english the log levels - enum LogLevel { - Trace, //!<@~english Trace level. Can be used for mostly unneeded records used for internal code tracing. - Debug, //!<@~english Debug level.for the debugging of the software. - Info, //!<@~english Info level. Can be used for informational records, which may be interesting for not only developers. - Warning, //!<@~english Warning. May be used to log some non-fatal warnings detected by your application. - Error, //!<@~english May be used for a big problems making your application work wrong but not crashing. - Fatal //!<@~english Fatal. Used for unrecoverable errors, crashes the application (abort) right after the log record is written. - }; - - Logger(); - Logger(const QString &defaultCategory); - ~Logger(); - - static Logger *globalInstance(); - - static QString levelToString(LogLevel level); - static LogLevel levelFromString(const QString &str); - - void registerAppender(AbstractAppender *appender); - void registerCategoryAppender(const QString &category, AbstractAppender *appender); -#if DTK_VERSION < DTK_VERSION_CHECK(6, 0, 0, 0) - QT_DEPRECATED_X("no longer take effect") void logToGlobalInstance(const QString &category, bool logToGlobal = false); -#endif - void setDefaultCategory(const QString &category); - QString defaultCategory() const; - - void write(const QDateTime &time, LogLevel level, const char *file, int line, - const char *func, const char *category, const QString &msg); - void write(LogLevel level, const char *file, int line, - const char *func, const char *category, const QString &msg); - QDebug write(LogLevel level, const char *file, int line, - const char *func, const char *category); - void writeAssert(const char *file, int line, - const char *func, const char *condition); - -private: - void write(const QDateTime &time, LogLevel level, const char *file, int line, - const char *func, const char *category, - const QString &msg, bool fromLocalInstance); - Q_DECLARE_PRIVATE(Logger) - LoggerPrivate *d_ptr; -}; - -DCORE_END_NAMESPACE -#endif // LOGGER_H diff --git a/include/log/RollingFileAppender.h b/include/log/RollingFileAppender.h deleted file mode 100644 index 044ed1d..0000000 --- a/include/log/RollingFileAppender.h +++ /dev/null @@ -1,71 +0,0 @@ -// Copyright (C) 2017 ~ 2017 Deepin Technology Co., Ltd. -// SPDX-FileCopyrightText: 2022 UnionTech Software Technology Co., Ltd. -// -// SPDX-License-Identifier: LGPL-3.0-or-later - -#ifndef ROLLINGFILEAPPENDER_H -#define ROLLINGFILEAPPENDER_H - -#include - -#include - -DCORE_BEGIN_NAMESPACE - -class LIBDTKCORESHARED_EXPORT RollingFileAppender : public FileAppender -{ - public: - /*! - @~english - The enum DatePattern defines constants for date patterns. - \sa setDatePattern(DatePattern) - */ - enum DatePattern - { - - MinutelyRollover = 0,/*!<@~english The minutely date pattern string is "'.'yyyy-MM-dd-hh-mm". */ - HourlyRollover,/*!<@~english The hourly date pattern string is "yyyy-MM-dd-hh". */ - HalfDailyRollover,/*!<@~english The half-daily date pattern string is "'.'yyyy-MM-dd-a". */ - DailyRollover,/*!<@~english The daily date pattern string is "'.'yyyy-MM-dd". */ - WeeklyRollover,/*!<@~english The weekly date pattern string is "'.'yyyy-ww". */ - MonthlyRollover/*!<@~english The monthly date pattern string is "'.'yyyy-MM". */ - }; - - RollingFileAppender(const QString &fileName = QString()); - - DatePattern datePattern() const; - void setDatePattern(DatePattern datePattern); - QT_DEPRECATED_X("use setDatePattern(DatePattern)") void setDatePattern(const QString &datePattern); - - QT_DEPRECATED_X("use datePattern(DatePattern)") QString datePatternString() const; - - void setLogFilesLimit(int limit); - int logFilesLimit() const; - - void setLogSizeLimit(int limit); - qint64 logSizeLimit() const; - - protected: - virtual void append(const QDateTime &time, Logger::LogLevel level, const char *file, int line, - const char *func, const QString &category, const QString &msg); - - private: - void rollOver(); - void computeRollOverTime(); - void computeFrequency(); - void removeOldFiles(); - void setDatePatternString(const QString &datePatternString); - - QString m_datePatternString; - DatePattern m_frequency; - - QDateTime m_rollOverTime; - QString m_rollOverSuffix; - int m_logFilesLimit; - qint64 m_logSizeLimit; - mutable QMutex m_rollingMutex; -}; - -DCORE_END_NAMESPACE - -#endif // ROLLINGFILEAPPENDER_H diff --git a/include/log/dloggerdefs.h b/include/log/dloggerdefs.h deleted file mode 100644 index cce2654..0000000 --- a/include/log/dloggerdefs.h +++ /dev/null @@ -1,42 +0,0 @@ -// SPDX-FileCopyrightText: 2022 UnionTech Software Technology Co., Ltd. -// -// SPDX-License-Identifier: LGPL-3.0-or-later -#ifndef DLOGGER_DEFINE_H -#define DLOGGER_DEFINE_H - -#include "dtkcore_global.h" -#include - -DCORE_BEGIN_NAMESPACE - -class Logger; -class DLogHelper; -LIBDTKCORESHARED_EXPORT Logger *loggerInstance(); -#define dlogger loggerInstance() - -#define DLOG_CTX(category) QMessageLogContext(__FILE__, __LINE__, Q_FUNC_INFO, category) - -// include DLog or dloghelper.h -#define dTrace DLogHelper(Logger::Trace, DLOG_CTX("default")).write -#define dDebug DLogHelper(Logger::Debug, DLOG_CTX("default")).write -#define dInfo DLogHelper(Logger::Info, DLOG_CTX("default")).write -#define dWarning DLogHelper(Logger::Warning, DLOG_CTX("default")).write -#define dError DLogHelper(Logger::Error, DLOG_CTX("default")).write -#define dFatal DLogHelper(Logger::Fatal, DLOG_CTX("default")).write - -#define dCDebug(category) DLogHelper(Logger::Debug, DLOG_CTX(category)).write() -#define dCInfo(category) DLogHelper(Logger::Info, DLOG_CTX(category)).write() -#define dCWarning(category) DLogHelper(Logger::Warning, DLOG_CTX(category)).write() -#define dCError(category) DLogHelper(Logger::Error, DLOG_CTX(category)).write() -#define dCFatal(category) DLogHelper(Logger::Fatal, DLOG_CTX(category)).write() - -#define dTraceTime DLogHelper helper(Logger::Trace, DLOG_CTX("default")); helper.timing -#define dDebugTime DLogHelper helper(Logger::Debug, DLOG_CTX("default")); helper.timing -#define dInfoTime DLogHelper helper(Logger::Info, DLOG_CTX("default")); helper.timing - -#define dAssert(cond) ((!(cond)) ? loggerInstance()->writeAssert(__FILE__, __LINE__, Q_FUNC_INFO, #cond) : qt_noop()) -#define dAssertX(cond, msg) ((!(cond)) ? loggerInstance()->writeAssert(__FILE__, __LINE__, Q_FUNC_INFO, msg) : qt_noop()) - -DCORE_END_NAMESPACE - -#endif // DLOGGER_DEFINE_H diff --git a/include/log/dloghelper.h b/include/log/dloghelper.h deleted file mode 100644 index cb3ecd6..0000000 --- a/include/log/dloghelper.h +++ /dev/null @@ -1,37 +0,0 @@ -// SPDX-FileCopyrightText: 2023 UnionTech Software Technology Co., Ltd. -// -// SPDX-License-Identifier: LGPL-3.0-or-later - -#ifndef DLOGHELPER_H -#define DLOGHELPER_H - -#include -#include "Logger.h" - -#include -#include - -DCORE_BEGIN_NAMESPACE -class DLogHelperPrivate; -class LIBDTKCORESHARED_EXPORT DLogHelper : public QObject -{ - Q_DISABLE_COPY(DLogHelper) -public: - DLogHelper(Logger::LogLevel level, const QMessageLogContext &context, QObject *parent = nullptr); - ~DLogHelper(); - - void write(const char* msg, ...) Q_ATTRIBUTE_FORMAT_PRINTF(2, 3); - void write(const QString& msg); - QDebug write(); - - void timing(const QString& msg, QObject *context = nullptr); - - static Logger::LogLevel levelFromQtMsgType(QtMsgType mt); - static QtMsgType qtMsgTypeFromLogLevel(Logger::LogLevel lvl); - - Q_DECLARE_PRIVATE(DLogHelper) -}; - -DCORE_END_NAMESPACE - -#endif // DLOGHELPER_H diff --git a/include/log/win32/OutputDebugAppender.h b/include/log/win32/OutputDebugAppender.h deleted file mode 100644 index 11c5b3e..0000000 --- a/include/log/win32/OutputDebugAppender.h +++ /dev/null @@ -1,22 +0,0 @@ -// SPDX-FileCopyrightText: 2022 UnionTech Software Technology Co., Ltd. -// -// SPDX-License-Identifier: LGPL-3.0-or-later - -#ifndef OUTPUTDEBUGAPPENDER_H -#define OUTPUTDEBUGAPPENDER_H - -#include "dtkcore_global.h" -#include - -DCORE_BEGIN_NAMESPACE - -class LIBDTKCORESHARED_EXPORT OutputDebugAppender : public AbstractStringAppender -{ - protected: - virtual void append(const QDateTime &time, Logger::LogLevel level, const char *file, int line, - const char *func, const QString &category, const QString &msg); -}; - -DCORE_END_NAMESPACE - -#endif // OUTPUTDEBUGAPPENDER_H diff --git a/misc/DtkCoreConfig.cmake.in b/misc/DtkCoreConfig.cmake.in index 856554e..fb6351e 100644 --- a/misc/DtkCoreConfig.cmake.in +++ b/misc/DtkCoreConfig.cmake.in @@ -6,6 +6,7 @@ endif() include(CMakeFindDependencyMacro) find_dependency(Qt@QT_VERSION_MAJOR@Core) find_dependency(Qt@QT_VERSION_MAJOR@Xml) +find_dependency(DLog) if (LINUX) find_dependency(Qt@QT_VERSION_MAJOR@DBus) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 2cb7bf4..ca3c5d5 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -7,6 +7,7 @@ set(CMAKE_AUTOUIC ON) set(CMAKE_AUTORCC ON) find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS Core) +find_package(DLog REQUIRED) if(LINUX) find_package(PkgConfig REQUIRED) find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS DBus) @@ -14,9 +15,6 @@ if(LINUX) pkg_check_modules(QGSettings REQUIRED IMPORTED_TARGET gsettings-qt) #Dtk6 removed. endif() - if(BUILD_WITH_SYSTEMD) - pkg_check_modules(Systemd REQUIRED IMPORTED_TARGET libsystemd) - endif() endif() find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS Xml) find_package(DtkBuildHelper REQUIRED) @@ -39,7 +37,6 @@ include(filesystem/filesystem.cmake) #end filesystem # start log include(log/log.cmake) -find_package(spdlog REQUIRED) #end log # start settings include(settings/settings.cmake) @@ -67,24 +64,18 @@ if(LINUX) Qt${QT_VERSION_MAJOR}::Core Qt${QT_VERSION_MAJOR}::DBus Qt${QT_VERSION_MAJOR}::Xml + Dtk::DLog ) target_link_libraries(${LIB_NAME} PRIVATE ICU::uc Qt${QT_VERSION_MAJOR}::CorePrivate uchardet - spdlog::spdlog ) if("${QT_VERSION_MAJOR}" STREQUAL "5") target_link_libraries(${LIB_NAME} PRIVATE PkgConfig::QGSettings ) endif() - if(BUILD_WITH_SYSTEMD) - target_link_libraries(${LIB_NAME} PRIVATE - PkgConfig::Systemd - ) - add_definitions(-DBUILD_WITH_SYSTEMD) - endif() else() add_library(${LIB_NAME} SHARED @@ -105,7 +96,6 @@ else() ICU::uc Qt${QT_VERSION_MAJOR}::CorePrivate uchardet - spdlog::spdlog ) if("${QT_VERSION_MAJOR}" STREQUAL "5") target_link_libraries(${LIB_NAME} PRIVATE diff --git a/src/log/AbstractAppender.cpp b/src/log/AbstractAppender.cpp deleted file mode 100644 index 61fc2a2..0000000 --- a/src/log/AbstractAppender.cpp +++ /dev/null @@ -1,167 +0,0 @@ -// SPDX-FileCopyrightText: 2022 UnionTech Software Technology Co., Ltd. -// -// SPDX-License-Identifier: LGPL-3.0-or-later - -#include "AbstractAppender.h" - -DCORE_BEGIN_NAMESPACE - -/*! -@~english - \class Dtk::Core::AbstractAppender - \inmodule dtkcore - - \brief The AbstractAppender class provides an abstract base class for writing a log entries. - - The AbstractAppender class is the base interface class for all log appenders that could be used with Logger. - - AbstractAppender provides a common implementation for the thread safe, mutex-protected logging of application - messages, such as ConsoleAppender, FileAppender or something else. AbstractAppender is abstract and can not be - instantiated, but you can use any of its subclasses or create a custom log appender at your choice. - - Appenders are the logical devices that is aimed to be attached to Logger object by calling - Logger::registerAppender(). On each log record call from the application Logger object sequentially calls write() - function on all the appenders registered in it. - - You can subclass AbstractAppender to implement a logging target of any kind you like. It may be the external logging - subsystem (for example, syslog in *nix), XML file, SQL database entries, D-Bus messages or anything else you can - imagine. - - For the simple non-structured plain text logging (for example, to a plain text file or to the console output) you may - like to subclass the AbstractStringAppender instead of AbstractAppender, which will give you a more convenient way to - control the format of the log output. - - \sa AbstractStringAppender - \sa Logger::registerAppender() - */ - - -/*! -@~english - \brief Constructs a AbstractAppender object. - */ -AbstractAppender::AbstractAppender() - :m_detailsLevel(Logger::Debug) -{ - -} - -/*! -@~english - \brief Destructs the AbstractAppender object. - */ -AbstractAppender::~AbstractAppender() -{ - -} - -/*! -@~english - \brief Returns the current details level of appender. - - Log records with a log level lower than a current detailsLevel() will be silently ignored by appender and would not - be sent to its append() function. - - It provides additional logging flexibility, allowing you to set the different severity levels for different types - of logs. - - \note This function is thread safe. - - \return The log level. - - \sa setDetailsLevel() - \sa Logger::LogLevel - */ -Logger::LogLevel AbstractAppender::detailsLevel() const -{ - QMutexLocker locker(&m_detailsLevelMutex); - return m_detailsLevel; -} - -/*! -@~english - \brief Sets the current details level of appender. - - Default details \a level is Logger::Debug - - \note This function is thread safe. - - \sa detailsLevel() - \sa Logger::LogLevel - */ -void Dtk::Core::AbstractAppender::setDetailsLevel(Logger::LogLevel level) -{ - QMutexLocker locker(&m_detailsLevelMutex); - m_detailsLevel = level; -} - -/*! -@~english - \brief Sets the current details \a level of appender. - - This function is provided for convenience, it behaves like an above function. - - \sa detailsLevel() - \sa Logger::LogLevel - */ -void AbstractAppender::setDetailsLevel(const QString &level) -{ - setDetailsLevel(Logger::levelFromString(level)); -} - -/*! -@~english - \brief Tries to write the log record to this logger. - - This is the function called by Logger object to write a log \a message to the appender. - - The \a time parameter indicates the time stamp. - The \a level parameter describes the LogLevel. - The \a file parameter is the current file name. - The \a line parameter indicates the number of lines to output. - The \a func parameter indicates the function name to output. - The \a category parameter indicates the log category. - The \a msg parameter indicates the output message. - - \note This function is thread safe. - - \sa Logger::write() - \sa detailsLevel() - */ -void AbstractAppender::write(const QDateTime &time, Logger::LogLevel level, const char *file, int line, const char *func, const QString &category, const QString &msg) -{ - if (level < detailsLevel()) - return; - - QMutexLocker locker(&m_writeMutex); - append(time, level, file, line, func, category, msg); -} - -/*! -@~english - \fn virtual void AbstractAppender::append(const QDateTime &timeStamp, Logger::LogLevel level, const char *file, int line, - const char *function, const QString &category, const QString &message) = 0 - - \brief Writes the log record to the logger instance - - This function is called every time when user tries to write a message to this AbstractAppender instance using - the write() function. Write function works as proxy and transfers only the messages with log level more or equal - to the current logLevel(). - - Overload this function when you are implementing a custom appender. - - The \a time parameter indicates the time stamp. - The \a level parameter describes the LogLevel. - The \a file parameter is the current file name. - The \a line parameter indicates the number of lines to output. - The \a func parameter indicates the function name to output. - The \a category parameter indicates the log category. - The \a msg parameter indicates the output message. - - \note This function is not needed to be thread safe because it is never called directly by Logger object. The - write() function works as a proxy and protects this function from concurrent access. - - \sa Logger::write() - */ - -DCORE_END_NAMESPACE diff --git a/src/log/AbstractStringAppender.cpp b/src/log/AbstractStringAppender.cpp deleted file mode 100644 index 8cf3518..0000000 --- a/src/log/AbstractStringAppender.cpp +++ /dev/null @@ -1,481 +0,0 @@ -// SPDX-FileCopyrightText: 2022 UnionTech Software Technology Co., Ltd. -// -// SPDX-License-Identifier: LGPL-3.0-or-later - -#include "AbstractStringAppender.h" - -#include -#include -#include - -DCORE_BEGIN_NAMESPACE - -inline static QString formattedLevelWithColor(Logger::LogLevel level, QString &msg) { - switch (level) { - case Logger::Trace: - return QString("\x1b[94m%1\x1b[0m").arg(msg); - case Logger::Debug: - return QString("\x1b[36m%1\x1b[0m").arg(msg); - case Logger::Info: - return QString("\x1b[32m%1\x1b[0m").arg(msg); - case Logger::Warning: - return QString("\x1b[33m%1\x1b[0m").arg(msg); - case Logger::Error: - return QString("\x1b[31m%1\x1b[0m").arg(msg); - case Logger::Fatal: - return QString("\x1b[35m%1\x1b[0m").arg(msg); - default: - break; - } - return msg; -} - -/*! -@~english - \class Dtk::Core::AbstractStringAppender - \inmodule dtkcore - - \brief The AbstractStringAppender class provides a convenient base for appenders working with plain text formatted - logs. - - AbstractSringAppender is the simple extension of the AbstractAppender class providing the convenient way to create - custom log appenders working with a plain text formatted log targets. - - It have the formattedString() protected function that formats the logging arguments according to a format set with - setFormat(). - - This class can not be directly instantiated because it contains pure virtual function inherited from AbstractAppender - class. - - For more detailed description of customizing the log output format see the documentation on the setFormat() function. - */ - -const char formattingMarker = '%'; - -/*! -@~english - \brief Constructs a new string appender object. - */ -AbstractStringAppender::AbstractStringAppender() - : m_format(QLatin1String("%{time}{yyyy-MM-ddTHH:mm:ss.zzz} [%{type:-7}] <%{function}> %{message}\n")) -{ - -} - -/*! -@~english - \brief Returns the current log format string. - - The default format is set to "%{time}{yyyy-MM-ddTHH:mm:ss.zzz} [%{type:-7}] <%{function}> %{message}\n". You can set a different log record - format using the setFormat() function. - - \sa setFormat(const QString&) - */ -QString AbstractStringAppender::format() const -{ - QReadLocker locker(&m_formatLock); - return m_format; -} - -/*! -@~english - \brief Sets the logging format for writing strings to the log target with this appender. - - The string format seems to be very common to those developers who have used a standard sprintf function. - - Log output format is a simple QString with the special markers (starting with % sign) which will be replaced with - it's internal meaning when writing a log record. - - Controlling marker begins with the percent sign (%) which is followed by the command inside {} brackets - (the command describes, what will be put to log record instead of marker). - Optional field width argument may be specified right after the command (through the colon symbol before the closing bracket) - Some commands requires an additional formatting argument (in the second {} brackets). - - Field width argument works almost identically to the QString::arg() fieldWidth argument (and uses it - internally). For example, "%{type:-7}" will be replaced with the left padded debug level of the message - ("Debug ") or something. For the more detailed description of it you may consider to look to the Qt - Reference Documentation. - - Supported marker commands are: - \list - \li %{time} - timestamp. You may specify your custom timestamp \a format using the second {} brackets after the marker, - \li timestamp \a format here will be similar to those used in QDateTime::toString() function. For example, - \li "%{time}{dd-MM-yyyy, HH:mm}" may be replaced with "17-12-2010, 20:17" depending on current date and time. - \li The default \a format used here is "HH:mm:ss.zzz". - \li %{type} - Log level. Possible log levels are shown in the Logger::LogLevel enumerator. - \li %{Type} - Uppercased log level. - \li %{typeOne} - One letter log level. - \li %{TypeOne} - One uppercase letter log level. - \li %{File} - Full source file name (with path) of the file that requested log recording. Uses the __FILE__ preprocessor macro. - \li %{file} - Short file name (with stripped path). - \li %{line} - Line number in the source file. Uses the __LINE__ preprocessor macro. - \li %{Function} - Name of function that called on of the LOG_* macros. Uses the Q_FUNC_INFO macro provided with Qt. - \li %{function} - Similar to the %{Function}, but the function name is stripped using stripFunctionName - \li %{message} - The log message sent by the caller. - \li %{category} - The log category. - \li %{appname} - Application name (returned by QCoreApplication::applicationName() function). - \li %{pid} - Application pid (returned by QCoreApplication::applicationPid() function). - \li %{threadid} - ID of current thread. - \li %% - Convinient marker that is replaced with the single % mark. - \endlist - - \note Format doesn't add '\\n' to the end of the \a format line. Please consider adding it manually. - - \sa format() - \sa stripFunctionName() - \sa Logger::LogLevel - */ -void AbstractStringAppender::setFormat(const QString &format) -{ - QWriteLocker locker(&m_formatLock); - m_format = format; -} - -/*! -@~english - \brief Strips the long function signature (as added by Q_FUNC_INFO macro). - - The string processing drops the returning type, arguments and template parameters of function. It is definitely - useful for enchancing the log output readability. - - The \a name parameter is the function name. - - \return stripped function name - */ -QString AbstractStringAppender::stripFunctionName(const char *name) -{ - return QString::fromLatin1(qCleanupFuncinfo(name)); -} - -// The function was backported from Qt5 sources (qlogging.h) -QByteArray AbstractStringAppender::qCleanupFuncinfo(const char *name) -{ - QByteArray info(name); - - // Strip the function info down to the base function name - // note that this throws away the template definitions, - // the parameter types (overloads) and any const/volatile qualifiers. - if (info.isEmpty()) - return info; - - int pos; - - // skip trailing [with XXX] for templates (gcc) - pos = info.size() - 1; - if (info.endsWith(']')) { - while (--pos) { - if (info.at(pos) == '[') - info.truncate(pos); - } - } - - bool hasLambda = false; - QRegularExpression lambdaRegex("::"); - QRegularExpressionMatch match = lambdaRegex.match(QString::fromLatin1(info)); - if (match.hasMatch()) { - hasLambda = true; - info.remove(match.capturedStart(), match.capturedLength()); - } - - // operator names with '(', ')', '<', '>' in it - static const char operator_call[] = "operator()"; - static const char operator_lessThan[] = "operator<"; - static const char operator_greaterThan[] = "operator>"; - static const char operator_lessThanEqual[] = "operator<="; - static const char operator_greaterThanEqual[] = "operator>="; - - // canonize operator names - info.replace("operator ", "operator"); - - // remove argument list - Q_FOREVER { - int parencount = 0; - pos = info.lastIndexOf(')'); - if (pos == -1) { - // Don't know how to parse this function name - return info; - } - - // find the beginning of the argument list - --pos; - ++parencount; - while (pos && parencount) { - if (info.at(pos) == ')') - ++parencount; - else if (info.at(pos) == '(') - --parencount; - --pos; - } - if (parencount != 0) - return info; - - info.truncate(++pos); - - if (info.at(pos - 1) == ')') { - if (info.indexOf(operator_call) == pos - (int)strlen(operator_call)) - break; - - // this function returns a pointer to a function - // and we matched the arguments of the return type's parameter list - // try again - info.remove(0, info.indexOf('(')); - info.chop(1); - continue; - } else { - break; - } - } - - if (hasLambda) - info.append("::lambda"); - - // find the beginning of the function name - int parencount = 0; - int templatecount = 0; - --pos; - - // make sure special characters in operator names are kept - if (pos > -1) { - switch (info.at(pos)) { - case ')': - if (info.indexOf(operator_call) == pos - (int)strlen(operator_call) + 1) - pos -= 2; - break; - case '<': - if (info.indexOf(operator_lessThan) == pos - (int)strlen(operator_lessThan) + 1) - --pos; - break; - case '>': - if (info.indexOf(operator_greaterThan) == pos - (int)strlen(operator_greaterThan) + 1) - --pos; - break; - case '=': { - int operatorLength = (int)strlen(operator_lessThanEqual); - if (info.indexOf(operator_lessThanEqual) == pos - operatorLength + 1) - pos -= 2; - else if (info.indexOf(operator_greaterThanEqual) == pos - operatorLength + 1) - pos -= 2; - break; - } - default: - break; - } - } - - while (pos > -1) { - if (parencount < 0 || templatecount < 0) - return info; - - char c = info.at(pos); - if (c == ')') - ++parencount; - else if (c == '(') - --parencount; - else if (c == '>') - ++templatecount; - else if (c == '<') - --templatecount; - else if (c == ' ' && templatecount == 0 && parencount == 0) - break; - - --pos; - } - info = info.mid(pos + 1); - - // remove trailing '*', '&' that are part of the return argument - while ((info.at(0) == '*') - || (info.at(0) == '&')) - info = info.mid(1); - - // we have the full function name now. - // clean up the templates - while ((pos = info.lastIndexOf('>')) != -1) { - if (!info.contains('<')) - break; - - // find the matching close - int end = pos; - templatecount = 1; - --pos; - while (pos && templatecount) { - const char c = info.at(pos); - if (c == '>') - ++templatecount; - else if (c == '<') - --templatecount; - --pos; - } - ++pos; - info.remove(pos, end - pos + 1); - } - - return info; -} - -QString AbstractStringAppender::formattedString(const QDateTime &time, Logger::LogLevel level, - const char *file, int line, const char *func, - const QString &category, const QString &msg ) const { - return formattedString(time, level, file, line, func, category, msg, false); -} - -/*! -@~english - \brief Returns the string to record to the logging target, formatted according to the format(). - - \a time The time stamp. - The \a level parameter describes the LogLevel, and the \a file parameter is the current file name, - and the \a line parameter indicates the number of lines to output. - The \a func parameter indicates the function name to output. - The \a category parameter indicates the log category. - The \a msg parameter indicates the output message. - The \a withcolor parameter indicates wether to add color to output - - \sa format() - \sa setFormat(const QString&) - */ -QString AbstractStringAppender::formattedString(const QDateTime &time, Logger::LogLevel level, - const char *file, int line, const char *func, - const QString &category, const QString &msg, - bool withcolor) const -{ - QString f = format(); - - // dtkcore无法正确解析Qt的日志格式,dtk默认的日志格式并未和Qt统一,解析方式需要兼容两种不同的格式。 - if (f.contains(QLatin1String("time "))) - f.replace(f.indexOf(' ', f.indexOf(QLatin1String("time")) + QLatin1String("time").size()), 1, QLatin1String("}{")); - - const int size = f.size(); - - QString result; - - int i = 0; - while (i < f.size()) { - QChar c = f.at(i); - - // We will silently ignore the broken % marker at the end of string - if (c != QLatin1Char(formattingMarker) || (i + 2) >= size) { - result.append(c); - } else { - i += 2; - QChar currentChar = f.at(i); - QString command; - int fieldWidth = 0; - - if (currentChar.isLetter()) { - command.append(currentChar); - int j = 1; - while ((i + j) < size && f.at(i + j).isLetter()) { - command.append(f.at(i+j)); - j++; - } - - i+=j; - currentChar = f.at(i); - - // Check for the padding instruction - if (currentChar == QLatin1Char(':')) { - currentChar = f.at(++i); - if (currentChar.isDigit() || currentChar.category() == QChar::Punctuation_Dash) { - int j = 1; - while ((i + j) < size && f.at(i + j).isDigit()) j++; - - fieldWidth = f.mid(i, j).toInt(); - i += j; - } - } - } - - // Log record chunk to insert instead of formatting instruction - QString chunk; - - // Time stamp - if (command == QLatin1String("time")) { - if (f.at(i + 1) == QLatin1Char('{')) { - int j = 1; - while ((i + 2 + j) < size && f.at(i + 2 + j) != QLatin1Char('}')) j++; - - if ((i + 2 + j) < size) { - chunk = time.toString(f.mid(i + 2, j)); - - i += j; - i += 2; - } - } - - if (chunk.isNull()) - chunk = time.toString(QLatin1String("HH:mm:ss.zzz")); - - } else if (command == QLatin1String("type")) { - // Log level - chunk = Logger::levelToString(level); - if (withcolor) { - chunk = formattedLevelWithColor(level, chunk); - } - } else if (command == QLatin1String("Type")) { - // Uppercased log level - chunk = Logger::levelToString(level).toUpper(); - if (withcolor) { - chunk = formattedLevelWithColor(level, chunk); - } - } else if (command == QLatin1String("typeOne")) { - // One letter log level - chunk = Logger::levelToString(level).left(1).toLower(); - if (withcolor) { - chunk = formattedLevelWithColor(level, chunk); - } - } else if (command == QLatin1String("TypeOne")) { - // One uppercase letter log level - chunk = Logger::levelToString(level).left(1).toUpper(); - if (withcolor) { - chunk = formattedLevelWithColor(level, chunk); - } - } else if (command == QLatin1String("File")) { - // Filename - chunk = QLatin1String(file); - } else if (command == QLatin1String("file")) { - // Filename without a path - chunk = QString(QLatin1String(file)).section('/', -1); - } else if (command == QLatin1String("line")) { - // Source line number - chunk = QString::number(line); - } else if (command == QLatin1String("Function")) { - // Function name, as returned by Q_FUNC_INFO - chunk = QString::fromLatin1(func); - } else if (command == QLatin1String("function")) { - // Stripped function name - chunk = stripFunctionName(func); - } else if (command == QLatin1String("message")) { - // Log message - chunk = msg; - } else if (command == QLatin1String("category")) { - // Log message - chunk = category; - } else if (command == QLatin1String("pid")) { - // Application pid - chunk = QString::number(QCoreApplication::applicationPid()); - } else if (command == QLatin1String("appname")) { - // Application name - chunk = QCoreApplication::applicationName(); - } else if (command == QLatin1String("threadid")) { - // Thread ID (duplicates Qt5 threadid debbuging way) - chunk = QLatin1String("0x") + QString::number(qlonglong(QThread::currentThread()->currentThread()), 16); - } else if (command == QString(formattingMarker)) { - // We simply replace the double formatting marker (%) with one - chunk = QLatin1Char(formattingMarker); - } else { - // Do not process any unknown commands - chunk = QString(formattingMarker); - chunk.append(command); - } - - if (!chunk.isEmpty() && chunk != "0") { - result.append(QString(QLatin1String("%1")).arg(chunk, fieldWidth)); - } - } - ++i; - } - - return result; -} - -DCORE_END_NAMESPACE diff --git a/src/log/ConsoleAppender.cpp b/src/log/ConsoleAppender.cpp deleted file mode 100644 index 6969b5b..0000000 --- a/src/log/ConsoleAppender.cpp +++ /dev/null @@ -1,88 +0,0 @@ -// SPDX-FileCopyrightText: 2022 UnionTech Software Technology Co., Ltd. -// -// SPDX-License-Identifier: LGPL-3.0-or-later - -// Local - -#include "ConsoleAppender.h" - -#include -#include -#include -#include -#include - -// STL -#include -extern "C" { -#include -} - -DCORE_BEGIN_NAMESPACE - -/*! -@~english - @class Dtk::Core::ConsoleAppender - @ingroup dlog - - @brief ConsoleAppender is the simple appender that writes the log records to the std::cerr output stream. - - ConsoleAppender uses "[%{type:-7}] <%{function}> %{message}\n" as a default output format. It is similar to the - AbstractStringAppender but doesn't show a time. - - You can modify ConsoleAppender output format without modifying your code by using \c QT_MESSAGE_PATTERN environment - variable. If you need your application to ignore this environment variable you can call - ConsoleAppender::ignoreEnvironmentPattern(true) - */ - - -ConsoleAppender::ConsoleAppender() - : AbstractStringAppender() - , m_ignoreEnvPattern(false) -{ - if (!spdlog::get("console")) { - auto clogger = spdlog::stdout_color_mt("console"); - clogger->set_level(spdlog::level::level_enum(detailsLevel())); - } -} - - -QString ConsoleAppender::format() const -{ - const QString envPattern = QString::fromLocal8Bit(qgetenv("QT_MESSAGE_PATTERN")); - return (m_ignoreEnvPattern || envPattern.isEmpty()) ? AbstractStringAppender::format() : (envPattern + "\n"); -} - - -void ConsoleAppender::ignoreEnvironmentPattern(bool ignore) -{ - m_ignoreEnvPattern = ignore; -} - -/*! -@~english - \brief Writes the log record to the std::cerr stream. - \reimp - - The \a time parameter indicates the time stamp. - The \a level parameter describes the LogLevel. - The \a file parameter is the current file name. - The \a line parameter indicates the number of lines to output. - The \a func parameter indicates the function name to output. - The \a category parameter indicates the log category. - The \a msg parameter indicates the output message. - - \sa AbstractStringAppender::format() - */ -void ConsoleAppender::append(const QDateTime &time, Logger::LogLevel level, const char *file, int line, - const char *func, const QString &category, const QString &msg) -{ - auto clogger = spdlog::get("console"); - Q_ASSERT(clogger); - clogger->set_level(spdlog::level::level_enum(detailsLevel())); - - const auto &formatted = formattedString(time, level, file, line, func, category, msg, isatty(STDOUT_FILENO)); - clogger->log(spdlog::level::level_enum(level), formatted.toStdString()); -} - -DCORE_END_NAMESPACE diff --git a/src/log/FileAppender.cpp b/src/log/FileAppender.cpp deleted file mode 100644 index b8ca2bf..0000000 --- a/src/log/FileAppender.cpp +++ /dev/null @@ -1,131 +0,0 @@ -// SPDX-FileCopyrightText: 2022 UnionTech Software Technology Co., Ltd. -// -// SPDX-License-Identifier: LGPL-3.0-or-later - -#include "FileAppender.h" - -#include - -#include "rollingfilesink_p.h" - -#include - -DCORE_BEGIN_NAMESPACE - -std::string loggerName(const QFile &logFile) -{ - return QFileInfo(logFile).fileName().toStdString(); -} -/*! -@~english - @class Dtk::Core::FileAppender - @ingroup dtkcore - - @brief Simple appender that writes the log records to the plain text file. - */ - - -/*! -@~english - @brief Constructs the new file appender assigned to file with the given \a fileName. - */ -FileAppender::FileAppender(const QString &fileName) -{ - setFileName(fileName); -} - - -FileAppender::~FileAppender() -{ - closeFile(); -} - -/*! -@~english - \brief Returns the name set by setFileName() or to the FileAppender constructor. - - \sa setFileName() - */ -QString FileAppender::fileName() const -{ - QMutexLocker locker(&m_logFileMutex); - return m_logFile.fileName(); -} - -/*! - \brief Sets the \a s name of the file. The name can have no path, a relative path, or an absolute path. - - \sa fileName() - */ -void FileAppender::setFileName(const QString &s) -{ - QMutexLocker locker(&m_logFileMutex); - - if (s == m_logFile.fileName()) - return; - - closeFile(); - - m_logFile.setFileName(s); - - if (!spdlog::get(loggerName(s))) - rolling_logger_mt(loggerName(s), - m_logFile.fileName().toStdString(), - 1024 * 1024 * 20, 0); -} - -qint64 FileAppender::size() const -{ - QMutexLocker locker(&m_logFileMutex); - - if (auto *bs = get_sink(loggerName(m_logFile))){ - return qint64(bs->filesize()); - } - - return m_logFile.size(); -} - -bool FileAppender::openFile() -{ - auto fl = spdlog::get(loggerName(m_logFile)); - - return fl.get(); -} - -/*! -@~english - \brief Write the log record to the file. - \reimp - - The \a time parameter indicates the time stamp. - The \a level parameter describes the LogLevel. - The \a file parameter is the current file name. - The \a line parameter indicates the number of lines to output. - The \a func parameter indicates the func name to output. - The \a category parameter indicates the log category. - The \a msg parameter indicates the output message. - - \sa fileName() - \sa AbstractStringAppender::format() - */ -void FileAppender::append(const QDateTime &time, Logger::LogLevel level, const char *file, int line, - const char *func, const QString &category, const QString &msg) -{ - - if (!openFile()) - return; - - auto fl = spdlog::get(loggerName(m_logFile)); - fl->set_level(spdlog::level::level_enum(detailsLevel())); - - const auto &formatted = formattedString(time, level, file, line, func, category, msg); - fl->log(spdlog::level::level_enum(level), formatted.toStdString()); - fl->flush(); -} - -void FileAppender::closeFile() -{ - spdlog::drop(loggerName(m_logFile)); -} - -DCORE_END_NAMESPACE diff --git a/src/log/JournalAppender.cpp b/src/log/JournalAppender.cpp deleted file mode 100644 index de96e80..0000000 --- a/src/log/JournalAppender.cpp +++ /dev/null @@ -1,67 +0,0 @@ -// SPDX-FileCopyrightText: 2022 UnionTech Software Technology Co., Ltd. -// -// SPDX-License-Identifier: LGPL-3.0-or-later -#include "JournalAppender.h" - -#define SD_JOURNAL_SUPPRESS_LOCATION -#include -DCORE_BEGIN_NAMESPACE - -/** - * @~english - * @brief it can be used to send log to journal - * @param time journal time - * @param level log level - * @param file - * @param line Number of lines of code when writing to the log - * @param func function name - * @param category log category - * @param msg log message - */ -void JournalAppender::append(const QDateTime &time, - Logger::LogLevel level, - const char *file, - int line, - const char *func, - const QString &category, - const QString &msg) -{ - JournalPriority logLevel = LOG_INFO; - switch (level) { - case Logger::Debug: - logLevel = LOG_DEBUG; - break; - case Logger::Info: - logLevel = LOG_INFO; - break; - case Logger::Warning: - logLevel = LOG_WARNING; - break; - case Logger::Error: - logLevel = LOG_ERR; - break; - case Logger::Fatal: - logLevel = LOG_CRIT; - break; - default: - logLevel = LOG_INFO; - break; - } - sd_journal_send("MESSAGE=%s", - msg.toStdString().c_str(), - "PRIORITY=%d", - logLevel, - "DTKPRIORITTY=%d", - level, - "CODE_FILE=%s", - file, - "CODE_LINE=%d", - line, - "CODE_FUNC=%s", - func, - "CODE_CATEGORY=%s", - category.toStdString().c_str(), - NULL); -} - -DCORE_END_NAMESPACE diff --git a/src/log/LogManager.cpp b/src/log/LogManager.cpp index 390a70f..50246ff 100644 --- a/src/log/LogManager.cpp +++ b/src/log/LogManager.cpp @@ -12,8 +12,6 @@ #include #include "dstandardpaths.h" -#include "spdlog/spdlog.h" - DCORE_BEGIN_NAMESPACE #define RULES_KEY ("rules") @@ -126,9 +124,6 @@ void DLogManagerPrivate::updateLoggingRules() DLogManager::DLogManager() :d_ptr(new DLogManagerPrivate(this)) { - spdlog::set_automatic_registration(true); - spdlog::set_pattern("%v"); - d_ptr->initLoggingRules(); } @@ -242,7 +237,6 @@ QString DLogManager::joinPath(const QString &path, const QString &fileName){ DLogManager::~DLogManager() { - spdlog::shutdown(); } DCORE_END_NAMESPACE diff --git a/src/log/Logger.cpp b/src/log/Logger.cpp deleted file mode 100644 index ee4af30..0000000 --- a/src/log/Logger.cpp +++ /dev/null @@ -1,1058 +0,0 @@ -// SPDX-FileCopyrightText: 2022 UnionTech Software Technology Co., Ltd. -// -// SPDX-License-Identifier: LGPL-3.0-or-later - -#include "Logger.h" -#include "AbstractAppender.h" -#include "AbstractStringAppender.h" - -#include -#include -#include -#include -#include -#include - -#include - -DCORE_BEGIN_NAMESPACE - -/*! -@~english - \headerfile - \inmodule dtkcore - @brief A file containing the description of Logger class and and additional useful macros for logging. - */ - -/*! -@~english - \macro Dtk::Core::dlogger - \relates Dtk::Core::Logger - \keyword Dtk::Core::dlogger - - @brief Macro returning the current instance of Logger object - - If you haven't created a local Logger object it returns the same value as the Logger::globalInstance() functions. - This macro is a recommended way to get an access to the Logger instance used in current class. - - Example: - \code - ConsoleAppender* consoleAppender = new ConsoleAppender; - dlogger->registerAppender(consoleAppender); - \endcode - - @sa Dtk::Core::Logger::globalInstance() - */ - -/*! -@~english - \macro Dtk::Core::dTrace - \relates Dtk::Core::Logger - \keyword Dtk::Core::dTrace - - @brief Writes the trace log record - - This macro is the convenient way to call Logger::write(). It uses the common preprocessor macros \c __FILE__, - \c __LINE__ and the standard Qt \c Q_FUNC_INFO macros to automatically determine the needed parameters to call - Logger::write(). - - @note This and other (dInfo() etc...) macros uses the variadic macro arguments to give convenient usage form for - the different versions of Logger::write() (using the QString or const char *argument or returning the QDebug class - instance). Not all compilers will support this. Please, consider reviewing your compiler documentation to ensure - it support __VA_ARGS__ macro. - - @sa Dtk::Core::dInfo Dtk::Core::dDebug Dtk::Core::dWarning Dtk::Core::dError - @sa Dtk::Core::Logger::LogLevel - @sa Dtk::Core::Logger::write() - */ - -/*! -@~english - \macro Dtk::Core::dDebug - \relates Dtk::Core::Logger - \keyword Dtk::Core::dDebug - - @brief Writes the debug log record - - This macro records the debug log record using the Logger::write() function. It works similar to the dTrace() - macro. - - @sa Dtk::Core::dTrace Dtk::Core::dInfo Dtk::Core::dWarning Dtk::Core::dError - @sa Dtk::Core::Logger::LogLevel - @sa Dtk::Core::Logger::write() - */ - -/*! -@~english - \macro Dtk::Core::dInfo - \relates Dtk::Core::Logger - \keyword Dtk::Core::dInfo - - @brief Writes the info log record - - This macro records the info log record using the Logger::write() function. It works similar to the dTrace() - macro. - - @sa Dtk::Core::dTrace Dtk::Core::dDebug Dtk::Core::dWarning Dtk::Core::dError - @sa Dtk::Core::Logger::LogLevel - @sa Dtk::Core::Logger::write() - */ - -/*! -@~english - \macro Dtk::Core::dWarning - \relates Dtk::Core::Logger - \keyword Dtk::Core::dWarning - - @brief Write the warning log record - - This macro records the warning log record using the Logger::write() function. It works similar to the dTrace() - macro. - - @sa Dtk::Core::dTrace Dtk::Core::dInfo Dtk::Core::dDebug Dtk::Core::dError - @sa Dtk::Core::Logger::LogLevel - @sa Dtk::Core::Logger::write() - */ - -/*! -@~english - \macro Dtk::Core::dError - \relates Dtk::Core::Logger - \keyword Dtk::Core::dError - - @brief Write the error log record - This macro records the error log record using the Logger::write() function. It works similar to the dTrace() - macro. - - @sa Dtk::Core::dTrace - @sa Dtk::Core::Logger::LogLevel - @sa Dtk::Core::Logger::write() - */ - -/*! -@~english - \macro Dtk::Core::dFatal - \relates Dtk::Core::Logger - \keyword Dtk::Core::dFatal - - @brief Write the fatal log record - - This macro records the fatal log record using the Logger::write() function. It works similar to the dTrace() - macro. - - @note Recording of the log record using the Logger::Fatal log level will lead to calling the STL abort() - function, which will interrupt the running of your software and begin the writing of the core dump. - - @sa Dtk::Core::dTrace - @sa Dtk::Core::Logger::LogLevel - @sa Dtk::Core::Logger::write() - */ - -/*! -@~english - \macro Dtk::Core::dCTrace(category) - \relates Dtk::Core::Logger - \keyword Dtk::Core::dCTrace() - - @brief Writes the trace log record to the specific category - - This macro is the similar to the dTrace() macro, but has a category parameter - to write only to the category appenders (registered using Logger::registerCategoryAppender() method). - - @param[in] category category name string - - @sa Dtk::Core::dTrace - @sa Dtk::Core::Logger::LogLevel - @sa Dtk::Core::Logger::registerCategoryAppender() - @sa Dtk::Core::Logger::write() - @sa Dtk::Core::dCategory(), Dtk::Core::dGlobalCategory() - */ - - -/*! -@~english - \macro Dtk::Core::dCDebug - \relates Dtk::Core::Logger - \keyword Dtk::Core::dCDebug - - @brief Writes the debug log record to the specific category - - This macro records the debug log record using the Logger::write() function. It works similar to the dCTrace() - macro. - - @sa Dtk::Core::dCTrace() - */ - -/*! -@~english - \macro Dtk::Core::dCInfo - \relates Dtk::Core::Logger - \keyword Dtk::Core::dCInfo - - @brief Writes the info log record to the specific category - - This macro records the info log record using the Logger::write() function. It works similar to the dCTrace() - macro. - - @sa Dtk::Core::dCTrace() - */ - -/*! -@~english - \macro Dtk::Core::dCWarning - \relates Dtk::Core::Logger - \keyword Dtk::Core::dCWarning - - @brief Writes the warning log record to the specific category - - This macro records the warning log record using the Logger::write() function. It works similar to the dCTrace() - macro. - - @sa Dtk::Core::dCTrace() - */ - -/*! -@~english - \macro Dtk::Core::dCError - \relates Dtk::Core::Logger - \keyword Dtk::Core::dCError - - @brief Writes the error log record to the specific category - - This macro records the error log record using the Logger::write() function. It works similar to the dCTrace() - macro. - - @sa Dtk::Core::dCTrace() - */ - -/*! -@~english - \macro Dtk::Core::dCFatal - \relates Dtk::Core::Logger - \keyword Dtk::Core::dCFatal - - @brief Write the fatal log record to the specific category - - This macro records the fatal log record using the Logger::write() function. It works similar to the dCTrace() - macro. - - @note Recording of the log record using the Logger::Fatal log level will lead to calling the STL abort() - function, which will interrupt the running of your software and begin the writing of the core dump. - - @sa Dtk::Core::dCTrace() - */ - -/*! -@~english - \macro Dtk::Core::dCategory(category) - \relates Dtk::Core::Logger - \keyword Dtk::Core::dCategory() - - @brief Create dlogger instance inside your custom class to log all messages to the specified \a category - - This macro is used to pass all log messages inside your custom class to the specific \a category. - You must include this macro inside your class declaration (similarly to the Q_OBJECT macro). - Internally, this macro redefines loggerInstance() function, creates the local Logger object inside your class and - sets the default category to the specified parameter. - - Thus, any call to loggerInstance() (for example, inside dTrace() macro) will return the local Logger object, - so any logging message will be directed to the default category. - - @note This macro does not register any appender to the newly created dlogger instance. You should register - dlogger appenders manually, inside your class. - - Usage example: - \code - class CustomClass : public QObject - { - Q_OBJECT - dCategory("custom_category") - ... - }; - - CustomClass::CustomClass(QObject* parent) : QObject(parent) - { - dlogger->registerAppender(new FileAppender("custom_category_log")); - dTrace() << "Trace to the custom category log"; - } - \endcode - - @sa Dtk::Core::Logger::write() - @sa Dtk::Core::dTrace() - @sa Dtk::Core::Logger::registerCategoryAppender() - @sa Dtk::Core::Logger::setDefaultCategory() - */ - -/*! -@~english - \macro Dtk::Core::dGlobalCategory(category) - \relates Dtk::Core::Logger - \keyword Dtk::Core::dGlobalCategory() - - @brief Create dlogger instance inside your custom class to log all messages both to the specified \a category and to - the global dlogger instance. - - This macro is similar to dCategory(), but also passes all log messages to the global dlogger instance appenders. - It is equal to defining the local \a category dlogger using dCategory macro and calling: - \code - dlogger->logToGlobalInstance(dlogger->defaultCategory(), true); - \endcode - - @sa Dtk::Core::dCategory - @sa Dtk::Core::Logger::logToGlobalInstance() - @sa Dtk::Core::Logger::defaultCategory() - @sa Dtk::Core::Logger::registerCategoryAppender() - @sa Dtk::Core::Logger::write() - */ - -/*! -@~english - \macro Dtk::Core::dAssert - \relates Dtk::Core::Logger - \keyword Dtk::Core::dAssert - - @brief Check the assertion - - This macro is a convenient and recommended to use way to call Logger::writeAssert() function. It uses the - preprocessor macros (as the dDebug() does) to fill the necessary arguments of the Logger::writeAssert() call. It - also uses undocumented but rather mature and stable \c qt_noop() function (which does nothing) when the assertion - is true. - - Example: - \code - bool b = checkSomething(); - ... - dAssert(b == true); - \endcode - - @sa Dtk::Core::Logger::writeAssert() - */ - -/*! -@~english - \macro Dtk::Core::dTraceTime - \relates Dtk::Core::Logger - \keyword Dtk::Core::dTraceTime - - @brief Logs the processing time of current function / code block - - This macro automagically measures the function or code of block execution time and outputs it as a Logger::Trace - level log record. - - Example: - \code - int foo() - { - dTraceTime(); - ... // Do some long operations - return 0; - } // Outputs: Function foo finished in