From 0189528bb6479dc2e46b13f66208c7129ded3492 Mon Sep 17 00:00:00 2001 From: maier Date: Tue, 11 Jun 2013 08:36:26 +0000 Subject: [PATCH] Allow to pop the "DEAL" prefix from logstream git-svn-id: https://svn.dealii.org/trunk@29805 0785d39b-7218-0410-832d-ea1e28bc413d --- deal.II/doc/news/changes.h | 2 +- deal.II/source/base/logstream.cc | 20 +++++++++++++++----- 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/deal.II/doc/news/changes.h b/deal.II/doc/news/changes.h index dfb20d925c..70ebb99fe1 100644 --- a/deal.II/doc/news/changes.h +++ b/deal.II/doc/news/changes.h @@ -374,7 +374,7 @@ parallel benchmark timings.
  • Improved and Fixed: LogStream (and deallog) now respect std::flush in addition to std::endl to write out content to the console/file. Furthermore, LogStream::push(...) and LogStream::pop() now work in a thread -safe manner. +safe manner. Also allow to pop() the prefix "DEAL".
    (Matthias Maier, 2013/04/18)
  • diff --git a/deal.II/source/base/logstream.cc b/deal.II/source/base/logstream.cc index e0fc350cf5..b9197a1b1e 100644 --- a/deal.II/source/base/logstream.cc +++ b/deal.II/source/base/logstream.cc @@ -226,14 +226,22 @@ LogStream::has_file() const const std::string & LogStream::get_prefix() const { - return get_prefixes().top(); + static std::string empty_string; + + if (get_prefixes().size() > 0) + return get_prefixes().top(); + else + return empty_string; } void LogStream::push (const std::string &text) { - std::string pre=get_prefixes().top(); + std::string pre; + if (get_prefixes().size() > 0) + pre = get_prefixes().top(); + pre += text; pre += std::string(":"); get_prefixes().push(pre); @@ -242,7 +250,7 @@ LogStream::push (const std::string &text) void LogStream::pop () { - if (get_prefixes().size() > 1) + if (get_prefixes().size() > 0) get_prefixes().pop(); } @@ -436,7 +444,8 @@ LogStream::print_line_head() if (print_thread_id) *std_out << '[' << thread << ']'; - *std_out << head << ':'; + if (head.size() > 0) + *std_out << head << ':'; } if (file && (get_prefixes().size() <= file_depth)) @@ -453,7 +462,8 @@ LogStream::print_line_head() if (print_thread_id) *file << '[' << thread << ']'; - *file << head << ':'; + if (head.size() > 0) + *file << head << ':'; } } -- 2.39.5