Apache Log4cxx Version 1.1.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
26{
27
37class LOG4CXX_EXPORT logstream_base
38{
39 public:
47 const log4cxx::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
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::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::LoggerPtr logger;
208 log4cxx::LevelPtr level;
213};
214
215typedef logstream_base& (*logstream_manipulator)(logstream_base&);
216
226class LOG4CXX_EXPORT logstream : public logstream_base
227{
228 typedef char Ch;
229 public:
234 const log4cxx::LevelPtr& level);
235
239 logstream(const Ch* loggerName,
240 const log4cxx::LevelPtr& level);
241
245 logstream(const std::basic_string<Ch>& loggerName,
246 const log4cxx::LevelPtr& level);
247
249
253 logstream& operator<<(std::ios_base & (*manip)(std::ios_base&));
254
258 logstream& operator<<(logstream_manipulator manip);
259
268
274
278 operator std::basic_ostream<Ch>& ();
279
280#if !(LOG4CXX_USE_GLOBAL_SCOPE_TEMPLATE)
285 template <class V>
286 inline log4cxx::logstream& operator<<(const V& val)
287 {
288 if (LOG4CXX_UNLIKELY(isEnabled()))
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::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:
337 const log4cxx::LevelPtr& level);
338
342 wlogstream(const Ch* loggerName,
343 const log4cxx::LevelPtr& level);
344
348 wlogstream(const std::basic_string<Ch>& loggerName,
349 const log4cxx::LevelPtr& level);
350
352
356 wlogstream& operator<<(std::ios_base & (*manip)(std::ios_base&));
357
361 wlogstream& operator<<(logstream_manipulator manip);
362
371
377
378
382 operator std::basic_ostream<Ch>& ();
383
384#if !(LOG4CXX_USE_GLOBAL_SCOPE_TEMPLATE)
389 template <class V>
390 inline log4cxx::wlogstream& operator<<(const V& val)
391 {
392 if (LOG4CXX_UNLIKELY(isEnabled()))
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::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#if LOG4CXX_UNICHAR_API || LOG4CXX_CFSTRING_API
433class LOG4CXX_EXPORT ulogstream : public logstream_base
434{
435 typedef UniChar Ch;
436 public:
441 const log4cxx::LevelPtr& level);
442
443#if LOG4CXX_UNICHAR_API
447 ulogstream(const Ch* loggerName,
448 const log4cxx::LevelPtr& level);
449
453 ulogstream(const std::basic_string<Ch>& loggerName,
454 const log4cxx::LevelPtr& level);
455#endif
456
457#if LOG4CXX_CFSTRING_API
458 ulogstream(const CFStringRef& loggerName,
459 const log4cxx::LevelPtr& level);
460#endif
461
463
467 ulogstream& operator<<(std::ios_base & (*manip)(std::ios_base&));
468
472 ulogstream& operator<<(logstream_manipulator manip);
473
482
488
489
493 operator std::basic_ostream<Ch>& ();
494
495#if !(LOG4CXX_USE_GLOBAL_SCOPE_TEMPLATE)
500 template <class V>
501 inline ulogstream& operator<<(const V& val)
502 {
503 if (LOG4CXX_UNLIKELY(isEnabled()))
504 {
505 ((std::basic_ostream<Ch>&) *this) << val;
506 }
507
508 return *this;
509 }
510#endif
511
512 protected:
513 virtual void log(LoggerPtr& logger,
514 const LevelPtr& level,
515 const log4cxx::spi::LocationInfo& location);
516
517 virtual void erase();
518
519 virtual void get_stream_state(std::ios_base& base,
520 std::ios_base& mask,
521 int& fill,
522 bool& fillSet) const;
523 virtual void refresh_stream_state();
524
525
526 private:
527 ulogstream(const ulogstream&);
528 ulogstream& operator=(const ulogstream&);
529 std::basic_stringstream<Ch>* stream;
530
531};
532#endif
533
534
535} // namespace log4cxx
536
537
538#if LOG4CXX_USE_GLOBAL_SCOPE_TEMPLATE
539//
540// VC6 will fail to compile if class-scope templates
541// are used to handle arbitrary insertion operations.
542// However, using global namespace insertion operations
543// run into LOGCXX-150.
544
549template <class V>
550inline log4cxx::logstream& operator<<(log4cxx::logstream& os, const V& val)
551{
552 if (LOG4CXX_UNLIKELY(os.isEnabled()))
553 {
554 ((std::basic_ostream<char>&) os) << val;
555 }
556
557 return os;
558}
559
560#if LOG4CXX_WCHAR_T_API
565template <class V>
566inline log4cxx::wlogstream& operator<<(log4cxx::wlogstream& os, const V& val)
567{
568 if (LOG4CXX_UNLIKELY(os.isEnabled()))
569 {
570 ((std::basic_ostream<wchar_t>&) os) << val;
571 }
572
573 return os;
574}
575#endif
576#endif
577
578#if !defined(LOG4CXX_ENDMSG)
579 #if LOG4CXX_LOGSTREAM_ADD_NOP
580 #define LOG4CXX_ENDMSG (log4cxx::logstream_manipulator) log4cxx::logstream_base::nop >> LOG4CXX_LOCATION << (log4cxx::logstream_manipulator) log4cxx::logstream_base::endmsg
581 #else
582 #define LOG4CXX_ENDMSG LOG4CXX_LOCATION << (log4cxx::logstream_manipulator) log4cxx::logstream_base::endmsg
583 #endif
584#endif
585
586
587#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.
An STL-like stream API for log4cxx using char as the character type.
Definition: stream.h:227
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
This class represents the location of a logging statement.
Definition: locationinfo.h:46
An STL-like stream API for log4cxx using UniChar as the character type.
Definition: stream.h:434
ulogstream & operator<<(const log4cxx::LevelPtr &level)
Insertion operator for level.
ulogstream(const CFStringRef &loggerName, const log4cxx::LevelPtr &level)
virtual void log(LoggerPtr &logger, const LevelPtr &level, const log4cxx::spi::LocationInfo &location)
Dispatches the pending log request.
virtual void erase()
Erase any content in the message construction buffer.
ulogstream(const log4cxx::LoggerPtr &logger, const log4cxx::LevelPtr &level)
Constructor.
ulogstream & operator>>(const log4cxx::spi::LocationInfo &location)
Alias for insertion operator for location.
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...
ulogstream(const std::basic_string< Ch > &loggerName, const log4cxx::LevelPtr &level)
Constructor.
ulogstream(const Ch *loggerName, const log4cxx::LevelPtr &level)
Constructor.
ulogstream & operator<<(logstream_manipulator manip)
Insertion operator for logstream_base::endmsg.
ulogstream & operator<<(const V &val)
Template to allow any class with an std::basic_ostream inserter to be applied to this class.
Definition: stream.h:501
ulogstream & operator<<(std::ios_base &(*manip)(std::ios_base &))
Insertion operator for std::fixed and similar manipulators.
ulogstream & operator<<(const log4cxx::spi::LocationInfo &location)
Insertion operator for location.
virtual void refresh_stream_state()
An STL-like stream API for log4cxx using wchar_t as the character type.
Definition: stream.h:330
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...
#define LOG4CXX_UNLIKELY(expr)
Provides optimization hint to the compiler to optimize for the expression being false.
Definition: logger.h:1956
const struct __CFString * CFStringRef
Definition: logstring.h:30
std::basic_ostream< char > & operator<<(CharMessageBuffer &os, const V &val)
Definition: messagebuffer.h:185
Definition: configuration.h:25
std::shared_ptr< Level > LevelPtr
Definition: optionconverter.h:28
unsigned short UniChar
Definition: logstring.h:38
std::shared_ptr< Logger > LoggerPtr
Definition: defaultloggerfactory.h:27