From a2bb0e30a4d95d3f18de782532f55d9d2368aa8c Mon Sep 17 00:00:00 2001 From: David Wells Date: Sun, 5 Aug 2018 19:37:42 -0400 Subject: [PATCH] Add another argument to LogStream::attach. Some tests that do not use initlog() have output that is formatted in a different way than the one set up by the default flags. --- include/deal.II/base/logstream.h | 10 ++++++++-- source/base/logstream.cc | 6 ++++-- tests/tests.h | 23 +++++++++++++++-------- 3 files changed, 27 insertions(+), 12 deletions(-) diff --git a/include/deal.II/base/logstream.h b/include/deal.II/base/logstream.h index 73216c1792..ed62db3590 100644 --- a/include/deal.II/base/logstream.h +++ b/include/deal.II/base/logstream.h @@ -144,10 +144,16 @@ public: /** * Enable output to a second stream o. * - * The optional argument @p print_job_id specifies whether + * @param[in] print_job_id Whether or not the JobIdentifier for the current + * process should be printed to the stream. + * + * @param[in] flags Format flags to set on the output stream @p o. */ void - attach(std::ostream &o, const bool print_job_id = true); + attach(std::ostream & o, + const bool print_job_id = true, + const std::ios_base::fmtflags flags = std::ios::showpoint | + std::ios::left); /** diff --git a/source/base/logstream.cc b/source/base/logstream.cc index 941dcc0a87..ccdb9a4ab0 100644 --- a/source/base/logstream.cc +++ b/source/base/logstream.cc @@ -214,11 +214,13 @@ LogStream::operator<<(std::ostream &(*p)(std::ostream &)) void -LogStream::attach(std::ostream &o, const bool print_job_id) +LogStream::attach(std::ostream & o, + const bool print_job_id, + const std::ios_base::fmtflags flags) { Threads::Mutex::ScopedLock lock(log_lock); file = &o; - o.setf(std::ios::showpoint | std::ios::left); + o.setf(flags); if (print_job_id) o << dealjobid(); } diff --git a/tests/tests.h b/tests/tests.h index 1ee7d71242..25ee9f2714 100644 --- a/tests/tests.h +++ b/tests/tests.h @@ -472,22 +472,26 @@ namespace // // This will open the correct output file, divert log output there and // switch off screen output. If screen output is desired, provide the -// optional second argument as 'true'. +// optional first argument as 'true'. std::string deallogname; std::ofstream deallogfile; void -initlog(bool console = false) +initlog(bool console = false, + const std::ios_base::fmtflags flags = std::ios::showpoint | + std::ios::left) { deallogname = "output"; deallogfile.open(deallogname.c_str()); - deallog.attach(deallogfile); + deallog.attach(deallogfile, true, flags); deallog.depth_console(console ? 10 : 0); } inline void -mpi_initlog(const bool console = false) +mpi_initlog(const bool console = false, + const std::ios_base::fmtflags flags = std::ios::showpoint | + std::ios::left) { #ifdef DEAL_II_WITH_MPI unsigned int myid = Utilities::MPI::this_mpi_process(MPI_COMM_WORLD); @@ -495,11 +499,12 @@ mpi_initlog(const bool console = false) { deallogname = "output"; deallogfile.open(deallogname.c_str()); - deallog.attach(deallogfile); + deallog.attach(deallogfile, true, flags); deallog.depth_console(console ? 10 : 0); } #else (void)console; + (void)flags; // can't use this function if not using MPI Assert(false, ExcInternalError()); #endif @@ -515,7 +520,9 @@ mpi_initlog(const bool console = false) */ struct MPILogInitAll { - MPILogInitAll(const bool console = false) + MPILogInitAll(const bool console = false, + const std::ios_base::fmtflags flags = std::ios::showpoint | + std::ios::left) { #ifdef DEAL_II_WITH_MPI const unsigned int myid = Utilities::MPI::this_mpi_process(MPI_COMM_WORLD); @@ -524,14 +531,14 @@ struct MPILogInitAll if (!deallog.has_file()) { deallogfile.open("output"); - deallog.attach(deallogfile); + deallog.attach(deallogfile, true, flags); } } else { deallogname = "output" + Utilities::int_to_string(myid); deallogfile.open(deallogname.c_str()); - deallog.attach(deallogfile); + deallog.attach(deallogfile, true, flags); } deallog.depth_console(console ? 10 : 0); -- 2.39.5