29 #include <coil/Mutex.h> 30 #include <coil/Guard.h> 36 #define BUFFER_LEN LINE_MAX 53 template <
typename _CharT,
typename _Traits=std::
char_traits<_CharT> >
55 :
public ::std::basic_streambuf<_CharT, _Traits>
84 this->setp(pStart, pEnd);
85 this->setg(pStart, pStart, pEnd);
136 void addStream(streambuf_type* stream,
bool cleanup =
false)
165 std::vector<coil::log_streambuf<char>::Stream>::iterator it;
168 if (it->stream_ == stream)
198 std::vector<streambuf_type*> buffs;
199 for (
int i(0), len(
m_streams.size()); i < len; ++i)
226 virtual std::streamsize
xsputn(
const char_type* s, std::streamsize n)
229 for (
int i(0), len(
m_streams.size()); i < len; ++i)
255 bytes_to_write = this->pptr() - this->gptr();
256 if (bytes_to_write > 0)
258 for (
int i(0), len(
m_streams.size()); i < len; ++i)
261 m_streams[i].stream_->sputn(this->gptr(), bytes_to_write);
263 this->gbump(bytes_to_write);
264 if (this->gptr() >= this->pptr())
266 this->pbump(this->pbase() - this->pptr());
267 this->gbump(this->pbase() - this->gptr());
270 return bytes_to_write;
293 virtual std::streamsize
stream_sputn(
const char_type* s, std::streamsize n)
296 for (
int i(0), len(
m_streams.size()); i < len; ++i)
336 if (this->pptr() > this->epptr() || this->pptr() < this->pbase())
337 return traits_type::eof();
339 if (!traits_type::eq_int_type(c, traits_type::eof()))
342 *(this->pptr()) = traits_type::to_char_type(c);
346 int bytes_to_write = this->pptr() - this->gptr();
348 if (bytes_to_write > 0)
350 if (
stream_sputn(this->gptr(), bytes_to_write) != bytes_to_write)
351 return traits_type::eof();
353 this->pbump(this->pbase() - this->pptr());
354 this->gbump(this->pbase() - this->gptr());
358 else if (!traits_type::eq_int_type(c, traits_type::eof()))
361 char_type last_char = traits_type::to_char_type(c);
364 return traits_type::eof();
368 if (traits_type::eq_int_type(c, traits_type::eof()))
369 return traits_type::not_eof(c);
394 if (this->pptr() > this->epptr() || this->pptr() < this->pbase())
398 bytes_to_write = this->pptr() - this->gptr();
399 if (bytes_to_write > 0)
401 if (
stream_sputn(this->gptr(), bytes_to_write) != bytes_to_write)
405 this->gbump(bytes_to_write);
406 if (this->gptr() >= this->pptr())
408 this->pbump(this->pbase() - this->pptr());
409 this->gbump(this->pbase() - this->gptr());
435 Stream(streambuf_type* stream,
bool cleanup =
false)
458 streambuf_type* stream = x.
stream_;
539 template <
typename _CharT,
typename _Traits=std::
char_traits<_CharT> >
541 :
public std::basic_ostream<_CharT, _Traits>
577 log_stream(streambuf_type* sb,
int levelmin,
int levelmax,
int level)
579 m_minLevel(levelmin), m_maxLevel(levelmax), m_logLevel(level)
581 if (m_minLevel >= m_maxLevel)
throw std::bad_alloc();
629 if (m_minLevel <= level && level <= m_maxLevel)
698 m_lockEnable =
false;
734 if (m_minLevel <= level && level <= m_logLevel)
771 return m_minLevel <= level && level <= m_logLevel;
926 template <
typename _CharT,
typename _Traits >
929 template <
typename _CharT,
typename _Traits >
log_streambuf template class
virtual int sync()
override of basic_streambuf::sync
static Mutex m_mutex
Mutual exclusion object.
Structure for stream management.
coil::Guard< Mutex > Guard
log_stream(streambuf_type *sb, int levelmin, int levelmax, int level)
Constructor.
log_streambuf()
Constructor.
log_stream< char > LogStream
Stream(streambuf_type *stream, bool cleanup=false)
virtual std::streamsize stream_sputn(const char_type *s, std::streamsize n)
Writes up to n characters from the array pointed by s to the output sequence controlled by the stream...
std::vector< streambuf_type * > getBuffers()
Get stream buffer list.
virtual std::streamsize stream_sputn()
Write the stream buffer in stream.
coil::Guard< coil::Mutex > Guard
void addStream(streambuf_type *stream, bool cleanup=false)
Destructor.
virtual ~log_streambuf()
Destructor.
log_stream template class
std::vector< Stream > m_streams
virtual std::streamsize xsputn(const char_type *s, std::streamsize n)
override of basic_streambuf::xsputn
Stream & operator=(const Stream &x)
void enableLock()
Enable the lock mode.
bool setLevel(int level)
Set the log level.
std::basic_streambuf< char_type, traits_type > streambuf_type
log_streambuf< char > LogStreamBuffer
ostream_type & level(int level)
Acquire log stream.
std::basic_streambuf< char_type, traits_type > streambuf_type
bool isValid(int level) const
Log level effective check.
virtual int overflow(int c=traits_type::eof())
override of basic_streambuf::overflow
std::basic_ostream< char_type, traits_type > ostream_type
void lock()
Acquire log lock Acquire log lock when the lock mode is set.
virtual void header(int level)
Message header appender function.
std::ofstream m_dummy
Dummy log.
static bool m_lockEnable
Lock enable mode.
int getLevel() const
Get the log level.
void disableLock()
Disable the lock mode.
void unlock()
Release the log lock Release the log lock when the lock mode is set.
bool removeStream(streambuf_type *stream)
Destructor.
Common Object Interface Layer.