|
hydrogen 1.2.6
|
Class for writing logs to the console. More...
#include <Logger.h>
Data Structures | |
| class | CrashContext |
| Helper class to preserve and restore recursive crash context strings using an RAAI pattern. More... | |
Public Types | |
| enum | log_levels { None = 0x00 , Error = 0x01 , Warning = 0x02 , Info = 0x04 , Debug = 0x08 , Constructors = 0x10 , Locks = 0x20 } |
| possible logging bits More... | |
| typedef std::list< QString > | queue_t |
| message queue type | |
Public Member Functions | |
| ~Logger () | |
| destructor | |
| void | flush () const |
| Waits till the logger thread poped all remaining messages from __msg_queue. | |
| bool | getLogColors () const |
| void | log (unsigned level, const QString &sClassName, const char *func_name, const QString &sMsg, const QString &sColor="") |
| the log function | |
| bool | should_log (unsigned lvl) const |
| return true if the level is set in the bitmask | |
Static Public Member Functions | |
| static unsigned | bit_mask () |
| return the current log level bit mask | |
| static Logger * | bootstrap (unsigned msk, const QString &sLogFilePath=QString(), bool bUseStdout=true, bool bLogTimestamps=false, bool bLogColors=true) |
| create the logger instance if not exists, set the log level and return the instance | |
| static Logger * | create_instance (const QString &sLogFilePath=QString(), bool bUseStdout=true, bool bLogTimestamps=false, bool bLogColors=true) |
| If __instance equals 0, a new H2Core::Logger singleton will be created and stored in it. | |
| static Logger * | get_instance () |
| Returns a pointer to the current H2Core::Logger singleton stored in __instance. | |
| static bool | isAvailable () |
| Checks whether the Logger instances was already created and can be used by other parts of Hydrogen. | |
| static unsigned | parse_log_level (const char *lvl) |
| parse a log level string and return the corresponding bit mask | |
| static void | set_bit_mask (unsigned msk) |
| set the bitmask | |
Crash context management | |
Access the crash context string that can be used to report what caused a crash. The crash-context string is a thread-local property, and may be read by a fatal exception handler (which will execute in the same thread that caused the crash). This avoids potential contention for locking and unlocking of a shared crash context structure. | |
| static void | setCrashContext (QString *pContext) |
| static QString * | getCrashContext () |
Private Member Functions | |
| Logger (const QString &sLogFilePath=QString(), bool bUseStdout=true, bool bLogTimestamps=false, bool bLogColors=true) | |
| constructor | |
Static Private Member Functions | |
| static int | hextoi (const char *str, long len) |
| convert an hex string to an integer. | |
Private Attributes | |
| pthread_cond_t | __messages_available |
| queue_t | __msg_queue |
| the message queue | |
| pthread_mutex_t | __mutex |
| lock for adding or removing elements only | |
| bool | __running |
| set to true when the logger thread is running | |
| bool | m_bLogColors |
| bool | m_bLogTimestamps |
| bool | m_bUseStdout |
| QStringList | m_colorList |
| QStringList | m_prefixList |
| QString | m_sColorOff |
| QString | m_sLogFilePath |
Static Private Attributes | |
| static unsigned | __bit_msk = 0 |
| the bitmask of log_level_t | |
| static Logger * | __instance =nullptr |
| Object holding the current H2Core::Logger singleton. | |
| static const char * | __levels [] = { "None", "Error", "Warning", "Info", "Debug", "Constructors", "Locks" } |
| levels strings | |
| static thread_local QString * | pCrashContext = nullptr |
Friends | |
| void * | loggerThread_func (void *param) |
| needed for being able to access logger internal | |
| enum log_levels |
| ~Logger | ( | ) |
destructor
Definition at line 217 of file Logger.cpp.
|
private |
constructor
Definition at line 170 of file Logger.cpp.
|
inlinestatic |
|
static |
create the logger instance if not exists, set the log level and return the instance
| msk | the logging level bitmask |
Definition at line 136 of file Logger.cpp.
|
static |
If __instance equals 0, a new H2Core::Logger singleton will be created and stored in it.
It is called in Hydrogen::create_instance().
Definition at line 161 of file Logger.cpp.
| void flush | ( | ) | const |
Waits till the logger thread poped all remaining messages from __msg_queue.
Note that this function will neither lock __msg_queue nor prevent routines from adding new messages to the queue.
Definition at line 276 of file Logger.cpp.
|
inlinestatic |
Returns a pointer to the current H2Core::Logger singleton stored in __instance.
|
staticprivate |
convert an hex string to an integer.
returns -1 on failure.
| str | the hex string to convert |
| len | the length of the string |
Definition at line 322 of file Logger.cpp.
|
inlinestatic |
| void log | ( | unsigned | level, |
| const QString & | sClassName, | ||
| const char * | func_name, | ||
| const QString & | sMsg, | ||
| const QString & | sColor = "" ) |
the log function
| level | used to output the corresponding level string |
| sClassName | the name of the calling class |
| func_name | the name of the calling function/method |
| sMsg | the message to log |
| sColor | alternate color |
Definition at line 223 of file Logger.cpp.
|
static |
parse a log level string and return the corresponding bit mask
| lvl | the log level string |
Definition at line 289 of file Logger.cpp.
|
inlinestatic |
|
inlinestatic |
|
inline |
|
friend |
needed for being able to access logger internal
| param | is a pointer to the logger instance |
Definition at line 54 of file Logger.cpp.
|
staticprivate |
|
staticprivate |
Object holding the current H2Core::Logger singleton.
It is initialized with NULL, set with create_instance(), and accessed with get_instance().
|
staticprivate |
|
private |
|
private |