hamcast  Version 0.7
Macros | Typedefs | Functions
Logging.

Macros

#define HC_LOG_TRACE_LVL
 
#define HC_LOG_DEBUG_LVL
 
#define HC_LOG_INFO_LVL
 
#define HC_LOG_WARN_LVL
 
#define HC_LOG_ERROR_LVL
 
#define HC_LOG_FATAL_LVL
 
#define HC_LOG_TRACE(message)
 
#define HC_LOG_DEBUG(message)
 
#define HC_LOG_INFO(message)
 
#define HC_LOG_WARN(message)
 
#define HC_LOG_ERROR(message)
 
#define HC_LOG_FATAL(message)
 
#define HC_LOG_SCOPE(scope_name, message)
 

Typedefs

typedef void(* hc_log_fun_t )(int, const char *, const char *)
 

Functions

hc_log_fun_t hc_get_log_fun ()
 
void hc_set_log_fun (hc_log_fun_t function_ptr)
 
void hc_log (int log_lvl, const char *function_name, const char *log_msg)
 
void hc_set_default_log_fun (int log_lvl)
 
int hc_logging_enabled ()
 

Detailed Description

libhamcast provides its own logging mechanism. It's inteded for debugging of libhamcast, the middleware and technology modules only and must be enabled at compile by defining HC_ENABLE_LOGGING.

Usage example (C++):

#include "hamcast/hamcast_logging.h"
void fun1(int arg1, int arg2)
{
// writes an ENTER message to the log with "arg1 = 1, arg2 = 2"
// and an EXIT message if this function returns
HC_LOG_TRACE("arg1 = " << arg1 << ", arg2 = " << arg2);
// writes an DEBUG message with "arg1 + arg2 = 3"
HC_LOG_DEBUG("arg1 + arg2 = " << (arg1 + arg2));
// fun1 returns now to main (an trace EXIT message is written)
}
int main(int, char**)
{
// enable logging
// fun1 writes three messages to the log
fun1(1, 2);
// fourth log message
HC_LOG_DEBUG("done");
return 0;
}

Macro Definition Documentation

#define HC_LOG_DEBUG (   message)

Log debug informations.

Parameters
messageThe user defined log message.
See Also
HC_LOG_TRACE(message)
#define HC_LOG_DEBUG_LVL

Constant for logging of debug informations.

#define HC_LOG_ERROR (   message)

Log errors.

Parameters
messageThe user defined log message.
See Also
HC_LOG_TRACE(message)
#define HC_LOG_ERROR_LVL

Constant for logging of errors.

#define HC_LOG_FATAL (   message)

Log fatal errors.

Parameters
messageThe user defined log message.
See Also
HC_LOG_TRACE(message)
#define HC_LOG_FATAL_LVL

Constant for logging of fatal errors.

#define HC_LOG_INFO (   message)

Log runtime informations.

Parameters
messageThe user defined log message.
See Also
HC_LOG_TRACE(message)
#define HC_LOG_INFO_LVL

Constant for logging of runtime informations.

#define HC_LOG_SCOPE (   scope_name,
  message 
)

Log tracing informations for the current scope.

Parameters
scope_nameThe user defined name of the scope. This name is written to the log instead of the enclosing function name.
messageThe user defined log message.
See Also
HC_LOG_TRACE(message)
#define HC_LOG_TRACE (   message)

Log tracing informations for the current function.

If you're compiling C++ then this logs an ENTER event with message and an EXIT event if the function is leaved.

Parameters
messageThe user defined log message.
Note
If you're compiling C++, message will be streamed. This allows you to use the stream operator: HC_LOG_TRACE("arg1: " << arg1).
#define HC_LOG_TRACE_LVL

Constant for logging of trace informations.

#define HC_LOG_WARN (   message)

Log warnings.

Parameters
messageThe user defined log message.
See Also
HC_LOG_TRACE(message)
#define HC_LOG_WARN_LVL

Constant for logging of warnings.

Typedef Documentation

typedef void(* hc_log_fun_t)(int, const char *, const char *)

A function that could be used for logging.

The first argument is the log level, the second argument is the (human readable) name of the function where this log event occured and the last argument is the message.

Function Documentation

hc_log_fun_t hc_get_log_fun ( )

Get a pointer to the current active log function.

Returns
The current active log function (might be NULL).
void hc_log ( int  log_lvl,
const char *  function_name,
const char *  log_msg 
)

Invokes the function pointer returned by hc_get_log_fun() if not NULL.

Parameters
log_lvlOne of { HC_LOG_TRACE_LVL, HC_LOG_DEBUG_LVL, HC_LOG_INFO_LVL, HC_LOG_WARN_LVL, HC_LOG_ERROR_LVL, HC_LOG_FATAL_LVL }.
function_nameUsually __FUNCTION__ or __PRETTY_FUNCTION__.
log_msgThe user defined log message.
int hc_logging_enabled ( )

Check if libHAMcast was compiled with logging enabled.

Returns
1 if logging is enabled; otherwise 0
void hc_set_default_log_fun ( int  log_lvl)

Get a default logging implementation (one logfile per thread).

Parameters
log_lvlThe desired logging level.
Returns
Set a log function that discards all log messages with level < log_lvl.
void hc_set_log_fun ( hc_log_fun_t  function_ptr)

Set the log function to function_ptr.

Parameters
function_ptrA custom logging implementation.