Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages | Examples

slog.h

Go to the documentation of this file.
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         {
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 &notice(void)
00289                 {return operator()(Slog::levelNotice);};
00290 
00291         inline Slog &info(void)
00292                 {return operator()(Slog::levelInfo);};
00293 
00294 };
00295 
00296 //#ifdef        CYGWIN_IMPORTS
00297 //extern __declspec(dllimport) Slog slog;
00298 //#else
00299 extern __EXPORT Slog    slog;
00300 //#endif
00301 
00302 #ifdef  CCXX_NAMESPACES
00303 }
00304 #endif
00305 
00306 #endif
00307 

Generated on Fri Dec 9 22:36:22 2005 for GNU CommonC++ by  doxygen 1.4.4