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)
138 m_streams.push_back(
Stream(stream, cleanup));
165 std::vector<coil::log_streambuf<char>::Stream>::iterator it;
166 for( it = m_streams.begin(); it != m_streams.end(); it++ )
168 if (it->stream_ == stream)
198 std::vector<streambuf_type*> buffs;
199 for (
int i(0), len(m_streams.size()); i < len; ++i)
201 buffs.push_back(m_streams[i].stream_);
226 virtual std::streamsize
xsputn(
const char_type* s, std::streamsize n)
229 for (
size_t i(0), len(m_streams.size()); i < len; ++i)
231 Guard gaurd(m_streams[i].mutex_);
232 m_streams[i].stream_->sputn(s, n);
254 size_t bytes_to_write;
255 bytes_to_write = this->pptr() - this->gptr();
256 if (bytes_to_write > 0)
258 for (
size_t i(0), len(m_streams.size()); i < len; ++i)
260 Guard gaurd(m_streams[i].mutex_);
261 m_streams[i].stream_->sputn(this->gptr(), bytes_to_write);
263 this->gbump(static_cast<int>(bytes_to_write));
264 if (this->gptr() >= this->pptr())
266 this->pbump(static_cast<int>(this->pbase() - this->pptr()));
267 this->gbump(static_cast<int>(this->pbase() - this->gptr()));
270 return bytes_to_write;
293 virtual std::streamsize
stream_sputn(
const char_type* s, std::streamsize n)
296 for (
size_t i(0), len(m_streams.size()); i < len; ++i)
298 Guard gaurd(m_streams[i].mutex_);
299 m_streams[i].stream_->sputn(s, n);
300 m_streams[i].stream_->pubsync();
324 Guard guard(m_mutex);
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 size_t 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(static_cast<int>(this->pbase() - this->pptr()));
354 this->gbump(static_cast<int>(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);
393 Guard guard(m_mutex);
394 if (this->pptr() > this->epptr() || this->pptr() < this->pbase())
397 size_t bytes_to_write;
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(static_cast<int>(bytes_to_write));
406 if (this->gptr() >= this->pptr())
408 this->pbump(static_cast<int>(this->pbase() - this->pptr()));
409 this->gbump(static_cast<int>(this->pbase() - this->gptr()));
435 Stream(streambuf_type* stream,
bool cleanup =
false)
458 streambuf_type* stream = x.
stream_;
520 std::vector<Stream> m_streams;
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;
789 if (m_lockEnable) m_mutex.lock();
807 if (m_lockEnable) m_mutex.unlock();
894 int m_minLevel, m_maxLevel;
904 std::ofstream m_dummy;
926 template <
typename _CharT,
typename _Traits >
929 template <
typename _CharT,
typename _Traits >
void swap(Stream &x)
Definition: Logger.h:456
bool isValid(int level) const
ログレベル有効チェック
Definition: Logger.h:769
log_streambuf テンプレートクラス
Definition: Logger.h:54
coil::Mutex Mutex
Definition: Logger.h:61
Mutex クラス
Definition: Mutex.h:40
coil::Mutex Mutex
Definition: Logger.h:549
_Traits traits_type
Definition: Logger.h:59
_CharT char_type
Definition: Logger.h:545
virtual int sync()
basic_streambuf::sync のオーバーライド
Definition: Logger.h:389
virtual ~Stream()
Definition: Logger.h:440
static Mutex m_mutex
排他制御オブジェクト
Definition: Logger.h:923
ストリーム管理用構造体
Definition: Logger.h:433
coil::Guard< Mutex > Guard
Definition: Logger.h:550
log_stream(streambuf_type *sb, int levelmin, int levelmax, int level)
コンストラクタ
Definition: Logger.h:577
log_streambuf()
コンストラクタ
Definition: Logger.h:79
log_stream< char > LogStream
Definition: Logger.h:933
Stream(streambuf_type *stream, bool cleanup=false)
Definition: Logger.h:435
virtual std::streamsize stream_sputn(const char_type *s, std::streamsize n)
ストリームへ出力する。
Definition: Logger.h:293
std::vector< streambuf_type * > getBuffers()
ストリームバッファ取得
Definition: Logger.h:196
virtual std::streamsize stream_sputn()
ストリームへ出力する。
Definition: Logger.h:252
coil::Guard< coil::Mutex > Guard
Definition: Logger.h:62
#define BUFFER_LEN
Definition: Logger.h:36
_CharT char_type
Definition: Logger.h:58
void addStream(streambuf_type *stream, bool cleanup=false)
ストリームを追加する
Definition: Logger.h:136
virtual ~log_streambuf()
デストラクタ
Definition: Logger.h:103
log_stream テンプレートクラス
Definition: Logger.h:540
virtual std::streamsize xsputn(const char_type *s, std::streamsize n)
basic_streambuf::xsputn のオーバーライド
Definition: Logger.h:226
_Traits traits_type
Definition: Logger.h:546
Stream & operator=(const Stream &x)
Definition: Logger.h:449
void enableLock()
ロックモード設定
Definition: Logger.h:676
bool setLevel(int level)
ログレベル設定
Definition: Logger.h:627
std::basic_streambuf< char_type, traits_type > streambuf_type
Definition: Logger.h:548
log_streambuf< char > LogStreamBuffer
Definition: Logger.h:932
ostream_type & level(int level)
ログストリームの取得
Definition: Logger.h:732
streambuf_type * stream_
Definition: Logger.h:468
std::basic_streambuf< char_type, traits_type > streambuf_type
Definition: Logger.h:60
Stream(const Stream &x)
Definition: Logger.h:444
Mutex mutex_
Definition: Logger.h:467
virtual int overflow(int c=traits_type::eof())
basic_streambuf::overflow のオーバーライド
Definition: Logger.h:322
std::basic_ostream< char_type, traits_type > ostream_type
Definition: Logger.h:547
void lock()
ログロック取得 ロックモードが設定されている場合、ログのロックを取得する。
Definition: Logger.h:787
virtual void header(int level)
メッセージのヘッダ追加関数
Definition: Logger.h:603
static bool m_lockEnable
ロック有効モード
Definition: Logger.h:914
void disableLock()
ロックモード解除
Definition: Logger.h:696
void unlock()
ログロック解放 ロックモードが設定されている場合に、ログのロックを解放する。
Definition: Logger.h:805
bool removeStream(streambuf_type *stream)
ストリームを削除する
Definition: Logger.h:163
int getLevel() const
ログレベル取得
Definition: Logger.h:656
~log_stream()
デストラクタ
Definition: Logger.h:828
Common Object Interface Layer.
Definition: Affinity.h:28
bool cleanup_
Definition: Logger.h:469