Main Page | Data Structures | File List | Data Fields | Globals

dclog.c File Reference

#include <sys/socket.h>
#include <sys/time.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <errno.h>
#include <fcntl.h>
#include <netdb.h>
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <unistd.h>
#include <netinet/in.h>
#include <dclog.h>

Defines

#define DCLOG_FEAT_HEADER   1 << 0
 see DCLogSetHeader()

#define DCLOG_FEAT_UNIQUE   1 << 1
 see DCLogSetUniqueByDay()

#define DCLOG_FEAT_PLEVEL   1 << 2
 see DCLogSetPrintLevel()


Functions

DCLogNewDCLog (void)
UCHAR DestroyDCLog (DCLog *dclog)
char DCLogLevelToNum (const char *str)
const char * DCLogLevelToString (const char lev)
UCHAR DCLogSetHeader (DCLog *dclog, const UCHAR val)
UCHAR DCLogSetLevel (DCLog *dclog, const UCHAR lev)
UCHAR DCLogSetMailServer (DCLog *dclog, const char *mailhost)
UCHAR DCLogSetMaxFileSize (DCLog *dclog, const int size)
UCHAR DCLogSetPageServer (DCLog *dclog, const char *server)
UCHAR DCLogSetPrintLevel (DCLog *dclog, const UCHAR val)
UCHAR DCLogSetProgram (DCLog *dclog, const char *prog)
UCHAR DCLogSetSpool (DCLog *dclog, const char *spool)
UCHAR DCLogSetUniqueByDay (DCLog *dclog, const UCHAR val)
UCHAR DCLogSetTimestampFormat (DCLog *dclog, char *const ts_fmt)
UCHAR DCLogOpen (DCLog *dclog, const char *fn, const char *mode)
UCHAR DCLogClose (DCLog *dclog)
UCHAR DCLogWrite (DCLog *dclog, const UCHAR lev, const char *fmt,...)
UCHAR DCLogAlarm (DCLog *dclog, const char *code, const char *syn, const char *fmt,...)
UCHAR DCLogCanLog (const DCLog *dclog)

Define Documentation

#define DCLOG_FEAT_HEADER   1 << 0
 

see DCLogSetHeader()

#define DCLOG_FEAT_PLEVEL   1 << 2
 

see DCLogSetPrintLevel()

#define DCLOG_FEAT_UNIQUE   1 << 1
 

see DCLogSetUniqueByDay()


Function Documentation

UCHAR DCLogAlarm DCLog dclog,
const char *  code,
const char *  syn,
const char *  fmt,
... 
 

Sends an alarm.

Forks a child process, calls the function specified by the fp function pointer argument (if fp is NULL, no function is called), connects to the SMTP mail server (which should have been set by DCLogSetMailServer()), and sends an alarm email of the following format:

From: [program, set by DCLogSetProgram()]@[hostname]. To: [page server, set by DCLogSetPageServer()]. Subject: [code] : [syn]. Body: [controlled by format string fmt].

Parameters:
*dclog pointer to a DCLog object
code alarm code
syn alarm synopsis
fmt detailed description (printf-style format string)
... arguments to the format string
Returns:
1 on success, 0 on failure

UCHAR DCLogCanLog const DCLog dclog  ) 
 

Makes sure the object is able to log.

Parameters:
*dclog pointer to a DCLog object
Returns:
1 on success, 0 on failure

UCHAR DCLogClose DCLog dclog  ) 
 

Closes an open logfile.

Parameters:
*dclog pointer to a DCLog object
Returns:
1 on success, 0 on failure

char DCLogLevelToNum const char *  str  ) 
 

Returns the numeric log level for the specified string representation.

Parameters:
*str string representation of a log level
Returns:
numeric log level on success, -1 on error

const char* DCLogLevelToString const char  lev  ) 
 

Returns the string representation of the specified numeric log level.

Parameters:
lev numeric log level
Returns:
string representation of a log level on success, NULL on error

UCHAR DCLogOpen DCLog dclog,
const char *  fn,
const char *  mode
 

Opens a logfile.

If the unique_by_day member of the DCLog object is set to true, the day of the month will be appended to the filename of the logfile (see DCLogSetUniqueByDay, above).

Parameters:
*dclog pointer to a DCLog object
fn fully qualified filename
mode mode for opening file (w truncates, a appends)
Returns:
1 on success, 0 on failure

