![]() |
GemaCoreLib
The GeMA Core library
|
Implementation of support functions and macros for information logging. More...
#include "gmLog.h"
#include "gmTrace.h"
#include "gmPath.h"
#include "gmThreadLocalStorage.h"
#include <assert.h>
#include <luaTable.h>
#include <luaStackBalancer.h>
#include <qtMemUsage.h>
#include <qtHashData.h>
Classes | |
struct | GmLogContextData |
Auxiliary structure with global Log configuration. More... | |
Functions | |
static void | GmCategoryFilter (QLoggingCategory *category) |
Internal function used to define active logging levels based on the filter rules list. | |
static void | GmMessageHandler (QtMsgType type, const QMessageLogContext &context, const QString &msg) |
Message handler used to better format messages and write to the log file if necessary. | |
void | GmLogInit () |
Initializes the logging facilities. | |
bool | GmSetConsoleLogging (bool mode) |
Enables or disables logging to the console. Returns the previous mode. | |
void | GmSetLogFile (QString logfile, bool flush, const GmLogCategory &logger) |
Enables and configures file logging. More... | |
void | GmCloseLogFile () |
Closes the log file if enabled. | |
void | GmFlushLogFile () |
Flushes the log file if enabled. | |
bool | GmSetShowLoggerName (bool mode) |
Enables or disables showing the logger name before each message. Returns the previous mode. | |
bool | GmSetShowThreadId (bool mode) |
Enables or disables showing the thread id before each message. Returns the previous mode. | |
bool | GmSetHideRepeatedWarnings (bool mode) |
Enables or disables skipping repeated warning messages. Returns the previous mode. | |
bool | GmSetStringListLogging (bool mode, QStringList *targetList) |
Enables or disables logging to a string list. This is usefull for capturing messages for testing purposes. More... | |
const QStringList & | GmLogStringList () |
Returns the logging string list (has contents only if GmSetStringListLogging(true) was called before) | |
bool | GmSetCollectTimeStatistics (bool mode) |
Enables or disables the collection of time statistics from messages emmitted with GmTimeMsg. | |
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. | |
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. | |
const QObject * | GmSetLoggingSignal (bool enable) |
Enables or disables logging to the logMessage signal. Returns the object that will be used to emit the signal. | |
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. | |
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... | |
bool | GmLoggerDecorations (void) |
Returns the current logger decoration mode. When set to true, code logging value tables should add decorations to aid regression tests. | |
bool | GmSetLoggerDecorations (bool mode) |
Updates the current logger decoration mode. Returns the previous mode. | |
void | GmLogWrappedMsg (const GmLogCategory &logger, GmLogLevel level, const QString &msg, int maxSize, int maxBreak) |
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. | |
void | GmLogIdent (int offset) |
Changes the current identation level. | |
int | GmLogIdentClear () |
Clears the current identation level, returning the old one. | |
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. | |
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. | |
const GmLogCategory & | GmPanicLogger () |
Returns the global "panic" logger, usually used to report memory allocation fails deep inside class structures with no easy access to another logger. | |
Variables | |
static GmThreadLocal int | GmIdentLevel = 0 |
Current identation level for message logging. One value per thread. More... | |
static GmLogContextData | GmLogData |
Global context variable. | |
Implementation of support functions and macros for information logging.
Implementation of a support class for path handling.
void GmSetLogFile | ( | QString | logfile, |
bool | flush, | ||
const GmLogCategory & | logger | ||
) |
Enables and configures file logging.
logfile | The log file name |
flush | Set to true for forcing a flush after each log write |
logger | Logger used to report success/problems while opening the log file |
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.
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.
|
static |
Current identation level for message logging. One value per thread.
Uses the system TLS facilities and NOT the GmTLS class since the logger might be active before the thread manager initialization :(. This variable is not inside the GmLogContextData structure since it needs to be a static / global variable.