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

dclog.h

Go to the documentation of this file.
00001 /* =========================================================================
00002  * Copyright (c) 2003-4 Josh Glover <dclog@jmglov.net>
00003  *
00004  * LICENCE:
00005  *
00006  *   This file is distributed under the terms of the BSD License, v2. See
00007  *   the COPYING file, which should have been distributed with this file,
00008  *   for details. If you did not receive the COPYING file, see:
00009  *
00010  *   http://www.jmglov.net/open-source/licences/bsd.html
00011  *
00012  * dclog.h
00013  *
00014  * DESCRIPTION:
00015  *
00016  *   Defines the DCLog class.
00017  *
00018  * USAGE:
00019  *
00020  *   #include <dclog.h>
00021  *
00022  * EXAMPLES:
00023  *
00024  *   See test-dclog.c
00025  *
00026  * TODO:
00027  *
00028  *   - Convert char pointers to arrays in class
00029  *   - Nothing, this code is perfect
00030  *  
00031  * DEPENDENCIES:
00032  *
00033  *   None
00034  *
00035  * MODIFICATIONS:
00036  *
00037  *   Josh Glover <josh.glover@tfcci.com> (2003/09/03): Initial revision
00038  * =========================================================================
00039  */
00040 
00041 #ifndef __DCLOG_H__
00042 #define __DCLOG_H__
00043 
00044 // Standard headers
00045 #include <stdio.h>
00046 #include <time.h>
00047 
00048 // Our headers
00049 #include <common-types.h>
00050 
00051 // Log levels
00052 #define DCLOG_ALARM   0 
00053 #define DCLOG_ERROR   1 
00054 #define DCLOG_WARNING 2 
00055 #define DCLOG_INFO    3 
00056 #define DCLOG_DEBUG   4 
00057 #define DCLOG_PROFILE 5 
00058 
00059 
00060 #define DCLOG_FN_LEN 1024
00061 
00063 #define DCLOG_TS_FMT_LEN 32
00064 
00066 #define DCLOG_TS_FMT_DEFAULT ".%d"
00067 
00069 #define DCLOG_MAX_ALARM_SIZE 4096
00070 
00071 
00081 typedef struct {
00082 
00083   FILE *fp; 
00084   char *fn; 
00085 
00086   char *mailhost;   
00087   char *to;         
00088   char *from;       
00089   char  spool[256]; 
00090   
00091   UCHAR lev;      
00092   UCHAR features; 
00093 
00094   char ts_fmt[DCLOG_TS_FMT_LEN]; 
00095   
00096   struct tm *prev_date; 
00097 
00098   time_t oldtime[1000];  
00099   ULONG  count[1000];    
00100 
00101   int limit_size;    
00102   int max_file_size; 
00103 
00104 } DCLog;
00105 
00106 static const char DCLOG_MAILHOST[] = "localhost";
00107 static const char DCLOG_TO[]       = "root@localhost";
00108 static const char DCLOG_FROM[]     = "localhost";
00109 static const char DCLOG_PROG[]     = "dclog";
00110 static const char DCLOG_SPOOL[]    = "/var/spool/alarmd";
00111 
00112 
00113 // Constructors and destructors
00114 // -------------------------------------------------------------------------
00115 
00116 
00117 DCLog *NewDCLog( void );
00118 UCHAR  DestroyDCLog( DCLog *dclog );
00119 
00120 
00121 // -------------------------------------------------------------------------
00122 
00123 
00124 // Stringifying methods
00125 // -------------------------------------------------------------------------
00126 
00127 
00128 char        DCLogLevelToNum( const char *str );
00129 const char *DCLogLevelToString( const char lev );
00130 
00131 
00132 // -------------------------------------------------------------------------
00133 
00134 
00135 // Setup methods
00136 // -------------------------------------------------------------------------
00137 
00138 
00139 UCHAR DCLogSetHeader( DCLog *dclog, const UCHAR val );
00140 UCHAR DCLogSetLevel( DCLog *dclog, const UCHAR lev );
00141 UCHAR DCLogSetMailServer( DCLog *dclog, const char *mailhost );
00142 UCHAR DCLogSetMaxFileSize( DCLog *dclog, const int size );
00143 UCHAR DCLogSetPageServer( DCLog *dclog, const char *server );
00144 UCHAR DCLogSetPrintLevel( DCLog *dclog, const UCHAR val );
00145 UCHAR DCLogSetProgram( DCLog *dclog, const char *prog );
00146 UCHAR DCLogSetSpool( DCLog *dclog, const char *spool );
00147 UCHAR DCLogSetUniqueByDay( DCLog *dclog, const UCHAR val );
00148 UCHAR DCLogSetTimestampFormat( DCLog *dclog, char *const ts_fmt );
00149 
00150 
00151 // -------------------------------------------------------------------------
00152 
00153 
00154 // Logging methods
00155 // -------------------------------------------------------------------------
00156 
00157 
00158 UCHAR DCLogOpen( DCLog *dclog, const char *fn, const char *mode );
00159 UCHAR DCLogClose( DCLog *dclog );
00160 
00161 UCHAR DCLogAlarm( DCLog *dclog, const char *code, const char *syn,
00162                   const char *fmt, ... );
00163 UCHAR DCLogWrite( DCLog *dclog, const UCHAR lev, const char *fmt, ... );
00164 
00165 
00166 // -------------------------------------------------------------------------
00167 
00168 
00169 // Miscellaneous methods
00170 // -------------------------------------------------------------------------
00171 
00172 
00173 UCHAR DCLogCanLog( const DCLog *dclog );
00174 
00175 
00176 // -------------------------------------------------------------------------
00177 
00178 
00179 /*** Refactor for alarmd ***/
00180 // SMTP-specific functions
00181 // -------------------------------------------------------------------------
00182 
00183 
00184 UCHAR DCLogSmtpSend( const char *mailhost, const char *to, const char *from,
00185                      const char *subject, const char *msg );
00186 UCHAR DCLogSmtpShutdown( const int socket, const int retval );
00187 
00188 
00189 // -------------------------------------------------------------------------
00190 /*** Refactor for alarmd ***/
00191 
00192 
00193 #endif // #ifndef __DCLOG_H__

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