gmerlin
Macros | Enumerations | Functions
Logging

Global logging facilities. More...

Macros

#define bg_log(level, domain,...)   bg_log_translate(PACKAGE, level, domain, __VA_ARGS__)
 Translate a message and send it to the logger. More...
 

Enumerations

enum  bg_log_level_t {
  BG_LOG_DEBUG = 1<<0,
  BG_LOG_WARNING = 1<<1,
  BG_LOG_ERROR = 1<<2,
  BG_LOG_INFO = 1<<3
}
 Log levels. More...
 

Functions

void bg_log_notranslate (bg_log_level_t level, const char *domain, const char *format,...) __attribute__((format(printf
 Send a message to the logger without translating it. More...
 
void void bg_logs_notranslate (bg_log_level_t level, const char *domain, const char *str)
 Send a message (as complete string) to the logger without translating it. More...
 
void bg_log_translate (const char *translation_domain, bg_log_level_t level, const char *domain, const char *format,...) __attribute__((format(printf
 Translate a message and send it to the logger. More...
 
void bg_log_set_dest (bg_msg_queue_t *q)
 Set the log destination. More...
 
const char * bg_log_level_to_string (bg_log_level_t level)
 Convert a log level to a human readable string. More...
 
void bg_log_set_verbose (int mask)
 Set verbosity mask. More...
 
char * bg_log_last_error ()
 Get last error message. More...
 
void bg_log_syslog_init (const char *name)
 Initialize syslog logging. More...
 
void bg_log_syslog_flush ()
 

Detailed Description

Global logging facilities.

The logging mechanism is used for everything, which would be done with fprintf(stderr, ...) in simpler applications. It is the only mechanism, which used global variables, i.e. the functions bg_log_set_dest and bg_log_set_verbose. They should be called just once during application startup. The function bg_log can, of course, be called from multiple threads simultaneously.

Macro Definition Documentation

#define bg_log (   level,
  domain,
  ... 
)    bg_log_translate(PACKAGE, level, domain, __VA_ARGS__)

Translate a message and send it to the logger.

Enumeration Type Documentation

Log levels.

These specify the type and severity of a message. They can also be ORed for a call to bg_log_set_verbose.

Enumerator
BG_LOG_DEBUG 

Only for programmers, useless for users.

BG_LOG_WARNING 

Something went wrong, but is not fatal.

BG_LOG_ERROR 

Something went wrong, cannot continue.

BG_LOG_INFO 

Something interesting the user might want to know.

Function Documentation

void bg_log_notranslate ( bg_log_level_t  level,
const char *  domain,
const char *  format,
  ... 
)

Send a message to the logger without translating it.

Parameters
levelLevel
domainThe name of the volume
formatFormat like for printf

All other arguments must match the format string.

This function either prints a message to stderr (if you didn't case bg_log_set_dest and level is contained in the mask you passed to bg_log_set_verbose) or puts a message into the queue you passed to bg_log_set_dest.

void void bg_logs_notranslate ( bg_log_level_t  level,
const char *  domain,
const char *  str 
)

Send a message (as complete string) to the logger without translating it.

Parameters
levelLevel
domainThe name of the volume
strMessage string

All other arguments must match the format string.

This function either prints a message to stderr (if you didn't case bg_log_set_dest and level is contained in the mask you passed to bg_log_set_verbose) or puts a message into the queue you passed to bg_log_set_dest.

void bg_log_translate ( const char *  translation_domain,
bg_log_level_t  level,
const char *  domain,
const char *  format,
  ... 
)

Translate a message and send it to the logger.

Parameters
translation_domainGettext domain (usually package name)
levelLevel
domainThe name of the volume
formatFormat like for printf

All other arguments must match the format string.

This function either prints a message to stderr (if you didn't case bg_log_set_dest and level is contained in the mask you passed to bg_log_set_verbose) or puts a message into the queue you passed to bg_log_set_dest.

void bg_log_set_dest ( bg_msg_queue_t q)

Set the log destination.

Parameters
qMessage queue

This sets a global message queue to which log messages will be sent. The format of the logging messages is simple: The message id is equal to the log level (see bg_msg_get_id). The first two arguments are strings for the domain and the actual message respectively (see bg_msg_get_arg_string).

Note, that logging will become asynchronous with this method. Also, single threaded applications always must remember to handle messages from the log queue after they did something critical.

const char* bg_log_level_to_string ( bg_log_level_t  level)

Convert a log level to a human readable string.

Parameters
levelLog level
Returns
A human readable string describing the log level
void bg_log_set_verbose ( int  mask)

Set verbosity mask.

Parameters
maskORed log levels, which should be printed

Note, that this function is not thread save and has no effect if logging is done with a message queue.

char* bg_log_last_error ( )

Get last error message.

Returns
The last error message, must be freed

Use this only if you didn't set an log destination and you can make sure, that only your thread can trigger an error.

void bg_log_syslog_init ( const char *  name)

Initialize syslog logging.

Parameters
nameApplication name
void bg_log_syslog_flush ( )

Flush the log queue, must be done periodically by the application