diff options
author | David Mazieres <dm@uun.org> | 2014-02-08 02:13:25 -0800 |
---|---|---|
committer | David Mazieres <dm@uun.org> | 2014-02-08 02:13:25 -0800 |
commit | 6932e87ad71f15470c04721ce1854a10eca50bed (patch) | |
tree | fa82971069790085aeffa05a66ad8275787210d7 | |
parent | 7e923ea49f9b3162fa1964b2d1094629f95e3613 (diff) |
tag stderr in a more robust way
-rw-r--r-- | muchsync.cc | 20 |
1 files changed, 18 insertions, 2 deletions
diff --git a/muchsync.cc b/muchsync.cc index f6f03d2..8b3cf09 100644 --- a/muchsync.cc +++ b/muchsync.cc @@ -126,8 +126,6 @@ print_time (string msg) if (opt_verbose > 0) { auto oldFlags = cerr.flags(); cerr.setf (ios::fixed, ios::floatfield); - if (opt_server) - msg = "[SERVER] " + msg; cerr << msg << "... " << now - start_time_stamp << " (+" << now - last_time_stamp << ")\n"; cerr.flags (oldFlags); @@ -375,6 +373,23 @@ get_notmuch_config() exit(1); } +static void +tag_stderr(string tag) +{ + infinistreambuf *isb = + new infinistreambuf(new infinibuf_mt); + streambuf *err = cerr.rdbuf(isb); + thread t ([=]() { + istream in (isb); + ostream out (err); + string line; + while (getline(in, line)) + out << tag << line << endl; + }); + t.detach(); + cerr.rdbuf(isb); +} + [[noreturn]] void usage () { @@ -391,6 +406,7 @@ server () ifdinfinistream ibin(0); cleanup _fixbuf ([](streambuf *sb){ cin.rdbuf(sb); }, cin.rdbuf(ibin.rdbuf())); + tag_stderr("[SERVER] "); string maildir; try { maildir = notmuch_maildir_location(); } |