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
00038
00044 #ifndef CCXX_SLOG_H_
00045 #define CCXX_SLOG_H_
00046
00047 #ifndef CCXX_MISSING_H_
00048 #include <cc++/missing.h>
00049 #endif
00050
00051 #ifndef CCXX_THREAD_H_
00052 #include <cc++/thread.h>
00053 #endif
00054
00055 #ifndef HAVE_SYSLOG_H
00056 #include <cstdio>
00057 #endif
00058
00059 #ifdef CCXX_NAMESPACES
00060 namespace ost {
00061 #endif
00062
00104 class __EXPORT Slog : protected std::streambuf, public std::ostream
00105 {
00106 public:
00107 typedef enum Class {
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 levelEmergency = 1,
00125 levelAlert,
00126 levelCritical,
00127 levelError,
00128 levelWarning,
00129 levelNotice,
00130 levelInfo,
00131 levelDebug
00132 } Level;
00133
00134 private:
00135 #ifndef HAVE_SYSLOG_H
00136 Mutex lock;
00137 FILE *syslog;
00138 #endif
00139 int priority;
00140 Level _level;
00141 bool _enable;
00142 bool _clogEnable;
00143
00144 ThreadImpl *getPriv(void);
00145
00146 protected:
00152 int overflow(int c);
00153
00154 public:
00162 Slog(void);
00163
00164 virtual ~Slog(void);
00165
00166 void close(void);
00167
00173 void open(const char *ident, Class grp = classUser);
00174
00181 Slog &operator()(const char *ident, Class grp = classUser,
00182 Level level = levelError);
00183
00189 Slog &operator()(Level level, Class grp = classDefault);
00190
00194 Slog &operator()(void);
00195
00196 #ifdef HAVE_SNPRINTF
00197
00202 void error(const char *format, ...);
00203
00209 void warn(const char *format, ...);
00210
00216 void debug(const char *format, ...);
00217
00223 void emerg(const char *format, ...);
00224
00230 void alert(const char *format, ...);
00231
00237 void critical(const char *format, ...);
00238
00244 void notice(const char *format, ...);
00245
00251 void info(const char *format, ...);
00252 #endif
00253
00258 inline void level(Level enable)
00259 {_level = enable;};
00260
00266 inline void clogEnable(bool f=true)
00267 {_clogEnable = f;};
00268
00269 inline Slog &warn(void)
00270 {return operator()(Slog::levelWarning);};
00271
00272 inline Slog &error(void)
00273 {return operator()(Slog::levelError);};
00274
00275 inline Slog &debug(void)
00276 {return operator()(Slog::levelDebug);};
00277
00278 inline Slog &emerg(void)
00279 {return operator()(Slog::levelEmergency);};
00280
00281 inline Slog &alert(void)
00282 {return operator()(Slog::levelAlert);};
00283
00284 inline Slog &critical(void)
00285 {return operator()(Slog::levelCritical);};
00286
00287 inline Slog ¬ice(void)
00288 {return operator()(Slog::levelNotice);};
00289
00290 inline Slog &info(void)
00291 {return operator()(Slog::levelInfo);};
00292
00293 };
00294
00295
00296
00297
00298 extern __EXPORT Slog slog;
00299
00300
00301 #ifdef CCXX_NAMESPACES
00302 }
00303 #endif
00304
00305 #endif
00306