GNU CommonC++
slog.h
Go to the documentation of this file.
1 // Copyright (C) 1999-2005 Open Source Telecom Corporation.
2 //
3 // This program is free software; you can redistribute it and/or modify
4 // it under the terms of the GNU General Public License as published by
5 // the Free Software Foundation; either version 2 of the License, or
6 // (at your option) any later version.
7 //
8 // This program is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 // GNU General Public License for more details.
12 //
13 // You should have received a copy of the GNU General Public License
14 // along with this program; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
16 //
17 // As a special exception, you may use this file as part of a free software
18 // library without restriction. Specifically, if other files instantiate
19 // templates or use macros or inline functions from this file, or you compile
20 // this file and link it with other files to produce an executable, this
21 // file does not by itself cause the resulting executable to be covered by
22 // the GNU General Public License. This exception does not however
23 // invalidate any other reasons why the executable file might be covered by
24 // the GNU General Public License.
25 //
26 // This exception applies only to the code released under the name GNU
27 // Common C++. If you copy code from other releases into a copy of GNU
28 // Common C++, as the General Public License permits, the exception does
29 // not apply to the code that you add in this way. To avoid misleading
30 // anyone as to the status of such modified files, you must delete
31 // this exception notice from them.
32 //
33 // If you write modifications of your own for GNU Common C++, it is your choice
34 // whether to permit this exception to apply to your modifications.
35 // If you do not wish that, delete this exception notice.
36 //
37 
43 #ifndef CCXX_SLOG_H_
44 #define CCXX_SLOG_H_
45 
46 #ifndef CCXX_MISSING_H_
47 #include <cc++/missing.h>
48 #endif
49 
50 #ifndef CCXX_THREAD_H_
51 #include <cc++/thread.h>
52 #endif
53 
54 #ifndef HAVE_SYSLOG_H
55 #include <cstdio>
56 #endif
57 
58 #ifdef CCXX_NAMESPACES
59 namespace ost {
60 #endif
61 
103 class __EXPORT Slog : protected std::streambuf, public std::ostream
104 {
105 public:
106  typedef enum Class {
119  classLocal7
120  } Class;
121 
122  typedef enum Level {
123  levelEmergency = 1,
130  levelDebug
131  } Level;
132 
133 private:
134 #ifndef HAVE_SYSLOG_H
135  Mutex lock;
136  FILE *syslog;
137 #endif
138  int priority;
139  Level _level;
140  bool _enable;
141  bool _clogEnable;
142 
143  ThreadImpl *getPriv(void);
144 
145 protected:
151  int overflow(int c);
152 
153 public:
161  Slog(void);
162 
163  virtual ~Slog(void);
164 
165  void close(void);
166 
172  void open(const char *ident, Class grp = classUser);
173 
180  Slog &operator()(const char *ident, Class grp = classUser,
181  Level level = levelError);
182 
188  Slog &operator()(Level level, Class grp = classDefault);
189 
193  Slog &operator()(void);
194 
195 #ifdef HAVE_SNPRINTF
196 
201  void error(const char *format, ...);
202 
208  void warn(const char *format, ...);
209 
215  void debug(const char *format, ...);
216 
222  void emerg(const char *format, ...);
223 
229  void alert(const char *format, ...);
230 
236  void critical(const char *format, ...);
237 
243  void notice(const char *format, ...);
244 
250  void info(const char *format, ...);
251 #endif
252 
257  inline void level(Level enable)
258  {_level = enable;};
259 
265  inline void clogEnable(bool f=true)
266  {_clogEnable = f;};
267 
268  inline Slog &warn(void)
269  {return operator()(Slog::levelWarning);};
270 
271  inline Slog &error(void)
272  {return operator()(Slog::levelError);};
273 
274  inline Slog &debug(void)
275  {return operator()(Slog::levelDebug);};
276 
277  inline Slog &emerg(void)
278  {return operator()(Slog::levelEmergency);};
279 
280  inline Slog &alert(void)
281  {return operator()(Slog::levelAlert);};
282 
283  inline Slog &critical(void)
284  {return operator()(Slog::levelCritical);};
285 
286  inline Slog &notice(void)
287  {return operator()(Slog::levelNotice);};
288 
289  inline Slog &info(void)
290  {return operator()(Slog::levelInfo);};
291 
292 };
293 
294 //#ifdef CYGWIN_IMPORTS
295 //extern __declspec(dllimport) Slog slog;
296 //#else
297 extern __EXPORT Slog slog;
298 //#endif
299 
300 #ifdef CCXX_NAMESPACES
301 }
302 #endif
303 
304 #endif
305