diff options
author | Boris Kolpackov <boris@codesynthesis.com> | 2016-11-22 12:08:21 +0200 |
---|---|---|
committer | Boris Kolpackov <boris@codesynthesis.com> | 2016-11-22 12:08:21 +0200 |
commit | 0324ad68eed762ebf00ed4fb5a7ea2f2e3bd77b6 (patch) | |
tree | 36a327dbe3f33c6c25eb48ba54491261411dadfe /butl/diagnostics.cxx | |
parent | a345a24df9e40e0ba2bf1b35a5a98420b4cc255d (diff) |
Add diagnostics facility
Diffstat (limited to 'butl/diagnostics.cxx')
-rw-r--r-- | butl/diagnostics.cxx | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/butl/diagnostics.cxx b/butl/diagnostics.cxx new file mode 100644 index 0000000..e4c22dc --- /dev/null +++ b/butl/diagnostics.cxx @@ -0,0 +1,41 @@ +// file : butl/diagnostics.cxx -*- C++ -*- +// copyright : Copyright (c) 2014-2016 Code Synthesis Ltd +// license : MIT; see accompanying LICENSE file + +#include <butl/diagnostics> + +#include <iostream> // cerr + +using namespace std; + +namespace butl +{ + ostream* diag_stream = &cerr; + + void diag_record:: + flush () const + { + if (!empty_) + { + *diag_stream << os.str () << endl; + empty_ = true; + + if (epilogue_ != nullptr) + epilogue_ (*this); // Can throw. + } + } + + diag_record:: + ~diag_record () noexcept (false) + { + // Don't flush the record if this destructor was called as part of + // the stack unwinding. Right now this means we cannot use this + // mechanism in destructors, which is not a big deal, except for + // one place: exception_guard. So for now we are going to have + // this ugly special check which we will be able to get rid of + // once C++17 uncaught_exceptions() becomes available. + // + if (!std::uncaught_exception () || exception_unwinding_dtor) + flush (); + } +} |