Apache Log4cxx  Version 2.0.0
Loading...
Searching...
No Matches
stream.h
Go to the documentation of this file.
1/*
2 * Licensed to the Apache Software Foundation (ASF) under one or more
3 * contributor license agreements. See the NOTICE file distributed with
4 * this work for additional information regarding copyright ownership.
5 * The ASF licenses this file to You under the Apache License, Version 2.0
6 * (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17
18#ifndef _LOG4CXX_STREAM_H
19#define _LOG4CXX_STREAM_H
20
21#include <log4cxx/logger.h>
22#include <sstream>
24
25namespace LOG4CXX_NS
26{
27
37class LOG4CXX_EXPORT logstream_base
38{
39 public:
46 logstream_base(const LOG4CXX_NS::LoggerPtr& logger,
47 const LOG4CXX_NS::LevelPtr& level);
51 virtual ~logstream_base();
55 void insert(std::ios_base & (*manip)(std::ios_base&));
56
60 int precision();
64 int width();
69 int precision(int newval);
74 int width(int newval);
78 int fill();
82 int fill(int newval);
83
87 std::ios_base::fmtflags flags(std::ios_base::fmtflags newflags);
91 std::ios_base::fmtflags setf(std::ios_base::fmtflags newflags, std::ios_base::fmtflags mask);
95 std::ios_base::fmtflags setf(std::ios_base::fmtflags newflags);
96
97
102
107
112
113
114
119 void setLevel(const LevelPtr& level);
124 inline bool isEnabled() const
125 {
126 return enabled;
127 }
128
132 bool isEnabledFor(const LevelPtr& level) const;
133
137 void setLocation(const LOG4CXX_NS::spi::LocationInfo& location);
138
146 bool set_stream_state(std::ios_base& os, int& fillchar);
147
148 protected:
152 virtual void log(LoggerPtr& logger,
153 const LevelPtr& level,
154 const LOG4CXX_NS::spi::LocationInfo& location) = 0;
158 virtual void erase() = 0;
164 virtual void get_stream_state(std::ios_base& base,
165 std::ios_base& mask,
166 int& fill,
167 bool& fillSet) const = 0;
168 virtual void refresh_stream_state() = 0;
169
170 private:
178 logstream_base& operator=(logstream_base&);
183 class LOG4CXX_EXPORT logstream_ios_base : public std::ios_base
184 {
185 public:
186 logstream_ios_base(std::ios_base::fmtflags initval,
187 int initsize);
188 } initset, initclear;
192 int fillchar;
196 bool fillset;
200 bool enabled;
204 LOG4CXX_NS::LoggerPtr logger;
208 LOG4CXX_NS::LevelPtr level;
212 LOG4CXX_NS::spi::LocationInfo location;
213};
214
215typedef logstream_base& (*logstream_manipulator)(logstream_base&);
216
226class LOG4CXX_EXPORT logstream : public logstream_base
227{
228 typedef char Ch;
229 public:
233 logstream(const LOG4CXX_NS::LoggerPtr& logger,
234 const LOG4CXX_NS::LevelPtr& level);
235
239 logstream(const Ch* loggerName,
240 const LOG4CXX_NS::LevelPtr& level);
241
245 logstream(const std::basic_string<Ch>& loggerName,
246 const LOG4CXX_NS::LevelPtr& level);
247
249
253 logstream& operator<<(std::ios_base & (*manip)(std::ios_base&));
254
259
263 logstream& operator<<(const LOG4CXX_NS::LevelPtr& level);
267 logstream& operator<<(const LOG4CXX_NS::spi::LocationInfo& location);
268
273 logstream& operator>>(const LOG4CXX_NS::spi::LocationInfo& location);
274
278 operator std::basic_ostream<Ch>& ();
279
280#if !(LOG4CXX_USE_GLOBAL_SCOPE_TEMPLATE)
285 template <class V>
286 inline LOG4CXX_NS::logstream& operator<<(const V& val)
287 {
289 {
290 ((std::basic_ostream<char>&) *this) << val;
291 }
292
293 return *this;
294 }
295#endif
296
297
298 protected:
299 virtual void log(LoggerPtr& logger,
300 const LevelPtr& level,
301 const LOG4CXX_NS::spi::LocationInfo& location);
302
303 virtual void erase();
304
305 virtual void get_stream_state(std::ios_base& base,
306 std::ios_base& mask,
307 int& fill,
308 bool& fillSet) const;
309 virtual void refresh_stream_state();
310
311
312 private:
313 logstream(const logstream&);
314 logstream& operator=(const logstream&);
315 std::basic_stringstream<Ch>* stream;
316
317};
318
319#if LOG4CXX_WCHAR_T_API
329class LOG4CXX_EXPORT wlogstream : public logstream_base
330{
331 typedef wchar_t Ch;
332 public:
336 wlogstream(const LOG4CXX_NS::LoggerPtr& logger,
337 const LOG4CXX_NS::LevelPtr& level);
338
342 wlogstream(const Ch* loggerName,
343 const LOG4CXX_NS::LevelPtr& level);
344
348 wlogstream(const std::basic_string<Ch>& loggerName,
349 const LOG4CXX_NS::LevelPtr& level);
350
352
356 wlogstream& operator<<(std::ios_base & (*manip)(std::ios_base&));
357
362
366 wlogstream& operator<<(const LOG4CXX_NS::LevelPtr& level);
370 wlogstream& operator<<(const LOG4CXX_NS::spi::LocationInfo& location);
371
376 wlogstream& operator>>(const LOG4CXX_NS::spi::LocationInfo& location);
377
378
382 operator std::basic_ostream<Ch>& ();
383
384#if !(LOG4CXX_USE_GLOBAL_SCOPE_TEMPLATE)
389 template <class V>
390 inline LOG4CXX_NS::wlogstream& operator<<(const V& val)
391 {
393 {
394 ((std::basic_ostream<wchar_t>&) *this) << val;
395 }
396
397 return *this;
398 }
399#endif
400
401 protected:
402 virtual void log(LoggerPtr& logger,
403 const LevelPtr& level,
404 const LOG4CXX_NS::spi::LocationInfo& location);
405
406 virtual void erase();
407
408 virtual void get_stream_state(std::ios_base& base,
409 std::ios_base& mask,
410 int& fill,
411 bool& fillSet) const;
412 virtual void refresh_stream_state();
413
414
415 private:
416 wlogstream(const wlogstream&);
417 wlogstream& operator=(const wlogstream&);
418 std::basic_stringstream<Ch>* stream;
419
420};
421#endif
422
423} // namespace log4cxx
424
425
426#if LOG4CXX_USE_GLOBAL_SCOPE_TEMPLATE
427//
428// VC6 will fail to compile if class-scope templates
429// are used to handle arbitrary insertion operations.
430// However, using global namespace insertion operations
431// run into LOGCXX-150.
432
437template <class V>
438inline LOG4CXX_NS::logstream& operator<<(LOG4CXX_NS::logstream& os, const V& val)
439{
440 if (LOG4CXX_UNLIKELY(os.isEnabled()))
441 {
442 ((std::basic_ostream<char>&) os) << val;
443 }
444
445 return os;
446}
447
448#if LOG4CXX_WCHAR_T_API
453template <class V>
454inline LOG4CXX_NS::wlogstream& operator<<(LOG4CXX_NS::wlogstream& os, const V& val)
455{
456 if (LOG4CXX_UNLIKELY(os.isEnabled()))
457 {
458 ((std::basic_ostream<wchar_t>&) os) << val;
459 }
460
461 return os;
462}
463#endif
464#endif
465
466#if !defined(LOG4CXX_ENDMSG)
467 #if LOG4CXX_LOGSTREAM_ADD_NOP
468 #define LOG4CXX_ENDMSG (LOG4CXX_NS::logstream_manipulator) LOG4CXX_NS::logstream_base::nop >> LOG4CXX_LOCATION << (LOG4CXX_NS::logstream_manipulator) LOG4CXX_NS::logstream_base::endmsg
469 #else
470 #define LOG4CXX_ENDMSG LOG4CXX_LOCATION << (LOG4CXX_NS::logstream_manipulator) LOG4CXX_NS::logstream_base::endmsg
471 #endif
472#endif
473
474
475#endif //_LOG4CXX_STREAM_H
Base class for the basic_logstream template which attempts to emulate std::basic_ostream but attempts...
Definition stream.h:38
int width()
get width.
std::ios_base::fmtflags setf(std::ios_base::fmtflags newflags)
Set flags.
int fill(int newval)
Set fill character.
virtual void log(LoggerPtr &logger, const LevelPtr &level, const log4cxx::spi::LocationInfo &location)=0
Dispatches the pending log request.
int width(int newval)
set width.
virtual void erase()=0
Erase any content in the message construction buffer.
void end_message()
end of message action.
int fill()
Get fill character.
std::ios_base::fmtflags flags(std::ios_base::fmtflags newflags)
Set flags.
void setLevel(const LevelPtr &level)
Set the level.
void setLocation(const log4cxx::spi::LocationInfo &location)
Sets the location for subsequent log requests.
int precision(int newval)
set precision.
bool isEnabledFor(const LevelPtr &level) const
Returns if logger is currently enabled for the specified level.
virtual ~logstream_base()
Destructor.
logstream_base(const log4cxx::LoggerPtr &logger, const log4cxx::LevelPtr &level)
Create new instance.
std::ios_base::fmtflags setf(std::ios_base::fmtflags newflags, std::ios_base::fmtflags mask)
Set flags.
virtual void refresh_stream_state()=0
static logstream_base & endmsg(logstream_base &)
end of message manipulator, triggers logging.
void insert(std::ios_base &(*manip)(std::ios_base &))
Insertion operator for std::fixed and similar manipulators.
static logstream_base & nop(logstream_base &)
no-operation manipulator, Used to avoid ambiguity with VC6.
virtual void get_stream_state(std::ios_base &base, std::ios_base &mask, int &fill, bool &fillSet) const =0
Copy state of embedded stream (if any) to value and mask instances of std::ios_base and return fill c...
bool set_stream_state(std::ios_base &os, int &fillchar)
Sets the state of the embedded stream (if any) to the state of the formatting info.
bool isEnabled() const
Returns true if the current level is the same or high as the level of logger at time of construction ...
Definition stream.h:124
int precision()
get precision.
virtual void refresh_stream_state()
virtual void log(LoggerPtr &logger, const LevelPtr &level, const log4cxx::spi::LocationInfo &location)
Dispatches the pending log request.
logstream & operator<<(std::ios_base &(*manip)(std::ios_base &))
Insertion operator for std::fixed and similar manipulators.
logstream & operator<<(const log4cxx::LevelPtr &level)
Insertion operator for level.
virtual void get_stream_state(std::ios_base &base, std::ios_base &mask, int &fill, bool &fillSet) const
Copy state of embedded stream (if any) to value and mask instances of std::ios_base and return fill c...
logstream(const Ch *loggerName, const log4cxx::LevelPtr &level)
Constructor.
logstream & operator>>(const log4cxx::spi::LocationInfo &location)
Alias for insertion operator for location.
virtual void erase()
Erase any content in the message construction buffer.
logstream(const std::basic_string< Ch > &loggerName, const log4cxx::LevelPtr &level)
Constructor.
logstream & operator<<(const log4cxx::spi::LocationInfo &location)
Insertion operator for location.
logstream & operator<<(logstream_manipulator manip)
Insertion operator for logstream_base::endmsg.
logstream(const log4cxx::LoggerPtr &logger, const log4cxx::LevelPtr &level)
Constructor.
log4cxx::logstream & operator<<(const V &val)
Template to allow any class with an std::basic_ostream inserter to be applied to this class.
Definition stream.h:286
wlogstream & operator<<(const log4cxx::spi::LocationInfo &location)
Insertion operator for location.
virtual void log(LoggerPtr &logger, const LevelPtr &level, const log4cxx::spi::LocationInfo &location)
Dispatches the pending log request.
wlogstream(const log4cxx::LoggerPtr &logger, const log4cxx::LevelPtr &level)
Constructor.
virtual void refresh_stream_state()
wlogstream & operator<<(logstream_manipulator manip)
Insertion operator for logstream_base::endmsg.
log4cxx::wlogstream & operator<<(const V &val)
Template to allow any class with an std::basic_ostream inserter to be applied to this class.
Definition stream.h:390
wlogstream & operator>>(const log4cxx::spi::LocationInfo &location)
Alias for insertion operator for location.
wlogstream(const Ch *loggerName, const log4cxx::LevelPtr &level)
Constructor.
wlogstream & operator<<(const log4cxx::LevelPtr &level)
Insertion operator for level.
virtual void erase()
Erase any content in the message construction buffer.
wlogstream(const std::basic_string< Ch > &loggerName, const log4cxx::LevelPtr &level)
Constructor.
wlogstream & operator<<(std::ios_base &(*manip)(std::ios_base &))
Insertion operator for std::fixed and similar manipulators.
virtual void get_stream_state(std::ios_base &base, std::ios_base &mask, int &fill, bool &fillSet) const
Copy state of embedded stream (if any) to value and mask instances of std::ios_base and return fill c...
log4cxx::helpers::WideMessageBuffer & operator<<(log4cxx::helpers::WideMessageBuffer &mb, const QString &msg)
Definition log4cxx-qt/messagebuffer.h:24
#define LOG4CXX_UNLIKELY(expr)
Provides optimization hint to the compiler to optimize for the expression being false.
Definition log4cxx/logger.h:1803
logstream_base &(*) logstream_manipulator(logstream_base &)
Definition stream.h:215
std::shared_ptr< Level > LevelPtr
Definition optionconverter.h:28
std::shared_ptr< Logger > LoggerPtr
Definition logmanager.h:28