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 //
13 //---------------------------------------------------------------------------
14 
15 #include <deal.II/base/logstream.h>
16 #include <deal.II/base/utilities.h>
17 
18 using namespace dealii;
19 
20 #ifndef _FCST_LOGGING
21 #define _FCST_LOGGING
22 
23 namespace FcstUtilities
24 {
25  // Needed to declare extern file below
26  class FCSTLogStream;
31  extern FCSTLogStream log;
32 
49  {
50  public:
56  FCSTLogStream (std::ostream &stream);
57 
61  ~FCSTLogStream();
62 
73  void attach (std::ostream &o,
74  const bool print_job_id = true);
75 
76 
82  void detach ();
83 
94  /*void test_mode (bool on=true)
95  {
96  // internal_log.test_mode(on);
97  }
98  */
99 
103  /*
104  std::ostream &get_console ()
105  {
106  // return internal_log.get_console();
107  }
108  */
109 
110 
114  std::ostream &get_file_stream ()
115  {
116  // return internal_log.get_file_stream();
117  }
118 
119 
123  bool has_file () const
124  {
125  return (file != 0);
126  }
127 
135  void push (const std::string &text)
136  {
137 
138  }
139 
140 
144  void pop ()
145  {
146 
147  }
148 
149 
158  unsigned int depth_console (const unsigned int n)
159  {
160  //return internal_log.depth_console(n);
161  }
162 
163 
172  unsigned int depth_file (const unsigned int n)
173  {}
174 
183  template <typename T>
184  const FCSTLogStream &
185  operator << (const T &t) const;
186 
201  const FCSTLogStream &
202  operator<< (std::ostream& (*p) (std::ostream &)) const;
203 
211  //std::size_t memory_consumption () const;
212 
213  private:
218  std::ostream& output_stream;
219 
226  std::ostream *file;
227  };
228 
229 
230  // --------------------------- inline and template functions -----------
231  template <class T>
232  inline const FCSTLogStream &
233  FCSTLogStream::operator<< (const T &t) const
234  {
235  // #ifdef OPENFCST_WITH_PETSC
236  if (Utilities::MPI::this_mpi_process(MPI_COMM_WORLD) == 0)
237  // #endif
238  {
239  // Print to screen
240  output_stream<<t;
241 
242  // and to file
243  if (has_file() )
244  *file<<t;
245  }
246 
247  return *this;
248  }
249 
250  //----
251  inline const FCSTLogStream &
252  FCSTLogStream::operator<< (std::ostream& (*p) (std::ostream &)) const
253  {
254  // #ifdef OPENFCST_WITH_PETSC
255  if (Utilities::MPI::this_mpi_process(MPI_COMM_WORLD) == 0)
256  // #endif
257  {
258  output_stream<<p;
259 
260  // and to file
261  if (has_file() )
262  *file<<p;
263  }
264 
265  return *this;
266  }
267 
268 }
269 
270 #endif //_FCST_LOGGING
unsigned int depth_console(const unsigned int n)
Maximum number of levels to be printed on the console.
Definition: logging.h:158
void pop()
Remove the last prefix added with push().
Definition: logging.h:144
bool has_file() const
Definition: logging.h:123
unsigned int depth_file(const unsigned int n)
Maximum number of levels to be written to the log file.
Definition: logging.h:172
std::ostream & output_stream
Determine an estimate for the memory consumption (in bytes) of this object.
Definition: logging.h:218
std::ostream & get_file_stream()
Setup the logstream for regression test mode.
Definition: logging.h:114
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:48
void push(const std::string &text)
Push another prefix on the stack.
Definition: logging.h:135
std::ostream * file
Pointer to a stream, where a copy of the output is to go to.
Definition: logging.h:226