Di_log

## Macros

#define | di_error(format...) di_log (DI_LOG_LEVEL_ERROR, format)
#define | di_warning(format...) di_log (DI_LOG_LEVEL_WARNING, format)
#define | di_info(format...) di_log (DI_LOG_LEVEL_INFO, format)
#define | di_debug(format...) di_log (DI_LOG_LEVEL_DEBUG, format)

## Typedefs

typedef void | di_log_handler(di_log_level_flags log_level, const char *message, void *user_data)

## Enumerations

enum | di_log_level_flags { DI_LOG_FLAG_FATAL = 1 << 1 , DI_LOG_LEVEL_ERROR = 1 << 2 , DI_LOG_LEVEL_CRITICAL = 1 << 3 , DI_LOG_LEVEL_WARNING = 1 << 4 , DI_LOG_LEVEL_MESSAGE = 1 << 5 , DI_LOG_LEVEL_INFO = 1 << 6 , DI_LOG_LEVEL_DEBUG = 1 << 7 , DI_LOG_LEVEL_OUTPUT = 1 << 8 , DI_LOG_LEVEL_MASK = ~DI_LOG_FLAG_FATAL , DI_LOG_FATAL_MASK = DI_LOG_LEVEL_ERROR }
| Log levels and other flags. More...

## Functions

void | di_log (di_log_level_flags log_level, const char *format,...) __attribute__((format(printf
void void | di_vlog (di_log_level_flags log_level, const char *format, va_list args)
unsigned int | di_log_set_handler (di_log_level_flags log_levels, di_log_handler *log_func, void *user_data)

## Variables

di_log_handler | di_log_handler_default
di_log_handler | di_log_handler_syslog

## Detailed Description

## Macro Definition Documentation

## di_debug

#define di_debug | ( |  | format... | ) | di_log (DI_LOG_LEVEL_DEBUG, format)

logs debug info

## di_error

#define di_error | ( |  | format... | ) | di_log (DI_LOG_LEVEL_ERROR, format)

logs an error

## di_info

#define di_info | ( |  | format... | ) | di_log (DI_LOG_LEVEL_INFO, format)

logs information

## di_warning

#define di_warning | ( |  | format... | ) | di_log (DI_LOG_LEVEL_WARNING, format)

logs a warning

## Enumeration Type Documentation

## di_log_level_flags

enum di_log_level_flags

Log levels and other flags.

Enumerator
DI_LOG_FLAG_FATAL | flag as fatal
DI_LOG_LEVEL_ERROR | error level, always fatal
DI_LOG_LEVEL_CRITICAL | critical level
DI_LOG_LEVEL_WARNING | warning level
DI_LOG_LEVEL_MESSAGE | message level
DI_LOG_LEVEL_INFO | information level
DI_LOG_LEVEL_DEBUG | debug level
DI_LOG_LEVEL_OUTPUT | command output
DI_LOG_LEVEL_MASK | defines mask for levels
DI_LOG_FATAL_MASK | defines always fatal levels

{
DI_LOG_FLAG_FATAL = 1 << 1,
DI_LOG_LEVEL_ERROR = 1 << 2,
DI_LOG_LEVEL_CRITICAL = 1 << 3,
DI_LOG_LEVEL_WARNING = 1 << 4,
DI_LOG_LEVEL_MESSAGE = 1 << 5,
DI_LOG_LEVEL_INFO = 1 << 6,
DI_LOG_LEVEL_DEBUG = 1 << 7,
DI_LOG_LEVEL_OUTPUT = 1 << 8,
DI_LOG_LEVEL_MASK = ~DI_LOG_FLAG_FATAL,
DI_LOG_FATAL_MASK = DI_LOG_LEVEL_ERROR,
}
DI_LOG_LEVEL_MASK
@ DI_LOG_LEVEL_MASK
Definition: log.h:45
DI_LOG_LEVEL_WARNING
@ DI_LOG_LEVEL_WARNING
Definition: log.h:39
DI_LOG_LEVEL_MESSAGE
@ DI_LOG_LEVEL_MESSAGE
Definition: log.h:40
DI_LOG_FLAG_FATAL
@ DI_LOG_FLAG_FATAL
Definition: log.h:35
DI_LOG_LEVEL_INFO
@ DI_LOG_LEVEL_INFO
Definition: log.h:41
DI_LOG_LEVEL_ERROR
@ DI_LOG_LEVEL_ERROR
Definition: log.h:37
DI_LOG_LEVEL_CRITICAL
@ DI_LOG_LEVEL_CRITICAL
Definition: log.h:38
DI_LOG_FATAL_MASK
@ DI_LOG_FATAL_MASK
Definition: log.h:46
DI_LOG_LEVEL_DEBUG
@ DI_LOG_LEVEL_DEBUG
Definition: log.h:42
DI_LOG_LEVEL_OUTPUT
@ DI_LOG_LEVEL_OUTPUT
Definition: log.h:43

## Function Documentation

## di_log()

void di_log | ( | di_log_level_flags | log_level,
|  | const char * | format,
|  |  | ...
| ) |  |

Logs the resolved formatstring with log_level

Parameters

  log_level | the level of the message
  format | printf compatible format

## di_log_set_handler()

unsigned int di_log_set_handler | ( | di_log_level_flags | log_levels,
|  | di_log_handler * | log_func,
|  | void * | user_data
| ) |  |

Sets a log handler

Parameters

  log_levels | levels
  log_func | the log handler
  user_data | data for log_func

{
static unsigned int handler_id = 0;
di_log_handler_struct *handler;
handler = di_new (di_log_handler_struct, 1);
handler->id = ++handler_id;
handler->log_level = log_levels;
handler->log_func = log_func;
handler->user_data = user_data;
di_slist_append (&handlers, handler);
return handler_id;
}
di_new
#define di_new(struct_type, n_structs)
Definition: mem.h:73
di_slist_append
void di_slist_append(di_slist *slist, void *data) __attribute__((nonnull(1)))
Definition: slist.c:68
di_log_handler_struct
Log handler info.
Definition: log.c:47
di_log_handler_struct::user_data
void * user_data
Definition: log.c:51
di_log_handler_struct::log_func
di_log_handler * log_func
Definition: log.c:50
di_log_handler_struct::log_level
di_log_level_flags log_level
Definition: log.c:49
di_log_handler_struct::id
unsigned int id
Definition: log.c:48

Referenced by di_system_init().

## di_vlog()

void void di_vlog | ( | di_log_level_flags | log_level,
|  | const char * | format,
|  | va_list | args
| ) |  |

Logs the resolved formatstring with log_level

Parameters

  log_level | the level of the message
  format | printf compatible format
  args | variable arguments list

{
char buf[1024];
int fatal = log_level & DI_LOG_FATAL_MASK;
di_log_handler *log_func;
void *user_data=0;
vsnprintf (buf, sizeof (buf), format, args);
log_func = internal_di_log_get_handler (log_level, &user_data);
log_func (log_level, buf, user_data);
if (fatal)
exit (1);
}

References DI_LOG_FATAL_MASK.

## Variable Documentation

## di_log_handler_default

di_log_handler di_log_handler_default

Default log handler. Logs to STDOUT and STDERR.

## di_log_handler_syslog

di_log_handler di_log_handler_syslog

SYSLOG log handler. Logs to SYSLOG.

Referenced by di_system_init().