dnxLogging.c File Reference

#include "dnxLogging.h"
#include "dnxError.h"
#include "dnxTransport.h"
#include "dnxDebug.h"
#include <sys/types.h>
#include <sys/stat.h>
#include <stdio.h>
#include <stdarg.h>
#include <string.h>
#include <time.h>
#include <errno.h>
#include <assert.h>
#include <unistd.h>
#include <syslog.h>

Go to the source code of this file.

Defines

#define LOCALSTATEDIR   "/var"
#define LOGDIR   LOCALSTATEDIR "/log"
#define DEF_LOG_FILE   LOGDIR "/dnx.log"
#define DEF_DEBUG_FILE   LOGDIR "/dnx.debug.log"
#define DEF_DEBUG_LEVEL   0
#define MAX_LOG_LINE   4096
 Maximum log line length.
#define SYSLOG_IDENT   "DNX"
 The openlog ident string.

Functions

static int decodeSyslogFlags (const char *flagstr, int defaultSev)
 Decode the syslog flags specified in a comma delimited string.
static FILE * openFile (const char *filename, int *pstd)
 Open a file by name, or use standard handles.
static void dnx_vsyslog (int pri, const char *fmt, va_list ap)
 A version if vsyslog that calls the system version or implements.
static int vlogger (FILE *fp, char *fmt, va_list ap)
 A variable argument logger function that takes a stream.
void dnxLog (char *fmt,...)
 Log a parameterized message to the dnx system log file.
void dnxDebug (int level, char *fmt,...)
 Log a parameterized message to the dnx DEBUG log.
int dnxAudit (char *fmt,...)
 Log a parameterized message to the global audit log file.
void dnxLogInit (char *logFile, char *debugFile, char *auditFile, int *debugLevel)
 Initialize the logging sub-system with global references.

Variables

static char SLTAG [] = "syslog:"
 the syslog prefix tag.
static int defDebugLevel = DEF_DEBUG_LEVEL
 The default debug level.
static int s_syslogLog = 0
 syslog used for logging
static int s_syslogDebug = 0
 syslog used for debug
static int s_syslogAudit = 0
 syslog used for audit
static int * s_debugLevel = &defDebugLevel
 Debug level pointer.
static char s_logFileName [FILENAME_MAX+1] = DEF_LOG_FILE
static char s_dbgFileName [FILENAME_MAX+1] = DEF_DEBUG_FILE
static char s_audFileName [FILENAME_MAX+1] = ""


Define Documentation

#define DEF_DEBUG_FILE   LOGDIR "/dnx.debug.log"

Definition at line 59 of file dnxLogging.c.

#define DEF_DEBUG_LEVEL   0

Definition at line 63 of file dnxLogging.c.

#define DEF_LOG_FILE   LOGDIR "/dnx.log"

Definition at line 55 of file dnxLogging.c.

#define LOCALSTATEDIR   "/var"

Definition at line 49 of file dnxLogging.c.

#define LOGDIR   LOCALSTATEDIR "/log"

Definition at line 52 of file dnxLogging.c.

#define MAX_LOG_LINE   4096

Maximum log line length.

Definition at line 67 of file dnxLogging.c.

#define SYSLOG_IDENT   "DNX"

The openlog ident string.

Definition at line 68 of file dnxLogging.c.


Function Documentation

static int decodeSyslogFlags ( const char *  flagstr,
int  defaultSev 
) [static]

Decode the syslog flags specified in a comma delimited string.

Parameters:
[in] flagstr - a comma-delimited string containing syslog flags
[in] defaultSev - the default severity level to use if none is given in the flagstr parameter.
Returns:
the decoded flags word.

Definition at line 93 of file dnxLogging.c.

static void dnx_vsyslog ( int  pri,
const char *  fmt,
va_list  ap 
) [static]

A version if vsyslog that calls the system version or implements.

Parameters:
[in] pri - the syslog priority value.
[in] fmt - the syslog format string.
[in] ap - the syslog variable argument array.

Definition at line 212 of file dnxLogging.c.

References MAX_LOG_LINE.

int dnxAudit ( char *  fmt,
  ... 
)

