peapod  0.1.0
EAPOL Proxy Daemon
Macros | Functions | Variables
log.c File Reference

Logging operations. More...

#include <stdio.h>
#include <stdarg.h>
#include <string.h>
#include <time.h>
#include "args.h"
#include "defaults.h"
#include "log.h"
#include "peapod.h"
Include dependency graph for log.c:

Macros

#define DAEMONIZED   2
 Console output disabled. More...
 
#define MSGSIZ   1024
 Log message buffer size. More...
 
#define TMSIZ   64
 Timestamp buffer size. More...
 

Functions

static void log_to_file (const char *msg, int level, FILE *out)
 Log a message to a file or to the console. More...
 
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...
 

Variables

static FILE * log_fs = NULL
 Log file. More...
 
static char log_buf [MSGSIZ] = { "" }
 Log message buffer. More...
 
static char log_tm [TMSIZ] = { "" }
 Timestamp buffer. More...
 
struct args_t args
 Program arguments data structure. More...
 
Log level descriptions
static const char * levels []
 Five on-screen characters. More...
 
static const char * clevels []
 Five colorized on-screen characters. More...
 

Detailed Description

Logging operations.

Macro Definition Documentation

#define DAEMONIZED   2

Console output disabled.

#define MSGSIZ   1024

Log message buffer size.

#define TMSIZ   64

Timestamp buffer size.

Function Documentation

static void log_to_file ( const char *  msg,
int  level,
FILE *  out 
)
static

Log a message to a file or to the console.

Messages are timestamped if logging to the console. Messages are additionally datestamped if logging to a file.

Parameters
msgA message to be logged
levelThe level of the message
outFile stream of log file, or NULL to emit to the console
Note
level may be the syslog levels (LOG_EMERG to LOG_DEBUG, i.e. 0 to 7), or our own LOG_DEBUGLOW (8).
Output to console emits to stderr if level is below LOG_WARNING, and to stdout otherwise.
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.

Variable Documentation

const char* levels[]
static
Initial value:
= {
"EMERG", "ALERT", "CRIT ",
"ERROR", "WARN ", "NOTE ",
"INFO ", "DEBUG", "DBGLO"
}

Five on-screen characters.

Used for emitting logs to syslog or to a log file.

const char* clevels[]
static
Initial value:
= {
"\x1b[1;4;91mEMERG\x1b[0m",
"\x1b[1;4;93mALERT\x1b[0m",
"\x1b[1;96mCRIT\x1b[0m ",
"\x1b[1;91mERROR\x1b[0m",
"\x1b[1;95mWARN\x1b[0m ",
"\x1b[1;94mNOTE\x1b[0m ",
"\x1b[1;92mINFO\x1b[0m ",
"DEBUG",
"DBGLO"
}

Five colorized on-screen characters.

Used for emitting logs to the console (stdout / stderr).

FILE* log_fs = NULL
static

Log file.

char log_buf[MSGSIZ] = { "" }
static

Log message buffer.

char log_tm[TMSIZ] = { "" }
static

Timestamp buffer.

struct args_t args

Program arguments data structure.

Note
Global