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 COMMONCPP_SLOG_H_
00044 #define COMMONCPP_SLOG_H_
00045
00046 #include <cstdio>
00047
00048 #ifndef COMMONCPP_CONFIG_H_
00049 #include <commoncpp/config.h>
00050 #endif
00051
00052 #ifndef COMMONCPP_STRING_H_
00053 #include <commoncpp/string.h>
00054 #endif
00055
00056 #ifndef COMMONCPP_THREAD_H_
00057 #include <commoncpp/thread.h>
00058 #endif
00059
00060 NAMESPACE_COMMONCPP
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 pthread_mutex_t lock;
00135 FILE *syslog;
00136 int priority;
00137 Level _level;
00138 bool _enable;
00139 bool _clogEnable;
00140
00141 protected:
00147 int overflow(int c);
00148
00149 public:
00157 Slog(void);
00158
00159 virtual ~Slog(void);
00160
00161 void close(void);
00162
00168 void open(const char *ident, Class grp = classUser);
00169
00176 Slog &operator()(const char *ident, Class grp = classUser,
00177 Level level = levelError);
00178
00184 Slog &operator()(Level level, Class grp = classDefault);
00185
00189 Slog &operator()(void);
00190
00196 void error(const char *format, ...);
00197
00203 void warn(const char *format, ...);
00204
00210 void debug(const char *format, ...);
00211
00217 void emerg(const char *format, ...);
00218
00224 void alert(const char *format, ...);
00225
00231 void critical(const char *format, ...);
00232
00238 void notice(const char *format, ...);
00239
00245 void info(const char *format, ...);
00246
00251 inline void level(Level enable)
00252 {_level = enable;};
00253
00259 inline void clogEnable(bool f=true)
00260 {_clogEnable = f;};
00261
00262 inline Slog &warn(void)
00263 {return operator()(Slog::levelWarning);};
00264
00265 inline Slog &error(void)
00266 {return operator()(Slog::levelError);};
00267
00268 inline Slog &debug(void)
00269 {return operator()(Slog::levelDebug);};
00270
00271 inline Slog &emerg(void)
00272 {return operator()(Slog::levelEmergency);};
00273
00274 inline Slog &alert(void)
00275 {return operator()(Slog::levelAlert);};
00276
00277 inline Slog &critical(void)
00278 {return operator()(Slog::levelCritical);};
00279
00280 inline Slog ¬ice(void)
00281 {return operator()(Slog::levelNotice);};
00282
00283 inline Slog &info(void)
00284 {return operator()(Slog::levelInfo);};
00285
00286 };
00287
00288 extern __EXPORT Slog slog;
00289
00290 END_NAMESPACE
00291
00292 #endif
00293