diff options
author | Boris Kolpackov <boris@codesynthesis.com> | 2019-06-28 13:07:21 +0200 |
---|---|---|
committer | Boris Kolpackov <boris@codesynthesis.com> | 2019-06-28 13:07:21 +0200 |
commit | 646ff7d9933b550b65b8377b3fa1b9bd85056cb3 (patch) | |
tree | 308b613364b63a43847445dd50a969579f994bdc | |
parent | 5b549d176ba6eff19400c5edbd100eec825f6200 (diff) |
Add ability to specify custom diag_record writer
-rw-r--r-- | libbutl/diagnostics.cxx | 27 | ||||
-rw-r--r-- | libbutl/diagnostics.mxx | 5 |
2 files changed, 24 insertions, 8 deletions
diff --git a/libbutl/diagnostics.cxx b/libbutl/diagnostics.cxx index 43d931f..d9a979e 100644 --- a/libbutl/diagnostics.cxx +++ b/libbutl/diagnostics.cxx @@ -155,6 +155,23 @@ namespace butl diag_mutex.unlock (); } + static void + default_writer (const diag_record& r) + { + r.os.put ('\n'); + diag_stream_lock () << r.os.str (); + + // We can endup flushing the result of several writes. The last one may + // possibly be incomplete, but that's not a problem as it will also be + // followed by the flush() call. + // + // @@ Strange: why not just hold the lock for both write and flush? + // + diag_stream->flush (); + } + + void (*diag_record::writer) (const diag_record&) = &default_writer; + void diag_record:: flush () const { @@ -162,14 +179,8 @@ namespace butl { if (epilogue_ == nullptr) { - os.put ('\n'); - diag_stream_lock () << os.str (); - - // We can endup flushing the result of several writes. The last one may - // possibly be incomplete, but that's not a problem as it will also be - // followed by the flush() call. - // - diag_stream->flush (); + if (writer != nullptr) + writer (*this); empty_ = true; } diff --git a/libbutl/diagnostics.mxx b/libbutl/diagnostics.mxx index 43f13ad..c9ade44 100644 --- a/libbutl/diagnostics.mxx +++ b/libbutl/diagnostics.mxx @@ -179,6 +179,11 @@ LIBBUTL_MODEXPORT namespace butl diag_record (const diag_record&) = delete; diag_record& operator= (const diag_record&) = delete; + // Diagnostics writer. The default implementation writes the record text + // to diag_stream. If it is NULL, then the record text is ignored. + // + static void (*writer) (const diag_record&); + protected: #ifdef __cpp_lib_uncaught_exceptions const int uncaught_; |