log4tango
4.0.3
|
00001 // 00002 // LoggerStream.hh 00003 // 00004 // Copyright (C) : 2000 - 2002 00005 // LifeLine Networks BV (www.lifeline.nl). All rights reserved. 00006 // Bastiaan Bakker. All rights reserved. 00007 // 00008 // 2004,2005,2006,2007,2008,2009,2010 00009 // Synchrotron SOLEIL 00010 // L'Orme des Merisiers 00011 // Saint-Aubin - BP 48 - France 00012 // 00013 // This file is part of log4tango. 00014 // 00015 // Log4ango is free software: you can redistribute it and/or modify 00016 // it under the terms of the GNU Lesser General Public License as published by 00017 // the Free Software Foundation, either version 3 of the License, or 00018 // (at your option) any later version. 00019 // 00020 // Log4tango is distributed in the hope that it will be useful, 00021 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00022 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00023 // GNU Lesser General Public License for more details. 00024 // 00025 // You should have received a copy of the GNU Lesser General Public License 00026 // along with Log4Tango. If not, see <http://www.gnu.org/licenses/>. 00027 00028 #ifndef _LOG4TANGO_LOGGER_STREAM_H 00029 #define _LOG4TANGO_LOGGER_STREAM_H 00030 00031 #include <log4tango/Portability.hh> 00032 #include <log4tango/Level.hh> 00033 #ifdef LOG4TANGO_HAVE_SSTREAM 00034 # include <sstream> 00035 #endif 00036 #include <log4tango/LogSeparator.hh> 00037 00038 namespace log4tango { 00039 00040 //----------------------------------------------------------------------------- 00041 // FORWARD DECLARATION 00042 //----------------------------------------------------------------------------- 00043 class LOG4TANGO_EXPORT Logger; 00044 class LoggerStream; 00045 00046 //----------------------------------------------------------------------------- 00047 // DEFINE WHAT IS A LS_TERMINATOR 00048 //----------------------------------------------------------------------------- 00049 typedef LoggerStream& (*ls_terminator) (LoggerStream&); 00050 00051 00052 typedef class std::ios_base&(*StdIosFlag)(class std::ios_base&); 00053 00054 00055 //----------------------------------------------------------------------------- 00056 // class : LoggerStream 00057 //----------------------------------------------------------------------------- 00058 class LoggerStream 00059 { 00060 public: 00061 00069 LOG4TANGO_EXPORT LoggerStream(Logger& logger, Level::Value level, bool filter = true); 00070 00074 LOG4TANGO_EXPORT ~LoggerStream(); 00075 00080 inline LOG4TANGO_EXPORT Logger& get_logger (void) const { 00081 return _logger; 00082 }; 00083 00088 inline LOG4TANGO_EXPORT Level::Value get_level (void) const { 00089 return _level; 00090 }; 00091 00097 inline LOG4TANGO_EXPORT LoggerStream& operator<< (LogInitiator& i) { 00098 return *this; 00099 } 00100 00107 inline LOG4TANGO_EXPORT LoggerStream& operator<< (LogSeparator& s) { 00108 flush(); 00109 return *this; 00110 } 00111 00118 inline LOG4TANGO_EXPORT LoggerStream& operator<< (ls_terminator endoflog) { 00119 flush(); 00120 return *this; 00121 } 00122 00127 LOG4TANGO_EXPORT void flush (void); 00128 00134 #ifdef WIN32 00135 inline LOG4TANGO_EXPORT LoggerStream& operator<< (std::ios_base&(_cdecl *_F)(std::ios_base&)) { 00136 #else 00137 inline LOG4TANGO_EXPORT LoggerStream& operator<< (std::ios_base&(*_F)(std::ios_base&)) { 00138 #endif 00139 #ifndef LOG4TANGO_HAVE_SSTREAM 00140 if (!_buffer) 00141 _buffer = new std::ostringstream; 00142 #endif 00143 if (_buffer) 00144 (*_F)(*(std::ios_base *)(_buffer)); 00145 return *this; 00146 } 00147 00153 template<typename T> LoggerStream& operator<< (const T& t) { 00154 if (_level != Level::OFF) { 00155 #ifndef LOG4TANGO_HAVE_SSTREAM 00156 if (!_buffer) 00157 _buffer = new std::ostringstream; 00158 #endif 00159 if (_buffer) 00160 (*_buffer) << t; 00161 } 00162 return *this; 00163 } 00164 00165 private: 00166 00167 Logger& _logger; 00168 00169 Level::Value _level; 00170 00171 bool _filter; 00172 00173 std::ostringstream* _buffer; 00174 }; 00175 00176 } // namespace log4tango 00177 00178 namespace std { 00179 //-- A dummy <ls_terminator> 00180 inline log4tango::LoggerStream& endl (log4tango::LoggerStream& ls) { 00181 return ls; 00182 } 00183 } // namespace std 00184 00185 #endif // _LOG4TANGO_LOGGER_STREAM_H