libdebian-installer
Macros | Typedefs | Enumerations | Functions | Variables
Logging

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

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

logs debug info

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

logs an error

Referenced by di_malloc(), di_malloc0(), and di_realloc().

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

logs information

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

logs a warning

Referenced by di_parser_rfc822_read().

Enumeration Type Documentation

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

34 {
35  DI_LOG_FLAG_FATAL = 1 << 1,
37  DI_LOG_LEVEL_ERROR = 1 << 2,
38  DI_LOG_LEVEL_CRITICAL = 1 << 3,
39  DI_LOG_LEVEL_WARNING = 1 << 4,
40  DI_LOG_LEVEL_MESSAGE = 1 << 5,
41  DI_LOG_LEVEL_INFO = 1 << 6,
42  DI_LOG_LEVEL_DEBUG = 1 << 7,
43  DI_LOG_LEVEL_OUTPUT = 1 << 8,
47 }

Function Documentation

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

Logs the resolved formatstring with log_level

Parameters
log_levelthe level of the message
formatprintf compatible format
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_levelslevels
log_functhe log handler
user_datadata for log_func

References di_new, di_slist_append(), di_log_handler_struct::id, di_log_handler_struct::log_func, di_log_handler_struct::log_level, and di_log_handler_struct::user_data.

Referenced by di_system_init().

190 {
191  static unsigned int handler_id = 0;
192  di_log_handler_struct *handler;
193 
194  handler = di_new (di_log_handler_struct, 1);
195 
196  handler->id = ++handler_id;
197  handler->log_level = log_levels;
198  handler->log_func = log_func;
199  handler->user_data = user_data;
200 
201  di_slist_append (&handlers, handler);
202 
203  return handler_id;
204 }
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_levelthe level of the message
formatprintf compatible format
argsvariable arguments list

References DI_LOG_FATAL_MASK.

218 {
219  char buf[1024];
220  int fatal = log_level & DI_LOG_FATAL_MASK;
221  di_log_handler *log_func;
222  void *user_data=0;
223 
224  vsnprintf (buf, sizeof (buf), format, args);
225 
226  log_func = internal_di_log_get_handler (log_level, &user_data);
227 
228  log_func (log_level, buf, user_data);
229 
230  if (fatal)
231  exit (1);
232 }

Variable Documentation

di_log_handler di_log_handler_default

Default log handler. Logs to STDOUT and STDERR.

di_log_handler di_log_handler_syslog

SYSLOG log handler. Logs to SYSLOG.

Referenced by di_system_init().