log4tango  5.0.1
LogStream.hh
Go to the documentation of this file.
1 //
2 // LogStream.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_LOG_STREAM_H
29 #define _LOG4TANGO_LOG_STREAM_H
30 
31 #include <log4tango/Portability.hh>
32 #ifdef LOG4TANGO_HAVE_SSTREAM
33 # include <iostream>
34 #else
35 # include <iostream.h>
36 #endif
40 
41 namespace log4tango {
42 
43 //-----------------------------------------------------------------------------
44 // Class : LogStream
45 //-----------------------------------------------------------------------------
47 {
48 protected:
49 
51 
52  std::ostream _ostream;
53 
54 public:
55 
56  LogStream(LogStreamBuf* stream_buf);
57 
58  virtual ~LogStream();
59 
61  return *this;
62  }
63 
64  template<typename T> LogStream& operator<< (const T& t) {
65  _rmutex.lock();
66  _ostream << t;
67  return *this;
68  }
69 
71  _rmutex.lock();
72  _ostream.flush();
73  _rmutex.unlockn();
74  return *this;
75  }
76 };
77 
78 inline std::ostream&
79 operator<< (std::ostream& o_str, LogSeparator&)
80 {
81  o_str.flush();
82  return o_str;
83 }
84 
85 } // namespace log4tango
86 
87 #endif // _LOG4TANGO_LOG_STREAM_H
Portability.hh
log4tango::LogInitiator
Definition: LogSeparator.hh:38
log4tango::threading::RecursiveMutex::lock
int lock(long timeout_=0)
Definition: MSThreads.hh:142
log4tango::operator<<
std::ostream & operator<<(std::ostream &o_str, LogSeparator &)
Definition: LogStream.hh:79
LogSeparator.hh
log4tango::LogStream::_rmutex
threading::RecursiveMutex _rmutex
Definition: LogStream.hh:50
Threading.hh
log4tango::LogStream
Definition: LogStream.hh:46
log4tango::threading::RecursiveMutex
Definition: MSThreads.hh:123
log4tango::LogStreamBuf
Definition: LogStreambuf.hh:44
log4tango
Definition: Appender.hh:40
LOG4TANGO_EXPORT
#define LOG4TANGO_EXPORT
Definition: Export.hh:38
log4tango::LogStream::_ostream
std::ostream _ostream
Definition: LogStream.hh:52
log4tango::threading::RecursiveMutex::unlockn
void unlockn(void)
Definition: MSThreads.hh:159
log4tango::LogSeparator
Definition: LogSeparator.hh:46
LogStreambuf.hh