/* Copyright (c) 2012 Boris Moiseev (cyberbobs at gmail dot com) This program is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License version 2.1 as published by the Free Software Foundation and appearing in the file LICENSE.LGPL included in the packaging of this file. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. */ // Local #include "Logger.h" #include "AbstractAppender.h" #include "AbstractStringAppender.h" #include #include #include #include #include #include #include #include DLOG_CORE_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