OpenFCST: The open-source Fuel Cell Simulation Toolbox
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
logging.h
Go to the documentation of this file.
1 //---------------------------------------------------------------------------
2 //
3 // FCST: Fuel Cell Simulation Toolbox
4 //
5 // Copyright (C) 2013 by Energy Systems Design Laboratory, University of Alberta
6 //
7 // This software is distributed under the MIT License.
8 // For more information, see the README file in /doc/LICENSE
9 //
10 // - Description: Logging objects to be used throughout fcst
11 // - Developers: Philip Wardlaw
12 // - $Id: fcst_utilities.h 2605 2014-08-15 03:36:44Z secanell $
13 //
14 //---------------------------------------------------------------------------
15 
16 #include <base/logstream.h>
17 #include <base/utilities.h>
18 
19 using namespace dealii;
20 
21 #ifndef _FCST_LOGGING
22 #define _FCST_LOGGING
23 
24 namespace FcstUtilities
25 {
26  // Needed to declare extern file below
27  class FCSTLogStream;
32  extern FCSTLogStream log;
33 
50  {
51  public:
57  FCSTLogStream (std::ostream &stream);
58 
62  ~FCSTLogStream();
63 
74  void attach (std::ostream &o,
75  const bool print_job_id = true);
76 
77 
83  void detach ();
84 
95  /*void test_mode (bool on=true)
96  {
97  // internal_log.test_mode(on);
98  }
99  */
100 
104  /*
105  std::ostream &get_console ()
106  {
107  // return internal_log.get_console();
108  }
109  */
110 
111 
115  std::ostream &get_file_stream ()
116  {
117  // return internal_log.get_file_stream();
118  }
119 
120 
124  bool has_file () const
125  {
126  return (file != 0);
127  }
128 
136  void push (const std::string &text)
137  {
138 
139  }
140 
141 
145  void pop ()
146  {
147 
148  }
149 
150 
159  unsigned int depth_console (const unsigned int n)
160  {
161  //return internal_log.depth_console(n);
162  }
163 
164 
173  unsigned int depth_file (const unsigned int n)
174  {}
175 
184  template <typename T>
185  const FCSTLogStream &
186  operator << (const T &t) const;
187 
202  const FCSTLogStream &
203  operator<< (std::ostream& (*p) (std::ostream &)) const;
204 
212  //std::size_t memory_consumption () const;
213 
214  private:
219  std::ostream& output_stream;
220 
227  std::ostream *file;
228  };
229 
230 
231  // --------------------------- inline and template functions -----------
232  template <class T>
233  inline const FCSTLogStream &
234  FCSTLogStream::operator<< (const T &t) const
235  {
236  // #ifdef OPENFCST_WITH_PETSC
237  if (Utilities::MPI::this_mpi_process(MPI_COMM_WORLD) == 0)
238  // #endif
239  {
240  // Print to screen
241  output_stream<<t;
242 
243  // and to file
244  if (has_file() )
245  *file<<t;
246  }
247 
248  return *this;
249  }
250 
251  //----
252  inline const FCSTLogStream &
253  FCSTLogStream::operator<< (std::ostream& (*p) (std::ostream &)) const
254  {
255  // #ifdef OPENFCST_WITH_PETSC
256  if (Utilities::MPI::this_mpi_process(MPI_COMM_WORLD) == 0)
257  // #endif
258  {
259  output_stream<<p;
260 
261  // and to file
262  if (has_file() )
263  *file<<p;
264  }
265 
266  return *this;
267  }
268 
269 }
270 
271 #endif //_FCST_LOGGING
unsigned int depth_console(const unsigned int n)
Maximum number of levels to be printed on the console.
Definition: logging.h:159
void pop()
Remove the last prefix added with push().
Definition: logging.h:145
bool has_file() const
Definition: logging.h:124
unsigned int depth_file(const unsigned int n)
Maximum number of levels to be written to the log file.
Definition: logging.h:173
std::ostream & output_stream
Determine an estimate for the memory consumption (in bytes) of this object.
Definition: logging.h:219
std::ostream & get_file_stream()
Setup the logstream for regression test mode.
Definition: logging.h:115
FCSTLogStream log
Object used to output data to file and, if file attached recorded to a file as well.
The object FcstUtilities::log should be used throughout OpenFCST for console logging.
Definition: logging.h:49
void push(const std::string &text)
Push another prefix on the stack.
Definition: logging.h:136
std::ostream * file
Pointer to a stream, where a copy of the output is to go to.
Definition: logging.h:227