log4tango  4.0.3
LogStream.hh
Go to the documentation of this file.
00001 //
00002 // LogStream.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_LOG_STREAM_H
00029 #define _LOG4TANGO_LOG_STREAM_H
00030 
00031 #include <log4tango/Portability.hh>
00032 #ifdef LOG4TANGO_HAVE_SSTREAM
00033 # include <iostream>
00034 #else
00035 # include <iostream.h>
00036 #endif
00037 #include <log4tango/threading/Threading.hh>
00038 #include <log4tango/LogStreambuf.hh>
00039 #include <log4tango/LogSeparator.hh>
00040 
00041 namespace log4tango {
00042 
00043 //-----------------------------------------------------------------------------
00044 // Class : LogStream
00045 //-----------------------------------------------------------------------------
00046 class LOG4TANGO_EXPORT LogStream
00047 {
00048 protected:
00049 
00050   threading::RecursiveMutex _rmutex;
00051 
00052   std::ostream _ostream;
00053 
00054 public:
00055   
00056   LogStream(LogStreamBuf* stream_buf);
00057 
00058   virtual ~LogStream();
00059 
00060   inline LogStream& operator<< (const LogInitiator&) {
00061     return *this;
00062   }
00063   
00064   template<typename T> LogStream& operator<< (const T& t) {
00065     _rmutex.lock();
00066     _ostream << t;
00067     return *this;
00068   }
00069 
00070   inline LogStream& operator<< (LogSeparator&) {
00071     _rmutex.lock();
00072     _ostream.flush();
00073     _rmutex.unlockn();
00074     return *this;
00075   }
00076 };
00077 
00078 inline std::ostream& 
00079 operator<< (std::ostream& o_str, LogSeparator&)
00080 {
00081   o_str.flush();
00082         return o_str; 
00083 }
00084 
00085 } // namespace log4tango
00086 
00087 #endif // _LOG4TANGO_LOG_STREAM_H