GNU CommonC++
|
00001 // Copyright (C) 1999-2005 Open Source Telecom Corporation. 00002 // 00003 // This program is free software; you can redistribute it and/or modify 00004 // it under the terms of the GNU General Public License as published by 00005 // the Free Software Foundation; either version 2 of the License, or 00006 // (at your option) any later version. 00007 // 00008 // This program is distributed in the hope that it will be useful, 00009 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00010 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00011 // GNU General Public License for more details. 00012 // 00013 // You should have received a copy of the GNU General Public License 00014 // along with this program; if not, write to the Free Software 00015 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 00016 // 00017 // As a special exception, you may use this file as part of a free software 00018 // library without restriction. Specifically, if other files instantiate 00019 // templates or use macros or inline functions from this file, or you compile 00020 // this file and link it with other files to produce an executable, this 00021 // file does not by itself cause the resulting executable to be covered by 00022 // the GNU General Public License. This exception does not however 00023 // invalidate any other reasons why the executable file might be covered by 00024 // the GNU General Public License. 00025 // 00026 // This exception applies only to the code released under the name GNU 00027 // Common C++. If you copy code from other releases into a copy of GNU 00028 // Common C++, as the General Public License permits, the exception does 00029 // not apply to the code that you add in this way. To avoid misleading 00030 // anyone as to the status of such modified files, you must delete 00031 // this exception notice from them. 00032 // 00033 // If you write modifications of your own for GNU Common C++, it is your choice 00034 // whether to permit this exception to apply to your modifications. 00035 // If you do not wish that, delete this exception notice. 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 //#ifdef CYGWIN_IMPORTS 00295 //extern __declspec(dllimport) Slog slog; 00296 //#else 00297 extern __EXPORT Slog slog; 00298 //#endif 00299 00300 #ifdef CCXX_NAMESPACES 00301 } 00302 #endif 00303 00304 #endif 00305