GemaCoreLib
The GeMA Core library
Classes | Macros | Enumerations | Functions
gmLog.h File Reference

Declaration of support functions and macros for information logging. More...

#include "gmCoreConfig.h"
#include <QLoggingCategory>
#include <QElapsedTimer>
Include dependency graph for gmLog.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

class  GmLogCategory
 Class representing a category with multiple logging levels. More...
 
class  GmLogSignalEmitter
 Aux class whose only purpose is to allow loggers to emit a logMessage signal, if configured to do so. More...
 
class  GmLogIdenter
 RAII object to add an identation level to log messages, reverting the settings when the object is destroyed. More...
 
class  GmLogIdentClearer
 RAII object to clear the identation level to log messages, restoring to the previous identation when the object is destroyed. More...
 
class  GmTimeMsg
 RAII object used to measure the elapsed time of an operation. More...
 
class  GmTimeAdder
 RAII class used to add the elapsed time to a counter received by reference. Counter is incremented in nano seconds. More...
 

Macros

#define gmLog(category, level, ...)   qCDebug((category).qtCategory(level), __VA_ARGS__)
 
#define gmTrace(category, ...)   qCDebug((category).qtCategory(GM_TRACE), __VA_ARGS__)
 
#define gmExtInfo(category, ...)   qCDebug((category).qtCategory(GM_EXT_INFO), __VA_ARGS__)
 
#define gmInfo(category, ...)   qCDebug((category).qtCategory(GM_INFO), __VA_ARGS__)
 
#define gmWarn(category, ...)   qCDebug((category).qtCategory(GM_WARNING), __VA_ARGS__)
 
#define gmError(category, ...)   qCDebug((category).qtCategory(GM_ERROR), __VA_ARGS__)
 
#define gmFatal(category, ...)   qCDebug((category).qtCategory(GM_FATAL), __VA_ARGS__)
 
#define gmTime(category, ...)   qCDebug((category).qtCategory(GM_TIME), __VA_ARGS__)
 
#define gmMemory(category, ...)   qCDebug((category).qtCategory(GM_MEMORY), __VA_ARGS__)
 
#define gmLogMsg(category, level, msg)   qCDebug((category).qtCategory(level), qPrintable(msg))
 
#define gmTraceMsg(category, msg)   qCDebug((category).qtCategory(GM_TRACE), qPrintable(msg))
 
#define gmExtInfoMsg(category, msg)   qCDebug((category).qtCategory(GM_EXT_INFO), qPrintable(msg))
 
#define gmInfoMsg(category, msg)   qCDebug((category).qtCategory(GM_INFO), qPrintable(msg))
 
#define gmWarnMsg(category, msg)   qCDebug((category).qtCategory(GM_WARNING), qPrintable(msg))
 
#define gmErrorMsg(category, msg)   qCDebug((category).qtCategory(GM_ERROR), qPrintable(msg))
 
#define gmFatalMsg(category, msg)   qCDebug((category).qtCategory(GM_FATAL), qPrintable(msg))
 
#define gmTimeMsg(category, msg)   qCDebug((category).qtCategory(GM_TIME), qPrintable(msg))
 
#define gmMemoryMsg(category, msg)   qCDebug((category).qtCategory(GM_MEMORY), qPrintable(msg))
 

Enumerations

enum  GmLogLevel {
  GM_TRACE, GM_EXT_INFO, GM_INFO, GM_WARNING,
  GM_ERROR, GM_FATAL, GM_TIME, GM_MEMORY,
  GM_COUNT
}
 Available log levels list. More...
 

Functions

GMC_API_EXPORT void GmLogInit ()
 Initializes the logging facilities.
 
GMC_API_EXPORT bool GmSetConsoleLogging (bool mode)
 Enables or disables logging to the console. Returns the previous mode.
 
GMC_API_EXPORT void GmSetLogFile (QString logfile, bool flush, const GmLogCategory &logger)
 Enables and configures file logging. More...
 
GMC_API_EXPORT void GmCloseLogFile ()
 Closes the log file if enabled.
 
GMC_API_EXPORT void GmFlushLogFile ()
 Flushes the log file if enabled.
 
GMC_API_EXPORT bool GmSetShowLoggerName (bool mode)
 Enables or disables showing the logger name before each message. Returns the previous mode.
 
GMC_API_EXPORT bool GmSetShowThreadId (bool mode)
 Enables or disables showing the thread id before each message. Returns the previous mode.
 
