log.h File Reference

CMX logging functions. More...

#include <stdio.h>
#include <stdarg.h>
Include dependency graph for log.h:

Logging macros

Logging Compile-time configuration:

  • LOG_NOTHING : Disables all logging
  • LOG_ONLY_AUDIT : compile AUDIT log statements
  • LOG_ONLY_ERROR : compile AUDIT, ERROR log statements
  • LOG_ONLY_WARN : compile AUDIT, ERROR, WARN log statements
  • LOG_ONLY_INFO : compile AUDIT, ERROR, WARN, INFO log statements
  • LOG_ONLY_DEBUG : compile AUDIR, ERROR, WARN, INFO, DEBUG log statements
  • no define : compile all log statements


#define _LOG_LOG(level,...)   cmx_log_printf(level, __FILE__, __LINE__, __FUNCTION__, __VA_ARGS__)
 internal log macro
#define LOG_AUDIT_IF(...)   _LOG_LOG(LOG_LEVEL_AUDIT, __VA_ARGS__)
 Audit Log entry.
#define LOG_ERROR_IF(...)   _LOG_LOG(LOG_LEVEL_ERROR, __VA_ARGS__)
 Error Log entry.
#define LOG_WARN_IF(...)   _LOG_LOG(LOG_LEVEL_WARN, __VA_ARGS__)
 Warn Log entry.
#define LOG_INFO_IF(...)   _LOG_LOG(LOG_LEVEL_INFO, __VA_ARGS__)
 Info Log entry.
#define LOG_DEBUG_IF(...)   _LOG_LOG(LOG_LEVEL_DEBUG, __VA_ARGS__)
 Debug Log entry.
#define LOG_TRACE_IF(...)   _LOG_LOG(LOG_LEVEL_TRACE, __VA_ARGS__)
 Trace Log entry.
enum  log_levels {
  LOG_LEVEL_AUDIT = 0, LOG_LEVEL_ERROR = 1, LOG_LEVEL_WARN = 2, LOG_LEVEL_INFO = 3,
  LOG_LEVEL_DEBUG = 4, LOG_LEVEL_TRACE = 5
}
 

Enumeration of all valid logging levels.

More...
typedef void(* cmx_log_adapter_t )(enum log_levels, const char *, int, const char *, const char *, va_list)
 Type of a log adapter function.
void cmx_log_set_adapter (cmx_log_adapter_t log_adapter_func)
 Set a external logging function.

Logging control functions



#define LOG_SET_LEVEL(l)
 Change log level for a code-block.
int cmx_log_current_level
 the current logging level.
enum log_levels cmx_log_level_from_env ()
 Read the log_level from environment variable LOG_LEVEL.
enum log_levels cmx_log_from_string (const char *level)
 Parse a string to log-level.
const char * cmx_log_level_name (enum log_levels level)
 convert a log level to string like "INFO".
void cmx_log_vprintf (enum log_levels level, const char *file, const int line, const char *function, const char *fmt, va_list ap)
 Logging implementation.
void cmx_log_printf (enum log_levels level, const char *file, const int line, const char *function, const char *fmt,...) __attribute__((format(printf
 redirects to cmx_log_vprintf()

Detailed Description

CMX logging functions.


Define Documentation

#define LOG_SET_LEVEL (  ) 
Value:
for (int _loop=1, _old_log_level = cmx_log_current_level; \
         _loop == 1 && ((cmx_log_current_level = l) || 1) ; \
         cmx_log_current_level = _old_log_level, _loop=0)

Change log level for a code-block.

This macro changes the logging level for the following code-block and restores the previous logging level afterwards.

The newly introduced local variables _loop and _old_log_level must remain unmodified by the caller.


Typedef Documentation

typedef void(* cmx_log_adapter_t)(enum log_levels, const char *, int, const char *, const char *, va_list)

Type of a log adapter function.

The internal stdout-logger can be replaced with a function of this type.

  1. enum log_levels: The log level (log_levels).
  2. const char *: The source file
  3. int : line number
  4. const char *: the source function name
  5. const char *: the message format
  6. va_list:, the argument for the previous format string

Enumeration Type Documentation

enum log_levels

Enumeration of all valid logging levels.

Enumerator:
LOG_LEVEL_AUDIT 

highest logging level

LOG_LEVEL_ERROR 
See also:
log_levels
LOG_LEVEL_WARN 
See also:
log_levels
LOG_LEVEL_INFO 
See also:
log_levels
LOG_LEVEL_DEBUG 
See also:
log_levels
LOG_LEVEL_TRACE 

lowest, most detailed logging level


Function Documentation

enum log_levels cmx_log_from_string ( const char *  level  ) 

Parse a string to log-level.

On parse error: return default log-level INFO.

enum log_levels cmx_log_level_from_env (  ) 

Read the log_level from environment variable LOG_LEVEL.

See also:
cmx_log_from_string()
const char* cmx_log_level_name ( enum log_levels  level  ) 

convert a log level to string like "INFO".

A unknown log level is returned as empty string.

void cmx_log_set_adapter ( cmx_log_adapter_t  log_adapter_func  ) 

Set a external logging function.

The type of the function is defined as cmx_log_adapter_t.

void cmx_log_vprintf ( enum log_levels  level,
const char *  file,
const int  line,
const char *  function,
const char *  fmt,
va_list  ap 
)

Logging implementation.

If a logadapter is set all logging is dispatched to the log_adapter function. If not a logging message is printed to stdout if cmx_log_current_level >= 'level'.


Variable Documentation

the current logging level.

This variable can but should usually not be manipulated directly. The valid values are defined in log_levels.


Generated on 14 Feb 2014 by  doxygen 1.6.1