|
hydrogen 1.2.3
|
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. | |
| void | log (unsigned level, const QString &class_name, const char *func_name, const QString &msg) |
| the log function | |
| void | set_use_file (bool use) |
| set use file flag | |
| bool | should_log (unsigned lvl) const |
| return true if the level is set in the bitmask | |
| bool | use_file () const |
| return __use_file | |
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) |
| 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) |
| 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 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) | |
| 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 | __use_file |
| write log to file if set to true | |
| bool | m_bUseStdout |
| 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 138 of file Logger.cpp.
|
private |
constructor
Definition at line 112 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 102 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 107 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 195 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 241 of file Logger.cpp.
| void log | ( | unsigned | level, |
| const QString & | class_name, | ||
| const char * | func_name, | ||
| const QString & | msg ) |
the log function
| level | used to output the corresponding level string |
| class_name | the name of the calling class |
| func_name | the name of the calling function/method |
| msg | the message to log |
Definition at line 144 of file Logger.cpp.
|
static |
parse a log level string and return the corresponding bit mask
| lvl | the log level string |
Definition at line 208 of file Logger.cpp.
|
inlinestatic |
|
inline |
|
inlinestatic |
|
inline |
|
friend |
needed for being able to access logger internal
| param | is a pointer to the logger instance |
Definition at line 44 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 |