| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | #include "na64util/streambuf-redirect.hh" | ||
| 2 | #include <sstream> | ||
| 3 | |||
| 4 | namespace na64dp { | ||
| 5 | namespace util { | ||
| 6 | |||
| 7 | ✗ | Log4Cpp_StreambufRedirect::Log4Cpp_StreambufRedirect( log4cpp::Category & c | |
| 8 | , log4cpp::Priority::PriorityLevel p | ||
| 9 | ✗ | ) : _category(c) | |
| 10 | ✗ | , _priority(p) { | |
| 11 | ✗ | std::ostringstream oss; | |
| 12 | ✗ | oss << std::endl; | |
| 13 | ✗ | _pdNl = oss.str(); | |
| 14 | } | ||
| 15 | |||
| 16 | void | ||
| 17 | ✗ | Log4Cpp_StreambufRedirect::_print_message_buffer() { | |
| 18 | ✗ | for( size_t n = _buf.find(_pdNl) | |
| 19 | ✗ | ; n != std::string::npos && !_buf.empty() | |
| 20 | ✗ | ; n = _buf.find(_pdNl) | |
| 21 | ) { | ||
| 22 | ✗ | if(_buf == _pdNl) { | |
| 23 | ✗ | _buf.clear(); | |
| 24 | ✗ | break; | |
| 25 | } | ||
| 26 | ✗ | _category << _priority << _buf.substr(0, n); | |
| 27 | ✗ | _buf = _buf.substr(n+_pdNl.size()); | |
| 28 | } | ||
| 29 | } | ||
| 30 | |||
| 31 | std::streamsize | ||
| 32 | ✗ | Log4Cpp_StreambufRedirect::xsputn(const char_type * c, std::streamsize n) { | |
| 33 | ✗ | if(0 == n) return 0; | |
| 34 | ✗ | std::string part(c, c+n); | |
| 35 | ✗ | _buf += part; | |
| 36 | ✗ | _print_message_buffer(); | |
| 37 | ✗ | return n; | |
| 38 | } | ||
| 39 | |||
| 40 | std::streambuf::int_type | ||
| 41 | ✗ | Log4Cpp_StreambufRedirect::overflow(int_type c) { | |
| 42 | ✗ | if(!traits_type::eq_int_type(c, traits_type::eof())){ | |
| 43 | ✗ | char_type const t = traits_type::to_char_type(c); | |
| 44 | ✗ | this->xsputn(&t, 1); | |
| 45 | } | ||
| 46 | ✗ | return !traits_type::eof(); | |
| 47 | } | ||
| 48 | |||
| 49 | int | ||
| 50 | ✗ | Log4Cpp_StreambufRedirect::sync() { | |
| 51 | ✗ | if(_buf.empty()) return 0; | |
| 52 | ✗ | _print_message_buffer(); | |
| 53 | ✗ | return 0; | |
| 54 | } | ||
| 55 | |||
| 56 | } // namespace ::na64dp::util | ||
| 57 | } // namespace na64dp | ||
| 58 |