log4tango 5.0.2
LoggerStream.hh
Go to the documentation of this file.
1//
2// LoggerStream.hh
3//
4// Copyright (C) : 2000 - 2002
5// LifeLine Networks BV (www.lifeline.nl). All rights reserved.
6// Bastiaan Bakker. All rights reserved.
7//
8// 2004,2005,2006,2007,2008,2009,2010,2011,2012
9// Synchrotron SOLEIL
10// L'Orme des Merisiers
11// Saint-Aubin - BP 48 - France
12//
13// This file is part of log4tango.
14//
15// Log4ango is free software: you can redistribute it and/or modify
16// it under the terms of the GNU Lesser General Public License as published by
17// the Free Software Foundation, either version 3 of the License, or
18// (at your option) any later version.
19//
20// Log4tango is distributed in the hope that it will be useful,
21// but WITHOUT ANY WARRANTY; without even the implied warranty of
22// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23// GNU Lesser General Public License for more details.
24//
25// You should have received a copy of the GNU Lesser General Public License
26// along with Log4Tango. If not, see <http://www.gnu.org/licenses/>.
27
28#ifndef _LOG4TANGO_LOGGER_STREAM_H
29#define _LOG4TANGO_LOGGER_STREAM_H
30
32#include <log4tango/Level.hh>
33#ifdef LOG4TANGO_HAVE_SSTREAM
34# include <sstream>
35#endif
37
38namespace log4tango {
39
40//-----------------------------------------------------------------------------
41// FORWARD DECLARATION
42//-----------------------------------------------------------------------------
44class LoggerStream;
45
46//-----------------------------------------------------------------------------
47// DEFINE WHAT IS A LS_TERMINATOR
48//-----------------------------------------------------------------------------
49typedef LoggerStream& (*ls_terminator) (LoggerStream&);
50
51
52typedef class std::ios_base&(*StdIosFlag)(class std::ios_base&);
53
54
55//-----------------------------------------------------------------------------
56// class : LoggerStream
57//-----------------------------------------------------------------------------
59{
60public:
61
69 LOG4TANGO_EXPORT LoggerStream(Logger& logger, Level::Value level, bool filter = true);
70
75
80 inline LOG4TANGO_EXPORT Logger& get_logger (void) const {
81 return _logger;
82 };
83
89 return _level;
90 };
91
98 return *this;
99 }
100
108 flush();
109 return *this;
110 }
111
119 flush();
120 return *this;
121 }
122
127 LOG4TANGO_EXPORT void flush (void);
128
134#ifdef WIN32
135 inline LOG4TANGO_EXPORT LoggerStream& operator<< (std::ios_base&(_cdecl *_F)(std::ios_base&)) {
136#else
137 inline LOG4TANGO_EXPORT LoggerStream& operator<< (std::ios_base&(*_F)(std::ios_base&)) {
138#endif
139#ifndef LOG4TANGO_HAVE_SSTREAM
140 if (!_buffer)
141 _buffer = new std::ostringstream;
142#endif
143 if (_buffer)
144 (*_F)(*(std::ios_base *)(_buffer));
145 return *this;
146 }
147
153 template<typename T> LoggerStream& operator<< (const T& t) {
154 if (_level != Level::OFF) {
155#ifndef LOG4TANGO_HAVE_SSTREAM
156 if (!_buffer)
157 _buffer = new std::ostringstream;
158#endif
159 if (_buffer)
160 (*_buffer) << t;
161 }
162 return *this;
163 }
164
165private:
166
167 Logger& _logger;
168
169 Level::Value _level;
170
171 bool _filter;
172
173 std::ostringstream* _buffer;
174};
175
176} // namespace log4tango
177
178namespace std {
179 //-- A dummy <ls_terminator>
181 return ls;
182 }
183} // namespace std
184
185#endif // _LOG4TANGO_LOGGER_STREAM_H
#define LOG4TANGO_EXPORT
Definition: Export.hh:38
#define LOG4TANGO_UNUSED(var)
Definition: Portability.hh:49
int Value
The type of Level Values.
Definition: Level.hh:98
@ OFF
Definition: Level.hh:87
Definition: LogSeparator.hh:38
Definition: LogSeparator.hh:46
Definition: LoggerStream.hh:59
LOG4TANGO_EXPORT ~LoggerStream()
Destructor for LoggerStream&)
Definition: LoggerStream.cpp:48
LOG4TANGO_EXPORT Logger & get_logger(void) const
Returns the destination Logger for this stream.
Definition: LoggerStream.hh:80
LOG4TANGO_EXPORT LoggerStream & operator<<(LOG4TANGO_UNUSED(LogInitiator &i))
Streams in a Initiator.
Definition: LoggerStream.hh:97
LOG4TANGO_EXPORT LoggerStream(Logger &logger, Level::Value level, bool filter=true)
Construct a LoggerStream for given Logger with given level.
Definition: LoggerStream.cpp:39
LOG4TANGO_EXPORT void flush(void)
Flush the contents of the stream buffer to the Logger and empties the buffer.
Definition: LoggerStream.cpp:59
LOG4TANGO_EXPORT Level::Value get_level(void) const
Returns the level for this stream.
Definition: LoggerStream.hh:88
Definition: Logger.hh:57
Definition: Portability.hh:56
Definition: Appender.hh:40
LoggerStream &(* ls_terminator)(LoggerStream &)
Definition: LoggerStream.hh:49
Definition: LoggerStream.hh:178
log4tango::LoggerStream & endl(log4tango::LoggerStream &ls)
Definition: LoggerStream.hh:180