hydrogen 1.1.1
Logger Class Reference

Class for writing logs to the console. More...

#include <Logger.h>

Public Types

enum  log_levels {
  None = 0x00 , Error = 0x01 , Warning = 0x02 , Info = 0x04 ,
  Debug = 0x08 , Constructors = 0x10 , AELockTracing = 0x20
}
 possible logging bits More...
 
typedef std::list< QString > queue_t
 message queue type More...
 

Public Member Functions

 ~Logger ()
 destructor More...
 
bool should_log (unsigned lvl) const
 return true if the level is set in the bitmask More...
 
void set_use_file (bool use)
 set use file flag More...
 
bool use_file () const
 return __use_file More...
 
void log (unsigned level, const QString &class_name, const char *func_name, const QString &msg)
 the log function More...
 

Static Public Member Functions

static Loggerbootstrap (unsigned msk)
 create the logger instance if not exists, set the log level and return the instance More...
 
static Loggercreate_instance ()
 If __instance equals 0, a new H2Core::Logger singleton will be created and stored in it. More...
 
static Loggerget_instance ()
 Returns a pointer to the current H2Core::Logger singleton stored in __instance. More...
 
static void set_bit_mask (unsigned msk)
 set the bitmask More...
 
static unsigned bit_mask ()
 return the current log level bit mask More...
 
static unsigned parse_log_level (const char *lvl)
 parse a log level string and return the corresponding bit mask More...
 

Private Member Functions

 Logger ()
 constructor More...
 

Static Private Member Functions

static int hextoi (const char *str, long len)
 convert an hex string to an integer. More...
 

Private Attributes

bool __use_file
 write log to file if set to true More...
 
bool __running
 set to true when the logger thread is running More...
 
pthread_mutex_t __mutex
 lock for adding or removing elements only More...
 
queue_t __msg_queue
 the message queue More...
 
pthread_cond_t __messages_available
 

Static Private Attributes

static Logger__instance =nullptr
 Object holding the current H2Core::Logger singleton. More...
 
static unsigned __bit_msk = 0
 the bitmask of log_level_t More...
 
static const char * __levels [] = { "None", "Error", "Warning", "Info", "Debug" }
 levels strings More...
 

Friends

void * loggerThread_func (void *param)
 needed for being able to access logger internal More...
 

Detailed Description

Class for writing logs to the console.

Member Typedef Documentation

◆ queue_t

typedef std::list<QString> queue_t

message queue type

Member Enumeration Documentation

◆ log_levels

enum log_levels

possible logging bits

Enumerator
None 
Error 
Warning 
Info 
Debug 
Constructors 
AELockTracing 

Intended to be used log the locking of the AudioEngine.

But this feature isn't implemented yet.

Constructor & Destructor Documentation

◆ ~Logger()

~Logger ( )

destructor

◆ Logger()

Logger ( )
private

constructor

Member Function Documentation

◆ bit_mask()

static unsigned bit_mask ( )
inlinestatic

return the current log level bit mask

◆ bootstrap()

Logger * bootstrap ( unsigned  msk)
static

create the logger instance if not exists, set the log level and return the instance

Parameters
mskthe logging level bitmask

◆ create_instance()

Logger * create_instance ( )
static

If __instance equals 0, a new H2Core::Logger singleton will be created and stored in it.

It is called in Hydrogen::create_instance().

◆ get_instance()

static Logger * get_instance ( )
inlinestatic

Returns a pointer to the current H2Core::Logger singleton stored in __instance.

◆ hextoi()

int hextoi ( const char *  str,
long  len 
)
staticprivate

convert an hex string to an integer.

returns -1 on failure.

Parameters
strthe hex string to convert
lenthe length of the string

◆ log()

void log ( unsigned  level,
const QString &  class_name,
const char *  func_name,
const QString &  msg 
)

the log function

Parameters
levelused to output the corresponding level string
class_namethe name of the calling class
func_namethe name of the calling function/method
msgthe message to log

◆ parse_log_level()

unsigned parse_log_level ( const char *  lvl)
static

parse a log level string and return the corresponding bit mask

Parameters
lvlthe log level string

◆ set_bit_mask()

static void set_bit_mask ( unsigned  msk)
inlinestatic

set the bitmask

Parameters
mskthe new bitmask to set

◆ set_use_file()

void set_use_file ( bool  use)
inline

set use file flag

Parameters
usethe flag status

◆ should_log()

bool should_log ( unsigned  lvl) const
inline

return true if the level is set in the bitmask

Parameters
lvlthe level to check

◆ use_file()

bool use_file ( ) const
inline

return __use_file

Friends And Related Function Documentation

◆ loggerThread_func

void * loggerThread_func ( void *  param)
friend

needed for being able to access logger internal

Parameters
paramis a pointer to the logger instance

Field Documentation

◆ __bit_msk

unsigned __bit_msk = 0
staticprivate

the bitmask of log_level_t

◆ __instance

Logger * __instance =nullptr
staticprivate

Object holding the current H2Core::Logger singleton.

It is initialized with NULL, set with create_instance(), and accessed with get_instance().

◆ __levels

const char * __levels = { "None", "Error", "Warning", "Info", "Debug" }
staticprivate

levels strings

◆ __messages_available

pthread_cond_t __messages_available
private

◆ __msg_queue

queue_t __msg_queue
private

the message queue

◆ __mutex

pthread_mutex_t __mutex
private

lock for adding or removing elements only

◆ __running

bool __running
private

set to true when the logger thread is running

◆ __use_file

bool __use_file
private

write log to file if set to true