CuteLogger
Fast and simple logging solution for Qt based applications
|
A file containing the description of Logger class and and additional useful macros for logging. More...
#include <QString>
#include <QDebug>
#include <QDateTime>
#include "CuteLogger_global.h"
Go to the source code of this file.
Classes | |
class | Logger |
Very simple but rather powerful component which may be used for logging your application activities. More... | |
Macros | |
#define | cuteLogger cuteLoggerInstance() |
Macro returning the current instance of Logger object. More... | |
#define | LOG_TRACE CuteMessageLogger(cuteLoggerInstance(), Logger::Trace, __FILE__, __LINE__, Q_FUNC_INFO).write |
Writes the trace log record. More... | |
#define | LOG_DEBUG CuteMessageLogger(cuteLoggerInstance(), Logger::Debug, __FILE__, __LINE__, Q_FUNC_INFO).write |
Writes the debug log record. More... | |
#define | LOG_INFO CuteMessageLogger(cuteLoggerInstance(), Logger::Info, __FILE__, __LINE__, Q_FUNC_INFO).write |
Writes the info log record. More... | |
#define | LOG_WARNING CuteMessageLogger(cuteLoggerInstance(), Logger::Warning, __FILE__, __LINE__, Q_FUNC_INFO).write |
Write the warning log record. More... | |
#define | LOG_ERROR CuteMessageLogger(cuteLoggerInstance(), Logger::Error, __FILE__, __LINE__, Q_FUNC_INFO).write |
Write the error log record This macro records the error log record using the Logger::write() function. It works similar to the LOG_TRACE() macro. More... | |
#define | LOG_FATAL CuteMessageLogger(cuteLoggerInstance(), Logger::Fatal, __FILE__, __LINE__, Q_FUNC_INFO).write |
Write the fatal log record. More... | |
#define | LOG_CTRACE(category) CuteMessageLogger(cuteLoggerInstance(), Logger::Trace, __FILE__, __LINE__, Q_FUNC_INFO, category).write() |
Writes the trace log record to the specific category. More... | |
#define | LOG_CDEBUG(category) CuteMessageLogger(cuteLoggerInstance(), Logger::Debug, __FILE__, __LINE__, Q_FUNC_INFO, category).write() |
Writes the debug log record to the specific category. More... | |
#define | LOG_CINFO(category) CuteMessageLogger(cuteLoggerInstance(), Logger::Info, __FILE__, __LINE__, Q_FUNC_INFO, category).write() |
Writes the info log record to the specific category. More... | |
#define | LOG_CWARNING(category) CuteMessageLogger(cuteLoggerInstance(), Logger::Warning, __FILE__, __LINE__, Q_FUNC_INFO, category).write() |
Writes the warning log record to the specific category. More... | |
#define | LOG_CERROR(category) CuteMessageLogger(cuteLoggerInstance(), Logger::Error, __FILE__, __LINE__, Q_FUNC_INFO, category).write() |
Writes the error log record to the specific category. More... | |
#define | LOG_CFATAL(category) CuteMessageLogger(cuteLoggerInstance(), Logger::Fatal, __FILE__, __LINE__, Q_FUNC_INFO, category).write() |
Write the fatal log record to the specific category. More... | |
#define | LOG_TRACE_TIME LoggerTimingHelper loggerTimingHelper(cuteLoggerInstance(), Logger::Trace, __FILE__, __LINE__, Q_FUNC_INFO); loggerTimingHelper.start |
Logs the processing time of current function / code block. More... | |
#define | LOG_DEBUG_TIME LoggerTimingHelper loggerTimingHelper(cuteLoggerInstance(), Logger::Debug, __FILE__, __LINE__, Q_FUNC_INFO); loggerTimingHelper.start |
Logs the processing time of current function / code block. More... | |
#define | LOG_INFO_TIME LoggerTimingHelper loggerTimingHelper(cuteLoggerInstance(), Logger::Info, __FILE__, __LINE__, Q_FUNC_INFO); loggerTimingHelper.start |
Logs the processing time of current function / code block. More... | |
#define | LOG_ASSERT(cond) ((!(cond)) ? cuteLoggerInstance()->writeAssert(__FILE__, __LINE__, Q_FUNC_INFO, #cond) : qt_noop()) |
Check the assertion. More... | |
#define | LOG_CATEGORY(category) |
Create logger instance inside your custom class to log all messages to the specified category. More... | |
#define | LOG_GLOBAL_CATEGORY(category) |
Create logger instance inside your custom class to log all messages both to the specified category and to the global logger instance. More... | |
A file containing the description of Logger class and and additional useful macros for logging.
#define cuteLogger cuteLoggerInstance() |
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:
#define LOG_ASSERT | ( | cond | ) | ((!(cond)) ? cuteLoggerInstance()->writeAssert(__FILE__, __LINE__, Q_FUNC_INFO, #cond) : qt_noop()) |
Check the assertion.
This macro is a convinient and recommended to use way to call Logger::writeAssert() function. It uses the preprocessor macros (as the LOG_DEBUG() does) to fill the necessary arguments of the Logger::writeAssert() call. It also uses undocumented but rather mature and stable qt_noop()
function (which does nothing) when the assertion is true.
Example:
#define LOG_CATEGORY | ( | category | ) |
Create logger instance inside your custom class to log all messages to the specified category.
This macro is used to pass all log messages inside your custom class to the specific category. You must include this macro inside your class declaration (similarly to the Q_OBJECT macro). Internally, this macro redefines cuteLoggerInstance() function, creates the local Logger object inside your class and sets the default category to the specified parameter.
Thus, any call to cuteLoggerInstance() (for example, inside LOG_TRACE() macro) will return the local Logger object, so any logging message will be directed to the default category.
Usage example:
If used compiler supports C++11 standard, LOG_CATEGORY and LOG_GLOBAL_CATEGORY macros would also work when added inside of any scope. It could be useful, for example, to log every single run of a method to a different file.
#define LOG_CDEBUG | ( | category | ) | CuteMessageLogger(cuteLoggerInstance(), Logger::Debug, __FILE__, __LINE__, Q_FUNC_INFO, category).write() |
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 LOG_CTRACE() macro.
#define LOG_CERROR | ( | category | ) | CuteMessageLogger(cuteLoggerInstance(), Logger::Error, __FILE__, __LINE__, Q_FUNC_INFO, category).write() |
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 LOG_CTRACE() macro.
#define LOG_CFATAL | ( | category | ) | CuteMessageLogger(cuteLoggerInstance(), Logger::Fatal, __FILE__, __LINE__, Q_FUNC_INFO, category).write() |
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 LOG_CTRACE() macro.
#define LOG_CINFO | ( | category | ) | CuteMessageLogger(cuteLoggerInstance(), Logger::Info, __FILE__, __LINE__, Q_FUNC_INFO, category).write() |
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 LOG_CTRACE() macro.
#define LOG_CTRACE | ( | category | ) | CuteMessageLogger(cuteLoggerInstance(), Logger::Trace, __FILE__, __LINE__, Q_FUNC_INFO, category).write() |
Writes the trace log record to the specific category.
This macro is the similar to the LOG_TRACE() macro, but has a category parameter to write only to the category appenders (registered using Logger::registerCategoryAppender() method).
category | category name string |
#define LOG_CWARNING | ( | category | ) | CuteMessageLogger(cuteLoggerInstance(), Logger::Warning, __FILE__, __LINE__, Q_FUNC_INFO, category).write() |
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 LOG_CTRACE() macro.
#define LOG_DEBUG CuteMessageLogger(cuteLoggerInstance(), Logger::Debug, __FILE__, __LINE__, Q_FUNC_INFO).write |
Writes the debug log record.
This macro records the debug log record using the Logger::write() function. It works similar to the LOG_TRACE() macro.
#define LOG_DEBUG_TIME LoggerTimingHelper loggerTimingHelper(cuteLoggerInstance(), Logger::Debug, __FILE__, __LINE__, Q_FUNC_INFO); loggerTimingHelper.start |
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::Debug level log record. It works similar to LOG_TRACE_TIME() macro.
#define LOG_ERROR CuteMessageLogger(cuteLoggerInstance(), Logger::Error, __FILE__, __LINE__, Q_FUNC_INFO).write |
Write the error log record This macro records the error log record using the Logger::write() function. It works similar to the LOG_TRACE() macro.
#define LOG_FATAL CuteMessageLogger(cuteLoggerInstance(), Logger::Fatal, __FILE__, __LINE__, Q_FUNC_INFO).write |
Write the fatal log record.
This macro records the fatal log record using the Logger::write() function. It works similar to the LOG_TRACE() macro.
#define LOG_GLOBAL_CATEGORY | ( | category | ) |
Create logger instance inside your custom class to log all messages both to the specified category and to the global logger instance.
This macro is similar to LOG_CATEGORY(), but also passes all log messages to the global logger instance appenders. It is equal to defining the local category logger using LOG_CATEGORY macro and calling:
#define LOG_INFO CuteMessageLogger(cuteLoggerInstance(), Logger::Info, __FILE__, __LINE__, Q_FUNC_INFO).write |
Writes the info log record.
This macro records the info log record using the Logger::write() function. It works similar to the LOG_TRACE() macro.
#define LOG_INFO_TIME LoggerTimingHelper loggerTimingHelper(cuteLoggerInstance(), Logger::Info, __FILE__, __LINE__, Q_FUNC_INFO); loggerTimingHelper.start |
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::Info level log record. It works similar to LOG_TRACE_TIME() macro.
#define LOG_TRACE CuteMessageLogger(cuteLoggerInstance(), Logger::Trace, __FILE__, __LINE__, Q_FUNC_INFO).write |
Writes the trace log record.
This macro is the convinient way to call Logger::write(). It uses the common preprocessor macros FILE
, LINE
and the standart Qt Q_FUNC_INFO
macros to automatically determine the needed parameters to call Logger::write().
#define LOG_TRACE_TIME LoggerTimingHelper loggerTimingHelper(cuteLoggerInstance(), Logger::Trace, __FILE__, __LINE__, Q_FUNC_INFO); loggerTimingHelper.start |
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:
If you are measuring a code of block execution time you may also add a name of block to the macro:
#define LOG_WARNING CuteMessageLogger(cuteLoggerInstance(), Logger::Warning, __FILE__, __LINE__, Q_FUNC_INFO).write |
Write the warning log record.
This macro records the warning log record using the Logger::write() function. It works similar to the LOG_TRACE() macro.