Log a parameterized message to the global audit log file.

Returns quickly if auditing is disabled because a null or empty log file was specified on startup.

Parameters:
[in] fmt - a format specifier string similar to that of printf.
Returns:
Zero on success, or a non-zero error value.

Definition at line 328 of file dnxLogging.c.

References dnx_vsyslog(), openFile(), s_audFileName, s_syslogAudit, and vlogger().

void dnxDebug ( int  level,
char *  fmt,
  ... 
)

Log a parameterized message to the dnx DEBUG log.

This routine logs a debug message if the current global (configured) debug level is greater than or equal the value of level.

Parameters:
[in] level - the debug level at which to log the message.
[in] fmt - a format specifier string similar to that of printf.

Definition at line 296 of file dnxLogging.c.

References dnx_vsyslog(), openFile(), s_dbgFileName, s_debugLevel, s_syslogDebug, and vlogger().

void dnxLog ( char *  fmt,
  ... 
)

Log a parameterized message to the dnx system log file.

Parameters:
[in] fmt - a format specifier string similar to that of printf.

Definition at line 264 of file dnxLogging.c.

References dnx_vsyslog(), openFile(), s_logFileName, s_syslogLog, and vlogger().

void dnxLogInit ( char *  logFile,
char *  debugFile,
char *  auditFile,
int *  debugLevel 
)

Initialize the logging sub-system with global references.

System and debug logging defaults to STDOUT. Both "STDOUT" and "STDERR" may be specified as log file strings for the log, debug and audit file paths. The audit log is optional, and is disabled if auditFile is null or empty.

The address of the debug flag is passed so it can change the behavior of the logging system dynamically.

Parameters:
[in] logFile - the global log file path.
[in] debugFile - the global debug file path.
[in] auditFile - the global audit file path (optional).
[in] debugLevel - the address of the global debug level indicator.

Definition at line 362 of file dnxLogging.c.

References decodeSyslogFlags(), s_audFileName, s_dbgFileName, s_debugLevel, s_logFileName, s_syslogAudit, s_syslogDebug, s_syslogLog, SLTAG, and SYSLOG_IDENT.

static FILE* openFile ( const char *  filename,
int *  pstd 
) [static]

Open a file by name, or use standard handles.

Parameters:
[in] filename - the name of the file to be opened.
[out] pstd - storage for returned "standard handle" flag
Returns:
a pointer to an open FILE object.

Definition at line 182 of file dnxLogging.c.

static int vlogger ( FILE *  fp,
char *  fmt,
va_list  ap 
) [static]

A variable argument logger function that takes a stream.

Parameters:
[in] fp - the stream to write to.
[in] fmt - the format string to write.
[in] ap - the argument list to use.
Returns:
zero on success or a non-zero error value if the data could not be written.

Definition at line 235 of file dnxLogging.c.


Variable Documentation

int defDebugLevel = DEF_DEBUG_LEVEL [static]

The default debug level.

Definition at line 71 of file dnxLogging.c.

char s_audFileName[FILENAME_MAX+1] = "" [static]

Definition at line 79 of file dnxLogging.c.

char s_dbgFileName[FILENAME_MAX+1] = DEF_DEBUG_FILE [static]

Definition at line 78 of file dnxLogging.c.

int* s_debugLevel = &defDebugLevel [static]

Debug level pointer.

Definition at line 76 of file dnxLogging.c.

char s_logFileName[FILENAME_MAX+1] = DEF_LOG_FILE [static]

Definition at line 77 of file dnxLogging.c.

int s_syslogAudit = 0 [static]

syslog used for audit

Definition at line 75 of file dnxLogging.c.

int s_syslogDebug = 0 [static]

syslog used for debug

Definition at line 74 of file dnxLogging.c.

int s_syslogLog = 0 [static]

syslog used for logging

Definition at line 73 of file dnxLogging.c.

char SLTAG[] = "syslog:" [static]

the syslog prefix tag.

Definition at line 70 of file dnxLogging.c.


Generated on Tue Apr 13 15:15:29 2010 for DNX by  doxygen 1.5.6