00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00043 #ifndef CCXX_SLOG_H_
00044 #define CCXX_SLOG_H_
00045
00046 #ifndef CCXX_MISSING_H_
00047 #include <cc++/missing.h>
00048 #endif
00049
00050 #ifndef CCXX_THREAD_H_
00051 #include <cc++/thread.h>
00052 #endif
00053
00054 #ifndef HAVE_SYSLOG_H
00055 #include <cstdio>
00056 #endif
00057
00058 #ifdef CCXX_NAMESPACES
00059 namespace ost {
00060 #endif
00061
00103 class __EXPORT Slog : protected std::streambuf, public std::ostream
00104 {
00105 public:
00106 typedef enum Class
00107 {
00108 classSecurity,
00109 classAudit,
00110 classDaemon,
00111 classUser,
00112 classDefault,
00113 classLocal0,
00114 classLocal1,
00115 classLocal2,
00116 classLocal3,
00117 classLocal4,
00118 classLocal5,
00119 classLocal6,
00120 classLocal7
00121 } Class;
00122
00123 typedef enum Level
00124 {
00125 levelEmergency = 1,
00126 levelAlert,
00127 levelCritical,
00128 levelError,
00129 levelWarning,
00130 levelNotice,
00131 levelInfo,
00132 levelDebug
00133 } Level;
00134
00135 private:
00136 #ifndef HAVE_SYSLOG_H
00137 Mutex lock;
00138 FILE *syslog;
00139 #endif
00140 int priority;
00141 Level _level;
00142 bool _enable;
00143 bool _clogEnable;
00144
00145 ThreadImpl *getPriv(void);
00146
00147 protected:
00153 int overflow(int c);
00154
00155 public:
00163 Slog(void);
00164
00165 virtual ~Slog(void);
00166
00167 void close(void);
00168
00174 void open(const char *ident, Class grp = classUser);
00175
00182 Slog &operator()(const char *ident, Class grp = classUser,
00183 Level level = levelError);
00184
00190 Slog &operator()(Level level, Class grp = classDefault);
00191
00195 Slog &operator()(void);
00196
00197 #ifdef HAVE_SNPRINTF
00198
00203 void error(const char *format, ...);
00204
00210 void warn(const char *format, ...);
00211
00217 void debug(const char *format, ...);
00218
00224 void emerg(const char *format, ...);
00225
00231 void alert(const char *format, ...);
00232
00238 void critical(const char *format, ...);
00239
00245 void notice(const char *format, ...);
00246
00252 void info(const char *format, ...);
00253 #endif
00254
00259 inline void level(Level enable)
00260 {_level = enable;};
00261
00267 inline void clogEnable(bool f=true)
00268 {_clogEnable = f;};
00269
00270 inline Slog &warn(void)
00271 {return operator()(Slog::levelWarning);};
00272
00273 inline Slog &error(void)
00274 {return operator()(Slog::levelError);};
00275
00276 inline Slog &debug(void)
00277 {return operator()(Slog::levelDebug);};
00278
00279 inline Slog &emerg(void)
00280 {return operator()(Slog::levelEmergency);};
00281
00282 inline Slog &alert(void)
00283 {return operator()(Slog::levelAlert);};
00284
00285 inline Slog &critical(void)
00286 {return operator()(Slog::levelCritical);};
00287
00288 inline Slog ¬ice(void)
00289 {return operator()(Slog::levelNotice);};
00290
00291 inline Slog &info(void)
00292 {return operator()(Slog::levelInfo);};
00293
00294 };
00295
00296
00297
00298
00299 extern __EXPORT Slog slog;
00300
00301
00302 #ifdef CCXX_NAMESPACES
00303 }
00304 #endif
00305
00306 #endif
00307