libusual  0.1
Defines | Typedefs | Functions | Variables
usual/logging.h File Reference

Logging framework for unix services. More...

Defines

#define LOG_CONTEXT_DEF
 Example: Prepare dummy context pointer.
#define LOG_CONTEXT
 Example: Reference dummy context pointer.
#define log_error(...)
 Log error message.
#define log_warning(...)
 Log warning message.
#define log_stats(...)
 Log stats (liveness) message.
#define log_info(...)
 Log info message.
#define log_debug(...)
 Log debug message.
#define log_noise(...)
 Log debug noise.
#define fatal(...)
 Log and die.
#define fatal_perror(...)
 Log strerror and die.
#define die(...)
 Less verbose fatal()

Typedefs

typedef int(* logging_prefix_fn_t )(enum LogLevel lev, void *ctx, char *dst, unsigned int dstlen)
 Signature for logging_prefix_cb.

Functions

void reset_logging (void)
 Close open logfiles and syslog.

Variables

logging_prefix_fn_t logging_prefix_cb
 Optional global callback for each log line.
int cf_verbose
 Global verbosity level.
int cf_quiet
 Toggle logging to stderr.
const char * cf_logfile
 Logfile location, default NULL.
int cf_syslog
 Syslog on/off.
const char * cf_syslog_ident
 ident for syslog, if NULL syslog is disabled (default)
const char * cf_syslog_facility
 Facility name.
enum LogLevel cf_syslog_level
 Max log level for syslog writer.
enum LogLevel cf_logfile_level
 Max log level for logfile writer.
enum LogLevel cf_stderr_level
 Max log level for stderr writer.

Detailed Description

Logging framework for unix services.

Supported outputs:

Logging context

It is possible to pass context info to all logging calls and later add details to log lines or to filter based on it.

Each call references 2 macros:

Later, global callback function logging_prefix_cb will get this pointer with destination buffer and can either add more info for log line or tell to skip logging this message.


Define Documentation

#define LOG_CONTEXT_DEF

Example: Prepare dummy context pointer.

#define LOG_CONTEXT

Example: Reference dummy context pointer.

#define log_error (   ...)

Log error message.

#define log_warning (   ...)

Log warning message.

#define log_stats (   ...)

Log stats (liveness) message.

#define log_info (   ...)

Log info message.

#define log_debug (   ...)

Log debug message.

#define log_noise (   ...)

Log debug noise.

#define fatal (   ...)

Log and die.

It also logs source location

#define fatal_perror (   ...)

Log strerror and die.

Error message also includes strerror(errno)

#define die (   ...)

Less verbose fatal()


Typedef Documentation

typedef int(* logging_prefix_fn_t)(enum LogLevel lev, void *ctx, char *dst, unsigned int dstlen)

Signature for logging_prefix_cb.

Return value is either added string length in dst or negative value to skip logging.


Function Documentation

void reset_logging ( void  )

Close open logfiles and syslog.

Useful when rotating log files.


Variable Documentation

Optional global callback for each log line.

It can either add info to log message or skip logging it.

Global verbosity level.

0 - show only info level msgs (default) 1 - show debug msgs (log_debug) 2 - show noise msgs (log_noise)

int cf_quiet

Toggle logging to stderr.

Default: 1. daemon.c turns this off if goes to background

const char* cf_logfile

Logfile location, default NULL.

int cf_syslog

Syslog on/off.

const char* cf_syslog_ident

ident for syslog, if NULL syslog is disabled (default)

const char* cf_syslog_facility

Facility name.

enum LogLevel cf_syslog_level

Max log level for syslog writer.

enum LogLevel cf_logfile_level

Max log level for logfile writer.

enum LogLevel cf_stderr_level

Max log level for stderr writer.