peapod  0.1.0
EAPOL Proxy Daemon
Functions
log.h File Reference

Function prototypes for log.c, global logging macros. More...

#include <errno.h>
#include <syslog.h>
Include dependency graph for log.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

A new log level less severe/more verbose than LOG_DEBUG

The syslog levels range from LOG_EMERG to LOG_DEBUG (0 to 7). Messages at this new level aren't even emitted to syslog.

#define LOG_DEBUGLOW   8
 
Function-like stderr output macros

Usage is like printf(3). Used during early program startup to print to stderr, before logging is even fully initialized. ceerr() adds strerror(errno) as the last argument, i.e.

ceerr("Error %d: %s", errno);

is equivalent to

cerr("Error %d: %s", errno, strerror(errno));
#define cerr(...)   fprintf(stderr, __VA_ARGS__)
 
#define ceerr(...)   cerr(__VA_ARGS__, strerror(errno))
 
Function-like logging macros

Usage is like printf(3).

  • Names range from emerg() for logging with level LOG_EMERG to debug for LOG_DEBUG in addition to debuglow() for our own LOG_DEBUGLOW.
  • The prefix 'l' adds file and line number information to the message (however, those macros were only used during development).
  • The prefix 'e' adds strerror(errno) as the last argument, i.e.
    eerr("Error %d: %s", errno);
    is equivalent to
    err("Error %d: %s", errno, strerror(errno));
  • The suffix 'die' also calls exit(3) with code EXIT_FAILURE.
#define emerg(...)   log_msg(LOG_EMERG, NULL, 0, __VA_ARGS__)
 
#define alert(...)   log_msg(LOG_ALERT, NULL, 0, __VA_ARGS__)
 
#define crit(...)   log_msg(LOG_CRIT, NULL, 0, __VA_ARGS__)
 
#define err(...)   log_msg(LOG_ERR, NULL, 0, __VA_ARGS__)
 
#define warning(...)   log_msg(LOG_WARNING, NULL, 0, __VA_ARGS__)
 
#define notice(...)   log_msg(LOG_NOTICE, NULL, 0, __VA_ARGS__)
 
#define info(...)   log_msg(LOG_INFO, NULL, 0, __VA_ARGS__)
 
#define debug(...)   log_msg(LOG_DEBUG, NULL, 0, __VA_ARGS__)
 
#define debuglow(...)   log_msg(LOG_DEBUGLOW, NULL, 0, __VA_ARGS__)
 
#define lemerg(...)   log_msg(LOG_EMERG, __FILE__, __LINE__, __VA_ARGS__)
 
#define lalert(...)   log_msg(LOG_ALERT, __FILE__, __LINE__, __VA_ARGS__)
 
#define lcrit(...)   log_msg(LOG_CRIT, __FILE__, __LINE__, __VA_ARGS__)
 
#define lerr(...)   log_msg(LOG_ERR, __FILE__, __LINE__, __VA_ARGS__)
 
#define lwarning(...)   log_msg(LOG_WARNING, __FILE__, __LINE__, __VA_ARGS__)
 
#define lnotice(...)   log_msg(LOG_NOTICE, __FILE__, __LINE__, __VA_ARGS__)
 
#define linfo(...)   log_msg(LOG_INFO, __FILE__, __LINE__, __VA_ARGS__)
 
#define ldebug(...)   log_msg(LOG_DEBUG, __FILE__, __LINE__, __VA_ARGS__)
 
#define ecrit(...)   crit(__VA_ARGS__, strerror(errno))
 
#define eerr(...)   err(__VA_ARGS__, strerror(errno))
 
#define ewarning(...)   warning(__VA_ARGS__, strerror(errno))
 
#define einfo(...)   info(__VA_ARGS__, strerror(errno))
 
#define critdie(...)   do { crit(__VA_ARGS__); exit(EXIT_FAILURE); } while (0)
 
#define ecritdie(...)   do { ecrit(__VA_ARGS__); exit(EXIT_FAILURE); } while (0)
 

