All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros
Functions | Variables
clixon_log.c File Reference
#include <stdio.h>
#include <stdarg.h>
#include <stdlib.h>
#include <fcntl.h>
#include <unistd.h>
#include <syslog.h>
#include <string.h>
#include <time.h>
#include <errno.h>
#include <assert.h>
#include <sys/time.h>
#include <sys/types.h>
#include "clixon_err.h"
#include "clixon_log.h"


int clicon_log_init (char *ident, int upto, int flags)
clicon_log_notify_t * clicon_log_register_callback (clicon_log_notify_t *cb, void *arg)
static int flogtime (FILE *f)
static char * slogtime (void)
int clicon_log_str (int level, char *msg)
int clicon_log (int level, char *format,...)
int clicon_debug_init (int dbglevel, FILE *f)
int clicon_debug (int dbglevel, char *format,...)
char * mon2name (int md)


int debug = 0
static int _logflags = 0x0
static clicon_log_notify_t * _log_notify_cb = NULL
static void * _log_notify_arg = NULL
static FILE * _debugfile = NULL

Function Documentation

int clicon_debug ( int  dbglevel,
char *  format,

Print a debug message with debug-level. Settings determine where msg appears.

If the dbglevel passed in the function is equal to or lower than the one set by clicon_debug_init(level). That is, only print debug messages <= than what you want: print message if level >= dbglevel. The message is sent to clicon_log. EIther to syslog, stderr or both, depending on clicon_log_init() setting

[in]dbglevel0 always called (dont do this: not really a dbg message) 1 default level if passed -D 2.. Higher debug levels
[in]formatMessage to print as argv.
int clicon_debug_init ( int  dbglevel,
FILE *  f 

Initialize debug messages. Set debug level.

Initialize debug module. The level is used together with clicon_debug(dbglevel) calls as follows: print message if level >= dbglevel. Example: clicon_debug_init(1) -> debug(1) is printed, but not debug(2). Normally, debug messages are sent to clicon_log() which in turn can be sent to syslog and/or stderr. But you can also override this with a specific debug file so that debug messages are written on the file independently of log or errors. This is to ensure that a syslog of normal logs is unpolluted by extensive debugging.

[in]dbglevel0 is show no debug messages, 1 is normal, 2.. is high debug. Note this is not level from syslog(3)
[in]fDebug-file. Open file where debug messages are directed. This overrides the clicon_log settings which is otherwise where debug messages are directed.
int clicon_log ( int  level,
char *  format,

Make a logging call to syslog using variable arg syntax.

See also clicon_log_init() and clicon_log_str()

clicon_log(LOG_NOTICE, "%s: dump to dtd not supported", __PROGRAM__);
[in]levellog level, eg LOG_DEBUG,LOG_INFO,...,LOG_EMERG. Thisis OR:d with facility == LOG_USER
[in]formatMessage to print as argv.
int clicon_log_init ( char *  ident,
int  upto,
int  flags 

Initialize system logger.

Make syslog(3) calls with specified ident and gates calls of level upto specified level (upto). May also print to stderr, if err is set. Applies to clicon_err() and clicon_debug too

[in]identprefix that appears on syslog (eg 'cli')
[in]uptolog priority, eg LOG_DEBUG,LOG_INFO,...,LOG_EMERG (see syslog(3)).
[in]flagsbitmask: if CLICON_LOG_STDERR, then print logs to stderr if CLICON_LOG_SYSLOG, then print logs to syslog You can do a combination of both
clicon_log_init(__PROGRAM__, LOG_INFO, CLICON_LOG_STDERR);
clicon_log_notify_t* clicon_log_register_callback ( clicon_log_notify_t *  cb,
void *  arg 

Register log callback, return old setting

int clicon_log_str ( int  level,
char *  msg 

Make a logging call to syslog (or stderr).

This is the only place the actual syslog (or stderr) logging is made in clicon,..

yslog makes itw own filtering, but if log to stderr we do it here
See Also
[in]levellog level, eg LOG_DEBUG,LOG_INFO,...,LOG_EMERG. Thisis OR:d with facility == LOG_USER
[in]msgMessage to print as argv.
static int flogtime ( FILE *  f)

Mimic syslog and print a time on file f

char* mon2name ( int  md)

Translate month number (0..11) to a three letter month name

[in]mdmonth number, where 0 is january
static char* slogtime ( void  )

Variable Documentation

FILE* _debugfile = NULL
void* _log_notify_arg = NULL
clicon_log_notify_t* _log_notify_cb = NULL
int _logflags = 0x0
int debug = 0