30 #include <QLoggingCategory> 31 #include <QElapsedTimer> 73 static GmLogLevel str2Level(
const char* levelStr);
82 #define gmLog(category, level, ...) qCDebug((category).qtCategory(level), __VA_ARGS__) 84 #define gmTrace(category, ...) qCDebug((category).qtCategory(GM_TRACE), __VA_ARGS__) 85 #define gmExtInfo(category, ...) qCDebug((category).qtCategory(GM_EXT_INFO), __VA_ARGS__) 86 #define gmInfo(category, ...) qCDebug((category).qtCategory(GM_INFO), __VA_ARGS__) 87 #define gmWarn(category, ...) qCDebug((category).qtCategory(GM_WARNING), __VA_ARGS__) 88 #define gmError(category, ...) qCDebug((category).qtCategory(GM_ERROR), __VA_ARGS__) 89 #define gmFatal(category, ...) qCDebug((category).qtCategory(GM_FATAL), __VA_ARGS__) 90 #define gmTime(category, ...) qCDebug((category).qtCategory(GM_TIME), __VA_ARGS__) 91 #define gmMemory(category, ...) qCDebug((category).qtCategory(GM_MEMORY), __VA_ARGS__) 93 #define gmLogMsg(category, level, msg) qCDebug((category).qtCategory(level), qPrintable(msg)) 95 #define gmTraceMsg(category, msg) qCDebug((category).qtCategory(GM_TRACE), qPrintable(msg)) 96 #define gmExtInfoMsg(category, msg) qCDebug((category).qtCategory(GM_EXT_INFO), qPrintable(msg)) 97 #define gmInfoMsg(category, msg) qCDebug((category).qtCategory(GM_INFO), qPrintable(msg)) 98 #define gmWarnMsg(category, msg) qCDebug((category).qtCategory(GM_WARNING), qPrintable(msg)) 99 #define gmErrorMsg(category, msg) qCDebug((category).qtCategory(GM_ERROR), qPrintable(msg)) 100 #define gmFatalMsg(category, msg) qCDebug((category).qtCategory(GM_FATAL), qPrintable(msg)) 101 #define gmTimeMsg(category, msg) qCDebug((category).qtCategory(GM_TIME), qPrintable(msg)) 102 #define gmMemoryMsg(category, msg) qCDebug((category).qtCategory(GM_MEMORY), qPrintable(msg)) 110 void logMessage(
int level,
QString msg);
140 int maxSize = 120,
int maxBreak = 30);
194 qint64 t = _timer.elapsed();
195 gmTimeMsg(_logger,
QObject::tr(
"%1 [%2] finished in %3 s").arg(_msg).arg(_nestLevel).arg(t/1000.0));
197 if(_collectTimeStatistics)
void setEnabled(GmLogLevel level, bool mode)
Enables or disables log messges for the requested level.
Definition: gmLog.h:68
GMC_API_EXPORT const QStringList & GmLogStringList()
Returns the logging string list (has contents only if GmSetStringListLogging(true) was called before)
Definition: gmLog.cpp:437
static bool _collectTimeStatistics
A global flag controlling whether we should collect per message statistics. Controled by GmSetCollect...
Definition: gmLog.h:206
GMC_API_EXPORT bool GmSetCollectTimeStatistics(bool mode)
Enables or disables the collection of time statistics from messages emmitted with GmTimeMsg.
Definition: gmLog.cpp:446
Reporting a fatal error. The system cannot continue.
Definition: gmLog.h:43
Declaration of usefull configuration definitions for the Core library.
GMC_API_EXPORT int GmLogIdentClear()
Clears the current identation level, returning the old one.
Definition: gmLog.cpp:625
GMC_API_EXPORT bool GmSetLoggerDecorations(bool mode)
Updates the current logger decoration mode. Returns the previous mode.
Definition: gmLog.cpp:570
QString tr(const char *sourceText, const char *disambiguation, int n)
GMC_API_EXPORT void GmFlushLogFile()
Flushes the log file if enabled.
Definition: gmLog.cpp:365
GMC_API_EXPORT void GmLogIdent(int offset)
Changes the current identation level.
Definition: gmLog.cpp:616
Extended information. Probably more than you wanted.
Definition: gmLog.h:39
GMC_API_EXPORT const GmLogCategory & GmPanicLogger()
Returns the global "panic" logger, usually used to report memory allocation fails deep inside class s...
Definition: gmLog.cpp:700
GMC_API_EXPORT bool GmSetShowThreadId(bool mode)
Enables or disables showing the thread id before each message. Returns the previous mode.
Definition: gmLog.cpp:385
QElapsedTimer _timer
Timer used to measure elapsed time.
Definition: gmLog.h:228
bool isEnabled(GmLogLevel level) const
Returns true if messages for this log level are enabled, false otherwise.
Definition: gmLog.h:65
RAII object used to measure the elapsed time of an operation.
Definition: gmLog.h:179
GMC_API_EXPORT void GmLogTimeStatistics(const GmLogCategory &logger)
Logs the current contents of the time statistics map using the given logger. Expects to be called fro...
Definition: gmLog.cpp:469
GMC_API_EXPORT void GmLogInit()
Initializes the logging facilities.
Definition: gmLog.cpp:285
GMC_API_EXPORT void GmSetLogLevels(const QList< QPair< QString, bool > > &rules)
Load a new set of logging rules from a rules list. Adds the no qt rules option on top of the given on...
Definition: gmLog.cpp:500
GMC_API_EXPORT void GmLogWrappedMsg(const GmLogCategory &logger, GmLogLevel level, const QString &msg, int maxSize=120, int maxBreak=30)
Logs the given message breaking lines bigger than maxSize. Message breaking is preferentially done on...
Definition: gmLog.cpp:584
RAII object to clear the identation level to log messages, restoring to the previous identation when ...
Definition: gmLog.h:165
A warning message reporting something strange but not necessarilly an error.
Definition: gmLog.h:41
Aux class whose only purpose is to allow loggers to emit a logMessage signal, if configured to do so.
Definition: gmLog.h:105
RAII class used to add the elapsed time to a counter received by reference. Counter is incremented in...
Definition: gmLog.h:215
Reporting timing information. New category so as to be easy to disable all timing messages for tests ...
Definition: gmLog.h:44
GMC_API_EXPORT void GmLogMemoryUsage(const GmLogCategory &logger, const QString &msg)
Log the current memory usage and the difference from the last call to GmLogMemoryUsage that printed s...
Definition: gmLog.cpp:638
Reporting an error from which the system can continue (maybe not with its total capacity)
Definition: gmLog.h:42
const GmLogCategory & _logger
The logger used to emmit messages.
Definition: gmLog.h:210
QElapsedTimer _timer
Timer used to measure elapsed time.
Definition: gmLog.h:209
GMC_API_EXPORT bool GmLoggerDecorations(void)
Returns the current logger decoration mode. When set to true, code logging value tables should add de...
Definition: gmLog.cpp:564
GMC_API_EXPORT void GmCloseLogFile()
Closes the log file if enabled.
Definition: gmLog.cpp:352
#define GMC_API_EXPORT
Macro for controling if the class is being exported (GEMA_CORE_LIB defined) or imported (GEMA_CORE_LI...
Definition: gmCoreConfig.h:35
static int _nestLevel
A global value storing the current nesting level (GmTimeMsg objects created in the scope of another o...
Definition: gmLog.h:207
GMC_API_EXPORT const QObject * GmSetLoggingSignal(bool enable)
Enables or disables logging to the logMessage signal. Returns the object that will be used to emit th...
Definition: gmLog.cpp:490
GmLogLevel
Available log levels list.
Definition: gmLog.h:36
Class representing a category with multiple logging levels.
Definition: gmLog.h:58
GMC_API_EXPORT bool GmSetHideRepeatedWarnings(bool mode)
Enables or disables skipping repeated warning messages. Returns the previous mode.
Definition: gmLog.cpp:396
GMC_API_EXPORT bool GmSetShowLoggerName(bool mode)
Enables or disables showing the logger name before each message. Returns the previous mode.
Definition: gmLog.cpp:374
qint64 nsecsElapsed() const const
QLoggingCategory & qtCategory(GmLogLevel level) const
Returns the "Qt category" that represents the requested level.
Definition: gmLog.h:71
QString _msg
Message title.
Definition: gmLog.h:211
Number of log levels.
Definition: gmLog.h:48
GMC_API_EXPORT void GmSetLogFile(QString logfile, bool flush, const GmLogCategory &logger)
Enables and configures file logging.
Definition: gmLog.cpp:328
GMC_API_EXPORT bool GmSetStringListLogging(bool mode, QStringList *targetList=NULL)
Enables or disables logging to a string list. This is usefull for capturing messages for testing purp...
Definition: gmLog.cpp:416
GMC_API_EXPORT QString GmLogFormatMemory(size_t s)
Return a string with the memory size converted to kb, Mb or Gb, adding the unit to the converted (if ...
Definition: gmLog.cpp:683
Trace information to help system debugging. Much more info than you want.
Definition: gmLog.h:38
Information regarding system evolution and config. Should be the "right" level of messages.
Definition: gmLog.h:40
RAII object to add an identation level to log messages, reverting the settings when the object is des...
Definition: gmLog.h:153
GMC_API_EXPORT bool GmSetConsoleLogging(bool mode)
Enables or disables logging to the console. Returns the previous mode.
Definition: gmLog.cpp:311
Reporting memory information. New category so as to be easy to disable all memory messages for tests ...
Definition: gmLog.h:45
qint64 * _counter
The counter where the elapsed time will be added to.
Definition: gmLog.h:229
GMC_API_EXPORT void GmAddToTimeStatistics(const QString &msg, qint64 elapsedTime)
Adds the given time to the global statistics for the giiven message used as identifir in calls to GmT...
Definition: gmLog.cpp:457