UCHAR DCLogSetHeader DCLog dclog,
const UCHAR  val
 

Turns the log header on or off.

If on, each log message will be appended to the timestamp and process ID (e.g. 15:27:13.05 [2727]: test for echo).

Parameters:
*dclog pointer to a DCLog object
val 1 for on, 0 for off
Returns:
1 on success, 0 on failure

UCHAR DCLogSetLevel DCLog dclog,
const UCHAR  lev
 

Sets the logging level.

Parameters:
*dclog pointer to a DCLog object
lev logging level (messages with a higher level will not be logged)
Returns:
1 on success, 0 on failure

UCHAR DCLogSetMailServer DCLog dclog,
const char *  mailhost
 

Sets the hostname of the SMTP mail server.

Alarm emails will be sent through this mail server.

Parameters:
*dclog pointer to a DCLog object
mailhost email address of the server
Returns:
1 on success, 2 on failure.

UCHAR DCLogSetMaxFileSize DCLog dclog,
const int  size
 

Sets maximum file size and turns on size limits.

Parameters:
*dclog pointer to a DCLog object
size maximum file size, in bytes
Returns:
1 on success, 0 on error

UCHAR DCLogSetPageServer DCLog dclog,
const char *  server
 

Sets the page server's email address.

Alarm emails will be sent to this address.

Parameters:
*dclog pointer to a DCLog object
server email address of the server
Returns:
1 on success, 0 on failure.

UCHAR DCLogSetPrintLevel DCLog dclog,
const UCHAR  val
 

Turns printing the message level on or off.

If on, each log message will be appended to the mnemonic level at which it was logged (e.g. messages logged at DCLOG_DEBUG would look like: "DEBUG some message or other").

Parameters:
*dclog pointer to a DCLog object
val 1 for on, 0 for off
Returns:
1 on success, 0 on failure

UCHAR DCLogSetProgram DCLog dclog,
const char *  prog
 

Sets the program name that will be used when alarming.

The from address in the alarm email will be program_name, where program_name is set by this function, and hostname is the hostname of the machine on which your code is running.

Parameters:
*dclog pointer to a DCLog object
*prog program string
Returns:
1 on success, 0 on failure

UCHAR DCLogSetSpool DCLog dclog,
const char *  spool
 

Sets the alarm spool directory.

Parameters:
*dclog pointer to a DCLog object
*spool spool directory
Returns:
1 on success, 0 on failure

UCHAR DCLogSetTimestampFormat DCLog dclog,
char *const  ts_fmt
 

Sets the timestamp format string and turns the unique feature on

Parameters:
*dclog pointer to a DCLog object
ts_fmt strftime(3) time format string
Returns:
1 on success, 0 on failure

UCHAR DCLogSetUniqueByDay DCLog dclog,
const UCHAR  val
 

Turns unique logfiles on or off.

If on, each logfile will get the day of the month appended to it (e.g. my_logfile.27 versus my_logfile). Setting this after the logfile is opened does not make a whole lot of sense.

Parameters:
*dclog pointer to a DCLog object
val 1 for on, 0 for off
Returns:
1 on success, 0 on failure

UCHAR DCLogWrite DCLog dclog,
const UCHAR  lev,
const char *  fmt,
... 
[inline]
 

Writes a message to an open logfile at the specified level.

If the global logging level for this object is lower than the specified level, the mesage will not be logged, but success will be returned. If the ts_header member of the DCLog object is set to true, a timestamp / PID header will be written before every log message (see DCLogSetHeader(), above). No newline is appended to your message, so if you want one, put it in your format string. If the level is zero, "ERROR: " will be written before the message.

Parameters:
*dclog pointer to a DCLog object
lev level of this log message
fmt printf-style format string
... arguments to the format string
Returns:
1 on success, 0 on failure

UCHAR DestroyDCLog DCLog dclog  ) 
 

Destroys a log object that is no longer needed.

Parameters:
*dclog pointer to a DCLog object
Returns:
1 on success, 0 on failure

DCLog* NewDCLog void   ) 
 

Constructer; creates a new DCLog object.

Returns:
pointer to the newly created DCLog object


Generated on Sun Feb 27 14:27:07 2005 for dclog by doxygen 1.3.5