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

dclog.h File Reference

#include <stdio.h>
#include <time.h>
#include <common-types.h>

Go to the source code of this file.

Data Structures

struct  DCLog

Defines

#define DCLOG_ALARM   0
 alarms

#define DCLOG_ERROR   1
 error messages

#define DCLOG_WARNING   2
 warnings

#define DCLOG_INFO   3
 information messages

#define DCLOG_DEBUG   4
 debugging messages

#define DCLOG_PROFILE   5
 profiling messages

#define DCLOG_FN_LEN   1024
 Length of our filename string.

#define DCLOG_TS_FMT_LEN   32
 Length of our timestamp strfime format string.

#define DCLOG_TS_FMT_DEFAULT   ".%d"
 Default timestamp strfime format string.

#define DCLOG_MAX_ALARM_SIZE   4096
 Maximum size of an alarm email.


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 DCLogAlarm (DCLog *dclog, const char *code, const char *syn, const char *fmt,...)
UCHAR DCLogWrite (DCLog *dclog, const UCHAR lev, const char *fmt,...)
UCHAR DCLogCanLog (const DCLog *dclog)
UCHAR DCLogSmtpSend (const char *mailhost, const char *to, const char *from, const char *subject, const char *msg)
UCHAR DCLogSmtpShutdown (const int socket, const int retval)


Define Documentation

#define DCLOG_ALARM   0
 

alarms

#define DCLOG_DEBUG   4
 

debugging messages

#define DCLOG_ERROR   1
 

error messages

#define DCLOG_FN_LEN   1024
 

Length of our filename string.

#define DCLOG_INFO   3
 

information messages

#define DCLOG_MAX_ALARM_SIZE   4096
 

Maximum size of an alarm email.

#define DCLOG_PROFILE   5
 

profiling messages

#define DCLOG_TS_FMT_DEFAULT   ".%d"
 

Default timestamp strfime format string.

#define DCLOG_TS_FMT_LEN   32
 

Length of our timestamp strfime format string.

#define DCLOG_WARNING   2
 

warnings


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 DCLogSmtpSend const char *  mailhost,
const char *  to,
const char *  from,
const char *  subject,
const char *  msg
 

UCHAR DCLogSmtpShutdown const int  socket,
const int  retval
 

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