18 #include <flecsi-config.h> 20 #if defined(FLECSI_ENABLE_FLOG) 22 #include "flecsi/log/packet.hh" 23 #include "flecsi/log/utils.hh" 26 #include <unordered_map> 49 std::streambuf * buffer;
58 void add_buffer(std::string key, std::streambuf * sb,
bool colorized) {
59 if(buffers_.find(key) == buffers_.end()) {
60 buffers_[key].enabled =
true;
61 buffers_[key].buffer = sb;
62 buffers_[key].colorized = colorized;
72 assert(buffers_.find(key) != buffers_.end());
73 buffers_[key].enabled =
true;
74 return buffers_[key].enabled;
82 assert(buffers_.find(key) != buffers_.end());
83 buffers_[key].enabled =
false;
84 return buffers_[key].enabled;
105 const size_t tbsize = test_buffer_.size();
108 test_buffer_.append(1,
char(c));
119 return flush_buffer(all_buffers);
130 return flush_buffer(all_buffers);
134 if(c ==
'0' || c ==
'1') {
141 return flush_buffer(all_buffers);
152 return flush_buffer(color_buffers);
157 return flush_buffer(all_buffers);
168 return flush_buffer(all_buffers);
172 if(isdigit(c) && (c -
'0') < 8) {
179 return flush_buffer(all_buffers);
186 return flush_buffer(color_buffers);
191 return flush_buffer(all_buffers);
206 for(
auto b : buffers_) {
207 const int s = b.second.buffer->pubsync();
208 state = (state != 0) ? state : s;
212 return (state == 0) ? 0 : -1;
223 return bd.enabled && bd.colorized;
228 int flush_buffer(P && predicate = all_buffers) {
232 for(
auto b : buffers_) {
233 if(predicate(b.second)) {
234 for(
auto bc : test_buffer_) {
235 const int w = b.second.buffer->sputc(bc);
236 eof = (eof == EOF) ? eof : w;
242 test_buffer_.clear();
245 return eof == EOF ? EOF : !EOF;
248 std::unordered_map<std::string, buffer_data_t> buffers_;
249 std::string test_buffer_;
263 if(std::getenv(
"FLOG_ENABLE_STDLOG")) {
264 tee_.add_buffer(
"flog", std::clog.rdbuf(),
true);
278 bool colorized =
false) {
279 tee_.add_buffer(key, s.rdbuf(), colorized);
289 tee_.enable_buffer(key);
300 tee_.disable_buffer(key);
312 #endif // FLECSI_ENABLE_FLOG void add_buffer(std::string const &key, std::ostream &s, bool colorized=false)
Definition: types.hh:276
bool disable_buffer(std::string const &key)
Definition: types.hh:299
virtual int overflow(int c)
Definition: types.hh:99
bool enable_buffer(std::string const &key)
Definition: types.hh:288
bool enable_buffer(std::string key)
Definition: types.hh:71
bool disable_buffer(std::string key)
Definition: types.hh:81
virtual int sync()
Definition: types.hh:203
void add_buffer(std::string key, std::streambuf *sb, bool colorized)
Definition: types.hh:58
Definition: control.hh:31