Functions

int log_init (void)
 Initialize logging. More...
 
int log_daemonize (void)
 Prepare logging when daemonizing. More...
 
void log_msg (int level, const char *file, int line, const char *fmt,...)
 Log a message. More...
 

Detailed Description

Function prototypes for log.c, global logging macros.

Macro Definition Documentation

#define LOG_DEBUGLOW   8
#define cerr (   ...)    fprintf(stderr, __VA_ARGS__)
#define ceerr (   ...)    cerr(__VA_ARGS__, strerror(errno))
#define emerg (   ...)    log_msg(LOG_EMERG, NULL, 0, __VA_ARGS__)
#define alert (   ...)    log_msg(LOG_ALERT, NULL, 0, __VA_ARGS__)
#define crit (   ...)    log_msg(LOG_CRIT, NULL, 0, __VA_ARGS__)
#define err (   ...)    log_msg(LOG_ERR, NULL, 0, __VA_ARGS__)
#define warning (   ...)    log_msg(LOG_WARNING, NULL, 0, __VA_ARGS__)
#define notice (   ...)    log_msg(LOG_NOTICE, NULL, 0, __VA_ARGS__)
#define info (   ...)    log_msg(LOG_INFO, NULL, 0, __VA_ARGS__)
#define debug (   ...)    log_msg(LOG_DEBUG, NULL, 0, __VA_ARGS__)
#define debuglow (   ...)    log_msg(LOG_DEBUGLOW, NULL, 0, __VA_ARGS__)
#define lemerg (   ...)    log_msg(LOG_EMERG, __FILE__, __LINE__, __VA_ARGS__)
#define lalert (   ...)    log_msg(LOG_ALERT, __FILE__, __LINE__, __VA_ARGS__)
#define lcrit (   ...)    log_msg(LOG_CRIT, __FILE__, __LINE__, __VA_ARGS__)
#define lerr (   ...)    log_msg(LOG_ERR, __FILE__, __LINE__, __VA_ARGS__)
#define lwarning (   ...)    log_msg(LOG_WARNING, __FILE__, __LINE__, __VA_ARGS__)
#define lnotice (   ...)    log_msg(LOG_NOTICE, __FILE__, __LINE__, __VA_ARGS__)
#define linfo (   ...)    log_msg(LOG_INFO, __FILE__, __LINE__, __VA_ARGS__)
#define ldebug (   ...)    log_msg(LOG_DEBUG, __FILE__, __LINE__, __VA_ARGS__)
#define ecrit (   ...)    crit(__VA_ARGS__, strerror(errno))
#define eerr (   ...)    err(__VA_ARGS__, strerror(errno))
#define ewarning (   ...)    warning(__VA_ARGS__, strerror(errno))
#define einfo (   ...)    info(__VA_ARGS__, strerror(errno))
#define critdie (   ...)    do { crit(__VA_ARGS__); exit(EXIT_FAILURE); } while (0)
#define ecritdie (   ...)    do { ecrit(__VA_ARGS__); exit(EXIT_FAILURE); } while (0)

Function Documentation

int log_init ( void  )

Initialize logging.

Returns
0 if successful, or -1 if unsuccessful
int log_daemonize ( void  )

Prepare logging when daemonizing.

Returns
0 if successful, or -1 if unsuccessful
void log_msg ( int  level,
const char *  file,
int  line,
const char *  fmt,
  ... 
)

Log a message.

Depending on the program arguments and the value of level, the same message is emitted to console (stdout/stderr), a log file, and/or syslog.

Parameters
levelThe level of the message
fileOrdinarily NULL
lineOrdinarily 0
fmt,...printf(3)-style format and variable arguments
Note
level may be the syslog levels (LOG_EMERG to LOG_DEBUG, i.e. 0 to 7), or our own LOG_DEBUGLOW (8).
file and line are the __FILE__ and __LINE__ macros, i.e. the source file and the line in the source file of the call to log_msg(). They were used during development only in the lfoo() logging macros defined in log.h.