Specifications
CHAPTER 5. IMPLEMENTATION 34
org) which is released under the terms of the Academic Free License version 2.0. The logging
system is implemented by libial log.c and libial log.h. It provides four different prior-
ities: LOGPRI ERROR, LOGPRI WARNING, LOGPRI INFO and LOGPRI DEBUG—with LOGPRI ERROR
being the highest and LOGPRI DEBUG being the lowest priority. The priorities are realized as
an enumeration ranging from 0 to 3 :
enum {
LOGPRI_ERROR = 0,
LOGPRI_WARNING = 1,
LOGPRI_INFO = 2,
LOGPRI_DEBUG = 3
};
Each priority has a corresponding macro defined in libial log.h. These macros are
used by the daemon and the modules to issue log entries. Errors are issued by using the
macro ERROR(expr ). Correspondingly, warnings are issued using the macro WARNING(expr ),
informative messages are issued using INFO(expr ) and debug messages are issued using the
macro DEBUG(expr ). All macros are invoked in the same way as printf(3): the format of expr
is the corresponding format string. The variable priority (libial log.c) contains the current
log level priority. It is set by the daemon using the library’s function log level set(). Once
the log level is set, only log messages less than or equal to the current log level are reported.
The lowest log level is LOGPRI ERROR (0 ) which ensures that errors are always reported. The
following example shows the detailed application flow of the logging system on the basis of the
macro INFO(expr ). The macro is defined as:
#define INFO(expr) \
do { \
log_setup(LOGPRI_INFO, __FILE__, __LINE__, __FUNCTION__); \
log_output expr; \
} while(0)
The three other macros are implemented in the exact same way. The only difference is the
first argument passed to log setup() which always corresponds to the macro:
– ERROR(expr ) calls log setup() with LOGPRIO ERROR
– WARNING(expr ) calls log setup() with LOGPRIO WARNING
– DEBUG(expr ) calls log setup() with LOGPRIO DEBUG
Granted that the daemon issues the log entry INFO(("Initialization successful."))
in the function main() at line 397 of iald.c, the preprocessor dissolves the macro to the
following code:
do {
log_setup(LOGPRI_INFO, "iald.c", 397, __FUNCTION__);
log_output("Initialization successful.");
} while(0);