From 9b696c2fc39cadab78ca674ce5fb1cbfd04478a2 Mon Sep 17 00:00:00 2001 From: Guido Kanschat Date: Wed, 4 Feb 2004 13:01:04 +0000 Subject: [PATCH] release cerr on destruction git-svn-id: https://svn.dealii.org/trunk@8393 0785d39b-7218-0410-832d-ea1e28bc413d --- deal.II/base/include/base/logstream.h | 17 ++++++++++++++++- deal.II/base/source/log.cc | 19 ++++++++++++++++--- 2 files changed, 32 insertions(+), 4 deletions(-) diff --git a/deal.II/base/include/base/logstream.h b/deal.II/base/include/base/logstream.h index aa7b22f155..6305245416 100644 --- a/deal.II/base/include/base/logstream.h +++ b/deal.II/base/include/base/logstream.h @@ -2,7 +2,7 @@ // $Id$ // Version: $Name$ // -// Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003 by the deal.II authors +// Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004 by the deal.II authors // // This file is subject to QPL and may not be distributed // without copyright and license information. Please refer @@ -62,6 +62,11 @@ class LogStream * standard output stream to std::cerr. */ LogStream (); + + /** + * Destructor. + */ + ~LogStream(); /** * Enable output to a second @@ -89,6 +94,10 @@ class LogStream /** * Reroutes cerr to LogStream. + * Works as a switch, turning + * logging of cerr on + * and of alternatingly with + * every call. */ void log_cerr (); @@ -308,6 +317,12 @@ class LogStream */ template void print (const T &t); + /** + * Original buffer of + * cerr in order to + * leave this class properly. + */ + std::ostream::__streambuf_type* old_cerr; }; diff --git a/deal.II/base/source/log.cc b/deal.II/base/source/log.cc index 41b0ca5fb8..6e5e135dd5 100644 --- a/deal.II/base/source/log.cc +++ b/deal.II/base/source/log.cc @@ -2,7 +2,7 @@ // $Id$ // Version: $Name$ // -// Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003 by the deal.II authors +// Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004 by the deal.II authors // // This file is subject to QPL and may not be distributed // without copyright and license information. Please refer @@ -50,13 +50,20 @@ LogStream::LogStream() std_out(&std::cerr), file(0), was_endl(true), std_depth(10000), file_depth(10000), print_utime(false), diff_utime(false), - last_time (0.) + last_time (0.), old_cerr(0) { prefixes.push("DEAL:"); std_out->setf(std::ios::showpoint | std::ios::left); } +LogStream::~LogStream() +{ + if (old_cerr) + std::cerr.rdbuf(old_cerr); +} + + void LogStream::attach(std::ostream& o) { @@ -74,7 +81,13 @@ void LogStream::detach () void LogStream::log_cerr () { - std::cerr.rdbuf(file->rdbuf()); + if (old_cerr == 0) + { + old_cerr = std::cerr.rdbuf(file->rdbuf()); + } else { + std::cerr.rdbuf(old_cerr); + old_cerr = 0; + } } -- 2.39.5