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 classSecurity,
00108 classAudit,
00109 classDaemon,
00110 classUser,
00111 classDefault,
00112 classLocal0,
00113 classLocal1,
00114 classLocal2,
00115 classLocal3,
00116 classLocal4,
00117 classLocal5,
00118 classLocal6,
00119 classLocal7
00120 } Class;
00121
00122 typedef enum Level {
00123 levelEmergency = 1,
00124 levelAlert,
00125 levelCritical,
00126 levelError,
00127 levelWarning,
00128 levelNotice,
00129 levelInfo,
00130 levelDebug
00131 } Level;
00132
00133 private:
00134 #ifndef HAVE_SYSLOG_H
00135 Mutex lock;
00136 FILE *syslog;
00137 #endif
00138 int priority;
00139 Level _level;
00140 bool _enable;
00141 bool _clogEnable;
00142
00143 ThreadImpl *getPriv(void);
00144
00145 protected:
00151 int overflow(int c);
00152
00153 public:
00161 Slog(void);
00162
00163 virtual ~Slog(void);
00164
00165 void close(void);
00166
00172 void open(const char *ident, Class grp = classUser);
00173
00180 Slog &operator()(const char *ident, Class grp = classUser,
00181 Level level = levelError);
00182
00188 Slog &operator()(Level level, Class grp = classDefault);
00189
00193 Slog &operator()(void);
00194
00195 #ifdef HAVE_SNPRINTF
00196
00201 void error(const char *format, ...);
00202
00208 void warn(const char *format, ...);
00209
00215 void debug(const char *format, ...);
00216
00222 void emerg(const char *format, ...);
00223
00229 void alert(const char *format, ...);
00230
00236 void critical(const char *format, ...);
00237
00243 void notice(const char *format, ...);
00244
00250 void info(const char *format, ...);
00251 #endif
00252
00257 inline void level(Level enable)
00258 {_level = enable;};
00259
00265 inline void clogEnable(bool f=true)
00266 {_clogEnable = f;};
00267
00268 inline Slog &warn(void)
00269 {return operator()(Slog::levelWarning);};
00270
00271 inline Slog &error(void)
00272 {return operator()(Slog::levelError);};
00273
00274 inline Slog &debug(void)
00275 {return operator()(Slog::levelDebug);};
00276
00277 inline Slog &emerg(void)
00278 {return operator()(Slog::levelEmergency);};
00279
00280 inline Slog &alert(void)
00281 {return operator()(Slog::levelAlert);};
00282
00283 inline Slog &critical(void)
00284 {return operator()(Slog::levelCritical);};
00285
00286 inline Slog ¬ice(void)
00287 {return operator()(Slog::levelNotice);};
00288
00289 inline Slog &info(void)
00290 {return operator()(Slog::levelInfo);};
00291
00292 };
00293
00294
00295
00296
00297 extern __EXPORT Slog slog;
00298
00299
00300 #ifdef CCXX_NAMESPACES
00301 }
00302 #endif
00303
00304 #endif
00305