GNU CommonC++
slog.h
Go to the documentation of this file.
1// Copyright (C) 1999-2005 Open Source Telecom Corporation.
2// Copyright (C) 2006-2010 David Sugar, Tycho Softworks.
3//
4// This program is free software; you can redistribute it and/or modify
5// it under the terms of the GNU General Public License as published by
6// the Free Software Foundation; either version 2 of the License, or
7// (at your option) any later version.
8//
9// This program is distributed in the hope that it will be useful,
10// but WITHOUT ANY WARRANTY; without even the implied warranty of
11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12// GNU General Public License for more details.
13//
14// You should have received a copy of the GNU General Public License
15// along with this program; if not, write to the Free Software
16// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17//
18// As a special exception, you may use this file as part of a free software
19// library without restriction. Specifically, if other files instantiate
20// templates or use macros or inline functions from this file, or you compile
21// this file and link it with other files to produce an executable, this
22// file does not by itself cause the resulting executable to be covered by
23// the GNU General Public License. This exception does not however
24// invalidate any other reasons why the executable file might be covered by
25// the GNU General Public License.
26//
27// This exception applies only to the code released under the name GNU
28// Common C++. If you copy code from other releases into a copy of GNU
29// Common C++, as the General Public License permits, the exception does
30// not apply to the code that you add in this way. To avoid misleading
31// anyone as to the status of such modified files, you must delete
32// this exception notice from them.
33//
34// If you write modifications of your own for GNU Common C++, it is your choice
35// whether to permit this exception to apply to your modifications.
36// If you do not wish that, delete this exception notice.
37//
38
44#ifndef CCXX_SLOG_H_
45#define CCXX_SLOG_H_
46
47#ifndef CCXX_MISSING_H_
48#include <cc++/missing.h>
49#endif
50
51#ifndef CCXX_THREAD_H_
52#include <cc++/thread.h>
53#endif
54
55#ifndef HAVE_SYSLOG_H
56#include <cstdio>
57#endif
58
59#ifdef CCXX_NAMESPACES
60namespace ost {
61#endif
62
104class __EXPORT Slog : protected std::streambuf, public std::ostream
105{
106public:
107 typedef enum Class {
120 classLocal7
121 } Class;
122
123 typedef enum Level {
124 levelEmergency = 1,
131 levelDebug
132 } Level;
133
134private:
135#ifndef HAVE_SYSLOG_H
136 Mutex lock;
137 FILE *syslog;
138#endif
139 int priority;
140 Level _level;
141 bool _enable;
142 bool _clogEnable;
143
144 ThreadImpl *getPriv(void);
145
146protected:
152 int overflow(int c);
153
154public:
162 Slog(void);
163
164 virtual ~Slog(void);
165
166 void close(void);
167
173 void open(const char *ident, Class grp = classUser);
174
181 Slog &operator()(const char *ident, Class grp = classUser,
182 Level level = levelError);
183
189 Slog &operator()(Level level, Class grp = classDefault);
190
195
196#ifdef HAVE_SNPRINTF
202 void error(const char *format, ...);
203
209 void warn(const char *format, ...);
210
216 void debug(const char *format, ...);
217
223 void emerg(const char *format, ...);
224
230 void alert(const char *format, ...);
231
237 void critical(const char *format, ...);
238
244 void notice(const char *format, ...);
245
251 void info(const char *format, ...);
252#endif
253
258 inline void level(Level enable)
259 {_level = enable;};
260
266 inline void clogEnable(bool f=true)
267 {_clogEnable = f;};
268
269 inline Slog &warn(void)
270 {return operator()(Slog::levelWarning);};
271
272 inline Slog &error(void)
273 {return operator()(Slog::levelError);};
274
275 inline Slog &debug(void)
276 {return operator()(Slog::levelDebug);};
277
278 inline Slog &emerg(void)
279 {return operator()(Slog::levelEmergency);};
280
281 inline Slog &alert(void)
282 {return operator()(Slog::levelAlert);};
283
284 inline Slog &critical(void)
285 {return operator()(Slog::levelCritical);};
286
287 inline Slog &notice(void)
288 {return operator()(Slog::levelNotice);};
289
290 inline Slog &info(void)
291 {return operator()(Slog::levelInfo);};
292
293};
294
295//#ifdef CYGWIN_IMPORTS
296//extern __declspec(dllimport) Slog slog;
297//#else
298extern __EXPORT Slog slog;
299//#endif
300
301#ifdef CCXX_NAMESPACES
302}
303#endif
304
305#endif
306
The Mutex class is used to protect a section of code so that at any given time only a single thread c...
Definition thread.h:187
The slog class is used to stream messages to the system's logging facility (syslogd).
Definition slog.h:105
Slog & critical(void)
Definition slog.h:284
Slog & emerg(void)
Definition slog.h:278
void error(const char *format,...)
Print a formatted syslog string.
void info(const char *format,...)
Print a formatted syslog string.
Slog & debug(void)
Definition slog.h:275
void warn(const char *format,...)
Print a formatted syslog string.
Slog & error(void)
Definition slog.h:272
void alert(const char *format,...)
Print a formatted syslog string.
Level
Definition slog.h:123
@ levelAlert
Definition slog.h:125
@ levelInfo
Definition slog.h:130
@ levelWarning
Definition slog.h:128
@ levelCritical
Definition slog.h:126
@ levelNotice
Definition slog.h:129
@ levelError
Definition slog.h:127
void notice(const char *format,...)
Print a formatted syslog string.
Slog(void)
Default (and only) constructor.
void close(void)
int overflow(int c)
This is the streambuf function that actually outputs the data to the device.
void debug(const char *format,...)
Print a formatted syslog string.
void clogEnable(bool f=true)
Enables or disables the echoing of the messages to clog in addition to the syslog daemon.
Definition slog.h:266
void critical(const char *format,...)
Print a formatted syslog string.
void emerg(const char *format,...)
Print a formatted syslog string.
void level(Level enable)
Sets the logging level.
Definition slog.h:258
Slog & operator()(void)
Does nothing except return *this.
Slog & operator()(Level level, Class grp=classDefault)
Changes the log level and class to use for subsequent output.
Slog & warn(void)
Definition slog.h:269
Class
Definition slog.h:107
@ classLocal1
Definition slog.h:114
@ classLocal6
Definition slog.h:119
@ classDaemon
Definition slog.h:110
@ classLocal0
Definition slog.h:113
@ classLocal2
Definition slog.h:115
@ classLocal3
Definition slog.h:116
@ classUser
Definition slog.h:111
@ classAudit
Definition slog.h:109
@ classSecurity
Definition slog.h:108
@ classDefault
Definition slog.h:112
@ classLocal5
Definition slog.h:118
@ classLocal4
Definition slog.h:117
Slog & info(void)
Definition slog.h:290
void open(const char *ident, Class grp=classUser)
(re)opens the output stream.
Slog & notice(void)
Definition slog.h:287
Slog & alert(void)
Definition slog.h:281
Slog & operator()(const char *ident, Class grp=classUser, Level level=levelError)
Sets the log identifier, level, and class to use for subsequent output.
virtual ~Slog(void)
#define __EXPORT
Definition config.h:1045
substitute functions which may be missing in target platform libc.
Definition address.h:64
__EXPORT Slog slog
Synchronization and threading services.