GMC_API_EXPORT bool GmSetHideRepeatedWarnings (bool mode)
 Enables or disables skipping repeated warning messages. Returns the previous mode.
 
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 ones.
 
GMC_API_EXPORT void GmSetLogLevels (LuaTable &tab, const QList< QPair< QString, bool > > &extraRules, const GmLogCategory &logger)
 Load a new set of logging rules from table tab, using logger to emmit warnings in case of errors on the table. More...
 
GMC_API_EXPORT bool GmLoggerDecorations (void)
 Returns the current logger decoration mode. When set to true, code logging value tables should add decorations to aid regression tests.
 
GMC_API_EXPORT bool GmSetLoggerDecorations (bool mode)
 Updates the current logger decoration mode. Returns the previous mode.
 
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 purposes. More...
 
GMC_API_EXPORT const QStringListGmLogStringList ()
 Returns the logging string list (has contents only if GmSetStringListLogging(true) was called before)
 
GMC_API_EXPORT bool GmSetCollectTimeStatistics (bool mode)
 Enables or disables the collection of time statistics from messages emmitted with GmTimeMsg.
 
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 GmTimeMsg.
 
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 from the main thread only.
 
GMC_API_EXPORT const QObjectGmSetLoggingSignal (bool enable)
 Enables or disables logging to the logMessage signal. Returns the object that will be used to emit the signal.
 
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 spaces but can end up being done anywhere if there is no space in the last maxBreak characters.
 
GMC_API_EXPORT void GmLogIdent (int offset)
 Changes the current identation level.
 
GMC_API_EXPORT int GmLogIdentClear ()
 Clears the current identation level, returning the old one.
 
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 something (on the first call, gives the difference from the amount of memory in use when the memory manager was initialized in the GmLogInit() function.
 
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 needed) value.
 
GMC_API_EXPORT const GmLogCategoryGmPanicLogger ()
 Returns the global "panic" logger, usually used to report memory allocation fails deep inside class structures with no easy access to another logger.
 

Detailed Description

Declaration of support functions and macros for information logging.

Author
Carlos Augusto Teixeira Mendes
Date
october, 2014

Enumeration Type Documentation

◆ GmLogLevel

enum GmLogLevel

Available log levels list.

Enumerator
GM_TRACE 

Trace information to help system debugging. Much more info than you want.

GM_EXT_INFO 

Extended information. Probably more than you wanted.

GM_INFO 

Information regarding system evolution and config. Should be the "right" level of messages.

GM_WARNING 

A warning message reporting something strange but not necessarilly an error.

GM_ERROR 

Reporting an error from which the system can continue (maybe not with its total capacity)

GM_FATAL 

Reporting a fatal error. The system cannot continue.

GM_TIME 

Reporting timing information. New category so as to be easy to disable all timing messages for tests based on diff with a standard file.

GM_MEMORY 

Reporting memory information. New category so as to be easy to disable all memory messages for tests based on diff with a standard file.

GM_COUNT 

Number of log levels.

Function Documentation

◆ GmSetLogFile()

GMC_API_EXPORT void GmSetLogFile ( QString  logfile,
bool  flush,
const GmLogCategory logger 
)

Enables and configures file logging.

Parameters
logfileThe log file name
flushSet to true for forcing a flush after each log write
loggerLogger used to report success/problems while opening the log file

◆ GmSetLogLevels()

GMC_API_EXPORT void GmSetLogLevels ( LuaTable tab,
const QList< QPair< QString, bool > > &  extraRules,
const GmLogCategory logger 
)

Load a new set of logging rules from table tab, using logger to emmit warnings in case of errors on the table.

The table should be a list following the following syntax example: tab = {{'gema.simLoader.info', true }, {'*.trace', false}, {'gema.simLoader.*', true }, } Loaded rules are applied on top of the default ruels set in GmLogInit() Extra rules in 'extraRules' are applied on top of the Lua table rules and can be used to override some of those config file options.

◆ GmSetStringListLogging()

GMC_API_EXPORT bool GmSetStringListLogging ( bool  mode,
QStringList targetList 
)

Enables or disables logging to a string list. This is usefull for capturing messages for testing purposes.

If targetList is different from NULL, the supplied list will be used to store log messages. Otherwise an internal list will be used. This parameter is relevant only when turning list logginng on.

When logging is disabled, if the target list is the internal list, it is also cleared. Returns the previous mode.