KratosMultiphysics
KRATOS Multiphysics (Kratos) is a framework for building parallel, multi-disciplinary simulation software, aiming at modularity, extensibility, and high performance. Kratos is written in C++, and counts with an extensive Python interface.
logger_output.h
Go to the documentation of this file.
1 // | / |
2 // ' / __| _` | __| _ \ __|
3 // . \ | ( | | ( |\__ `
4 // _|\_\_| \__,_|\__|\___/ ____/
5 // Multi-Physics
6 //
7 // License: BSD License
8 // Kratos default license: kratos/license.txt
9 //
10 // Main authors: Pooyan Dadvand
11 //
12 //
13 
14 
15 #if !defined(KRATOS_LOGGER_OUTPUT_H_INCLUDED )
16 #define KRATOS_LOGGER_OUTPUT_H_INCLUDED
17 
18 
19 
20 // System includes
21 #include <string>
22 #include <iostream>
23 #include <map>
24 
25 
26 // External includes
27 
28 
29 // Project includes
30 #include "includes/define.h"
32 #include "containers/flags.h"
33 
34 namespace Kratos
35 {
38 
41 
43 
47 class KRATOS_API(KRATOS_CORE) LoggerOutput
48 {
49 public:
52 
53  KRATOS_DEFINE_LOCAL_FLAG(WARNING_PREFIX);
55  KRATOS_DEFINE_LOCAL_FLAG(DETAIL_PREFIX);
56  KRATOS_DEFINE_LOCAL_FLAG(DEBUG_PREFIX);
57  KRATOS_DEFINE_LOCAL_FLAG(TRACE_PREFIX);
58 
61 
65 
69 
70  explicit LoggerOutput(std::ostream& rOutputStream)
71  : mpStream(&rOutputStream),
72  mMaxLevel(1),
73  mSeverity(LoggerMessage::Severity::INFO),
74  mCategory(LoggerMessage::Category::STATUS)
75  {
76  mOptions.Set(WARNING_PREFIX, true);
77  mOptions.Set(INFO_PREFIX, false);
78  mOptions.Set(DETAIL_PREFIX, false);
79  mOptions.Set(DEBUG_PREFIX, false);
80  mOptions.Set(TRACE_PREFIX, false);
81  }
82 
83  LoggerOutput(LoggerOutput const& Other)
84  : mpStream(Other.mpStream), mMaxLevel(Other.mMaxLevel), mSeverity(Other.mSeverity), mCategory(Other.mCategory) {}
85 
87  virtual ~LoggerOutput() {}
88 
89 
93 
94  LoggerOutput& operator=(LoggerOutput const& Other) = delete;
95 
99 
100 
104 
105  virtual void WriteHeader();
106 
107  virtual void WriteMessage(LoggerMessage const& TheMessage);
108 
109  virtual void Flush();
110 
111  void SetMaxLevel(std::size_t TheLevel) {
112  mMaxLevel = TheLevel;
113  }
114 
115  std::size_t GetMaxLevel() const {
116  return mMaxLevel;
117  }
118 
119  void SetSeverity(LoggerMessage::Severity const& TheSeverity) {
120  mSeverity = TheSeverity;
121  }
122 
124  return mSeverity;
125  }
126 
127  void SetCategory(LoggerMessage::Category const& TheCategory) {
128  mCategory = TheCategory;
129  }
130 
132  return mCategory;
133  }
134 
135  void SetOption(const Kratos::Flags ThisFlag, bool Value) {
136  mOptions.Set(ThisFlag, Value);
137  }
138 
139  bool GetOption(const Kratos::Flags ThisFlag) {
140  return mOptions.Is(ThisFlag);
141  }
142 
146 
150 
152  virtual std::string Info() const;
153 
155  virtual void PrintInfo(std::ostream& rOStream) const;
156 
158  virtual void PrintData(std::ostream& rOStream) const;
159 
160 
162  template<class StreamValueType>
163  LoggerOutput& operator << (StreamValueType const& rValue)
164  {
165  std::stringstream buffer;
166  buffer << rValue;
167 
168  GetStream() << buffer.str();
169 
170  return *this;
171  }
172 
174  LoggerOutput& operator << (std::ostream& (*pf)(std::ostream&));
175 
177  LoggerOutput& operator << (const char * rString);
178 
179 
180 
182 protected:
183 
185  : mpStream(nullptr),
186  mMaxLevel(1),
187  mSeverity(LoggerMessage::Severity::INFO),
188  mCategory(LoggerMessage::Category::STATUS)
189  {
190  mOptions.Set(WARNING_PREFIX, true);
191  mOptions.Set(INFO_PREFIX, false);
192  mOptions.Set(DETAIL_PREFIX, false);
193  mOptions.Set(DEBUG_PREFIX, false);
194  mOptions.Set(TRACE_PREFIX, false);
195  }
196 
197  std::ostream& GetStream() {return *mpStream;}
198  std::ostream* pGetStream() {return mpStream;}
199  void SetStream(std::ostream* pStream) {mpStream = pStream;}
200 
201  virtual void SetMessageColor(LoggerMessage::Severity MessageSeverity);
202  virtual void ResetMessageColor(LoggerMessage::Severity MessageSeverity);
203 
204 private:
207 
211 
212  std::ostream* mpStream;
213  std::size_t mMaxLevel;
214  LoggerMessage::Severity mSeverity;
215  LoggerMessage::Category mCategory;
216  Kratos::Flags mOptions;
217 
219 }; // Class LoggerOutput
220 
222 
225 
227 std::ostream& operator << (std::ostream& rOStream,
228  const LoggerOutput& rThis);
229 
233 
234 
236 
238 } // namespace Kratos.
239 
240 #endif // KRATOS_LOGGER_OUTPUT_H_INCLUDED defined
std::string Info() const override
Turn back information as a string.
Definition: periodic_interface_process.hpp:93
Definition: flags.h:58
LoggerMessage class holdes message and the properties of the message.
Definition: logger_message.h:53
Severity
Definition: logger_message.h:64
Category
Definition: logger_message.h:72
LoggerOutput is the base class for all logger outputs.
Definition: logger_output.h:48
KRATOS_DEFINE_LOCAL_FLAG(INFO_PREFIX)
LoggerMessage::Category GetCategory() const
Definition: logger_output.h:131
virtual ~LoggerOutput()
Destructor.
Definition: logger_output.h:87
void SetCategory(LoggerMessage::Category const &TheCategory)
Definition: logger_output.h:127
KRATOS_DEFINE_LOCAL_FLAG(DEBUG_PREFIX)
LoggerMessage::Severity GetSeverity() const
Definition: logger_output.h:123
LoggerOutput()
Definition: logger_output.h:184
void SetOption(const Kratos::Flags ThisFlag, bool Value)
Definition: logger_output.h:135
KRATOS_DEFINE_LOCAL_FLAG(TRACE_PREFIX)
std::size_t GetMaxLevel() const
Definition: logger_output.h:115
KRATOS_DEFINE_LOCAL_FLAG(DETAIL_PREFIX)
LoggerOutput(LoggerOutput const &Other)
Definition: logger_output.h:83
std::ostream * pGetStream()
Definition: logger_output.h:198
bool GetOption(const Kratos::Flags ThisFlag)
Definition: logger_output.h:139
void SetSeverity(LoggerMessage::Severity const &TheSeverity)
Definition: logger_output.h:119
LoggerOutput & operator=(LoggerOutput const &Other)=delete
LoggerOutput(std::ostream &rOutputStream)
Definition: logger_output.h:70
std::ostream & GetStream()
Definition: logger_output.h:197
KRATOS_CLASS_POINTER_DEFINITION(LoggerOutput)
Pointer definition of LoggerOutput.
KRATOS_DEFINE_LOCAL_FLAG(WARNING_PREFIX)
void SetStream(std::ostream *pStream)
Definition: logger_output.h:199
void SetMaxLevel(std::size_t TheLevel)
Definition: logger_output.h:111
def Flush(a)
Definition: DEM_procedures.py:13
REF: G. R. Cowper, GAUSSIAN QUADRATURE FORMULAS FOR TRIANGLES.
Definition: mesh_condition.cpp:21
std::ostream & operator<<(std::ostream &rOStream, const LinearMasterSlaveConstraint &rThis)
output stream function
Definition: linear_master_slave_constraint.h:432