Main Page   Data Structures   File List   Data Fields   Globals   Related Pages  

logger.c File Reference

PDepp's logger module. More...

#include "common.h"
#include <assert.h>
#include <errno.h>
#include <unistd.h>
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
#include <time.h>
#include "logger.h"
#include "buffer.h"
#include "conftable.h"
#include "fileplist.h"
#include "loggerlist.h"
#include "misc.h"
#include "xmalloc.h"

Include dependency graph for logger.c:

Include dependency graph

Go to the source code of this file.

Data Structures

struct  Logger
 internal representation of a Logger object. More...


Defines

#define lgGetSrcDescText(src)   (((src) <= LOG_SRC_LAST) ? (log_src_info_tab[src][0]) : "unknown source")
 returns a descriptive string corresponding to a log source macro.

#define lgGetSrcConfKey(src)   (((src) <= LOG_SRC_LAST) ? (log_src_info_tab[src][1]) : "U")
 returns the conftable key corresponding to a log source macro.

#define lgGetSrcDescMaxLen()   (lgGetSrcMaxLen(0))
 returns the maximum length of the descriptive strings of all log mesg sources.

#define lgGetSrcKeyMaxLen()   (lgGetSrcMaxLen(1))
 returns the maximum length of the contable keys of all log mesg sources.

#define lgGetLvlConfKey(lvl)   (((lvl) <= LOG_LVL_LAST) ? log_lvl_info_tab[lvl] : "u")
 returns the conftable key corresponding to a log severity level macro.


Functions

size_t lgGetSrcMaxLen (int which)
 returns the maximum length of src desc strings (which=0) or src conf key strings (which=1).

size_t lgGetLvlKeyMaxLen ()
 returns the maximum length of the sev. level conf key strings.

int logClose (Logger this)
 internal function: closes the current logfile. returns 0 on success.

Logger logInitStream_int (FILE *log_stream, const char *format, int manage_stream)
 internal function: initialise Logger object from a stream.

Logger logInit (const char *file_name, const char *format)
 opens a new logfile. returns 0 an success. More...

Logger logInitStream (FILE *log_stream, const char *format)
 sets the current logging stream to use the given stream log_stream. More...

int logMessagev (Logger this, const unsigned int origin, const unsigned int severity, const int errno_val, const char *const log_text_format, va_list daten)
 Low level function to write a message into on specific Logger object. May well become an internal function in the near future.

int logTerminate (Logger this)
 terminates a Logger object. More...

int addLogger2List (Logger lgr, int src, int lvl, const char *origin_flags)
 adds a logger to the logger matrix if enabled by the origin_flags.

char * int2str (int i)
 converts an int (-99 <= i <= 999) to a char. More...

int logfilesInit ()
 initialises the logging subsystem. More...

int logfilesTerminate ()
 shuts down the logging subsystem. More...

int logerr (const unsigned int origin, const unsigned int severity, const int errno_val, const char *const log_text_format,...)
 writes an error message with error code description. More...

int logger (const unsigned int origin, const unsigned int severity, const char *const log_text_format,...)
 writes a generic logging message. More...


Variables

LoggerList loggers [7+1][5+1]
 2D matrix of loggers for all sources and severity levels.

FilepList log_streams
 list of all open log streams.


Detailed Description

PDepp's logger module.

Definition in file logger.c.


Function Documentation

char * int2str int    i [inline]
 

converts an int (-99 <= i <= 999) to a char.

Bug:
Must NOT be used two or more times as a function parameter in the same function call!!! (That's not really a bug, more some kind of limitation...)

Definition at line 636 of file logger.c.

Referenced by logfilesInit().

Logger logInit const char *    file_name,
const char *    format
 

opens a new logfile. returns 0 an success.

Configures the logger to use file_name as the default logging output stream.

Parameters:
file_name  Name of a file system entity that can be opened as a stream.
Returns:
Returns a valid logger object on success and NULL on failure.

Definition at line 144 of file logger.c.

Logger logInitStream FILE *    log_stream,
const char *    format
 

sets the current logging stream to use the given stream log_stream.

Configures logger to use log_stream as its default output stream.

Parameters:
log_stream  a valid output stream
Returns:
Returns a valid Logger object on success and NULL on failure.

Definition at line 161 of file logger.c.

int logTerminate Logger    this
 

terminates a Logger object.

Parameters:
this  a Logger object
The Logger object this destroyed and all ressources allocated by it are freed. The logging stream itself is only freed if it has been opened by logInit(). If the Logger object has been created using logInitStream() the stream is not changed by this function.

Returns:
0 on success, -1 on failure

Definition at line 264 of file logger.c.

int logerr const unsigned int    source,
const unsigned int    severity,
const int    errno_val,
const char *const    log_text_format,
...   
 

writes an error message with error code description.

Parameters:
source  a valid log message source macro as defined in logger.h
severity  a valid severity level macro as defined in logger.h
errno_val  an errno error value returned by a libc function
log_text_format  a "printf()"-style format string containing the log message
...  additional informational parameters as described by the format string
The log message is written to all logging streams configured with logfilesInit(), formattet according to log_text_format and the format assigned to the logging stream used.

Returns:
0 on success, -1 on failure

Definition at line 569 of file logger.c.

int logfilesInit  
 

initialises the logging subsystem.

Todo:
Split this function into several independant subroutines... ;-)

Store identical format strings only once instead of copying them for every logger.

Bug:
A primary logfile (logfile=) should not be required. Right now it is...

Definition at line 295 of file logger.c.

Referenced by main().

int logfilesTerminate  
 

shuts down the logging subsystem.

Frees all ressources allocated by the logging system and closes all logging streams. Do not use logger or logerr after calling this function!

Returns:
0 on success, -1 on failure

Definition at line 542 of file logger.c.

Referenced by main().

int logger const unsigned int    origin,
const unsigned int    severity,
const char *const    log_text,
...   
 

writes a generic logging message.

Parameters:
source  a valid log message source macro as defined in logger.h
severity  a valid severity level macro as defined in logger.h
log_text_format  a "printf()"-style format string containing the log message
...  additional informational parameters as described by the format string
The log message is written to all logging streams configured with logfilesInit(), formattet according to log_text_format and the format assigned to the logging stream used.

Returns:
0 on success, -1 on failure

Definition at line 589 of file logger.c.


Generated on Fri Jan 25 22:40:51 2002 for PDepp Webserver by doxygen1.2.11.1 written by Dimitri van Heesch, © 1997-2001