]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Add another argument to LogStream::attach.
authorDavid Wells <drwells@email.unc.edu>
Sun, 5 Aug 2018 23:37:42 +0000 (19:37 -0400)
committerDavid Wells <drwells@email.unc.edu>
Mon, 6 Aug 2018 13:34:25 +0000 (09:34 -0400)
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
source/base/logstream.cc
tests/tests.h

index 73216c17923611bf2c41ad75071d526f43a0a4ef..ed62db3590d7c61a04d33c9d26f99fdce7eef3cf 100644 (file)
@@ -144,10 +144,16 @@ public:
   /**
    * Enable output to a second stream <tt>o</tt>.
    *
-   * 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);
 
 
   /**
index 941dcc0a8703ccfffe252b441af49d3532c8190d..ccdb9a4ab01407d910dcd0165990e20cf53d0a91 100644 (file)
@@ -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();
 }
index 1ee7d71242824497e55f8bc66100bffaa01c8e15..25ee9f27141afcb7b00de7744131659d7122270b 100644 (file)
@@ -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);

In the beginning the Universe was created. This has made a lot of people very angry and has been widely regarded as a bad move.

Douglas Adams


Typeset in Trocchi and Trocchi Bold Sans Serif.