00001
00002
00003
00004
00005
00006 #ifndef dsLog_h
00007 #define dsLog_h
00008
00009 #ifdef HAVE_CONFIG_H
00010 # include <config.h>
00011 #endif
00012
00013 #include <stdio.h>
00014 #include <stdlib.h>
00015 #include <string.h>
00016 #include <stdarg.h>
00017 #include <fcntl.h>
00018 #include <time.h>
00019
00020 #ifdef HAVE_UNISTD_H
00021 # include <unistd.h>
00022 #endif
00023
00024 #ifdef HAVE_IO_H
00025 # include <io.h>
00026 #endif
00027
00028 #include <dsSmartException.h>
00029 #include <dsMD5.h>
00030 #include <dsStrstream.h>
00031 #include <dsform.h>
00032
00033 DECLARE_EXCEPTION(dsLog);
00034
00035 #define LOG_ALWAYS 0xFF
00036 #define LOG_NONE 0
00037
00038
00042 class dsLog
00043 {
00044 public:
00045
00049 enum dsLogOpenFlags{
00050 LOG_OF_NONE=0,
00051 LOG_OF_APPEND=1,
00052 LOG_OF_TRUNCATE=2,
00053 LOG_OF_ROTATE=4,
00054 };
00055
00056 protected:
00057
00058 int _mode;
00059 char* _fname;
00060 int _fd;
00061
00062 void rotate(char *logname);
00063
00064 dsLogOpenFlags _openflags;
00065
00066 public:
00073 dsLog(long mode, char *logname, dsLogOpenFlags openflags = LOG_OF_APPEND);
00074 ~dsLog();
00075
00079 int mode(int mode = -1);
00080
00088
00089 void log(int mode, const char *format, ... );
00090 void log(int mode, dsStrstream& inmsg);
00091 void vlog(int mode, const char *format, va_list ap);
00093
00094 };
00095
00096 inline int dsLog::mode(int mode)
00097 { int old_mode = _mode;
00098 if (mode > 0)
00099 _mode = mode;
00100 return old_mode;
00101 }
00102
00103 inline dsLog::dsLogOpenFlags LogFlags(char *str)
00104 {
00105 int rc = 0;
00106 if ( strstr(str, "LOG_APPEND") != 0 ) rc |= dsLog::LOG_OF_APPEND;
00107 if ( strstr(str, "LOG_TRUNCATE") != 0 ) rc |= dsLog::LOG_OF_TRUNCATE;
00108 if ( strstr(str, "LOG_ROTATE") != 0 ) rc |= dsLog::LOG_OF_ROTATE;
00109
00110 return (dsLog::dsLogOpenFlags) rc;
00111 }
00112
00113
00114 #endif