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.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 // Carlos Roig
12 //
13 
14 
15 #if !defined(KRATOS_LOGGER_H_INCLUDED )
16 #define KRATOS_LOGGER_H_INCLUDED
17 
18 // System includes
19 #include <string>
20 #include <iostream>
21 
22 // Project includes
25 #include "includes/exception.h"
26 
27 
28 
29 namespace Kratos
30 {
33 
36 
40 
44 
48 
50 
56  class KRATOS_API(KRATOS_CORE) Logger
57  {
58  public:
61 
62  using LoggerOutputContainerType = std::vector<LoggerOutput::Pointer>;
66 
68 
70 
72 
76 
77  explicit Logger(std::string const& TheLabel);
78 
79  Logger();
80 
82  Logger(Logger const& rOther) = delete;
83 
84 
86  virtual ~Logger();
87 
88 
92 
94  Logger& operator=(Logger const& rOther) = delete;
95 
99 
100 
104 
106  {
107  static LoggerOutputContainerType instance;
108  return instance;
109  }
110 
112  {
113  static LoggerOutput defaultOutputInstance(std::cout);
114  return defaultOutputInstance;
115  }
116 
117  static void AddOutput(LoggerOutput::Pointer pTheOutput);
118 
119  static void RemoveOutput(LoggerOutput::Pointer pTheOutput);
120 
121  static void Flush();
122 
123 
127 
128  std::string const& GetCurrentMessage() {
129  return mCurrentMessage.GetMessage();
130  }
131 
135 
136 
140 
142  virtual std::string Info() const;
143 
145  virtual void PrintInfo(std::ostream& rOStream) const;
146 
148  virtual void PrintData(std::ostream& rOStream) const;
149 
150 
152  template<class StreamValueType>
153  Logger& operator << (StreamValueType const& rValue)
154  {
155  mCurrentMessage << rValue;
156 
157  return *this;
158  }
159 
161  Logger& operator << (std::ostream& (*pf)(std::ostream&));
162 
164  Logger& operator << (const char * rString);
165 
166  // Location stream function
167  Logger& operator << (CodeLocation const& TheLocation);
168 
170  Logger& operator << (Severity const& TheSeverity);
171 
173  Logger& operator << (Category const& TheCategory);
174 
175 
177  private:
180 
181 
185 
186  LoggerMessage mCurrentMessage;
187 
191 
192 
196 
197 
201 
202 
206 
207 
211 
212 
214 
215  }; // Class Logger
216 
218 
221 
222 
226 
227 
229  inline std::istream& operator >> (std::istream& rIStream,
230  Logger& rThis);
231 
233  inline std::ostream& operator << (std::ostream& rOStream,
234  const Logger& rThis)
235  {
236  rThis.PrintInfo(rOStream);
237  rOStream << std::endl;
238  rThis.PrintData(rOStream);
239 
240  return rOStream;
241  }
243 
246 // Each-N block
247 #define KRATOS_LOG_OCCURRENCES_LINE(line) kratos_log_loop_counter##line
248 #define KRATOS_LOG_OCCURRENCES KRATOS_LOG_OCCURRENCES_LINE(__LINE__)
249 
250 #define KRATOS_INFO(label) Kratos::Logger(label) << KRATOS_CODE_LOCATION << Kratos::Logger::Severity::INFO
251 #define KRATOS_INFO_IF(label, conditional) if(conditional) Kratos::Logger(label) << KRATOS_CODE_LOCATION << Kratos::Logger::Severity::INFO
252 #ifdef KRATOS_DEBUG
253  #define KRATOS_INFO_ONCE(label) static int KRATOS_LOG_OCCURRENCES = -1; if (++KRATOS_LOG_OCCURRENCES == 0) Kratos::Logger(label) << KRATOS_CODE_LOCATION << Kratos::Logger::Severity::INFO
254  #define KRATOS_INFO_FIRST_N(label, logger_count) static int KRATOS_LOG_OCCURRENCES = -1; if (++KRATOS_LOG_OCCURRENCES < logger_count) Kratos::Logger(label) << KRATOS_CODE_LOCATION << Kratos::Logger::Severity::INFO
255 #else
256  #define KRATOS_INFO_ONCE(label) if(false) KRATOS_INFO(label)
257  #define KRATOS_INFO_FIRST_N(label, logger_count) if(false) KRATOS_INFO(label)
258 #endif
259 
260 #define KRATOS_INFO_ALL_RANKS(label) KRATOS_INFO(label) << Kratos::Logger::DistributedFilter::FromAllRanks()
261 #define KRATOS_INFO_IF_ALL_RANKS(label, conditional) KRATOS_INFO_IF(label, conditional) << Kratos::Logger::DistributedFilter::FromAllRanks()
262 #define KRATOS_INFO_ONCE_ALL_RANKS(label) KRATOS_INFO_ONCE(label) << Kratos::Logger::DistributedFilter::FromAllRanks()
263 #define KRATOS_INFO_FIRST_N_ALL_RANKS(label, logger_count) KRATOS_INFO_FIRST_N(label, logger_count) << Kratos::Logger::DistributedFilter::FromAllRanks()
264 
265 #define KRATOS_WARNING(label) Kratos::Logger(label) << KRATOS_CODE_LOCATION << Kratos::Logger::Severity::WARNING
266 #define KRATOS_WARNING_IF(label, conditional) if(conditional) Kratos::Logger(label) << KRATOS_CODE_LOCATION << Kratos::Logger::Severity::WARNING
267 #ifdef KRATOS_DEBUG
268  #define KRATOS_WARNING_ONCE(label) static int KRATOS_LOG_OCCURRENCES = -1; if (++KRATOS_LOG_OCCURRENCES == 0) Kratos::Logger(label) << KRATOS_CODE_LOCATION << Kratos::Logger::Severity::WARNING
269  #define KRATOS_WARNING_FIRST_N(label, logger_count) static int KRATOS_LOG_OCCURRENCES = -1; if (++KRATOS_LOG_OCCURRENCES < logger_count) Kratos::Logger(label) << KRATOS_CODE_LOCATION << Kratos::Logger::Severity::WARNING
270 #else
271  #define KRATOS_WARNING_ONCE(label) if(false) KRATOS_WARNING(label)
272  #define KRATOS_WARNING_FIRST_N(label, logger_count) if(false) KRATOS_WARNING(label)
273 #endif
274 
275 #define KRATOS_WARNING_ALL_RANKS(label) KRATOS_WARNING(label) << Kratos::Logger::DistributedFilter::FromAllRanks()
276 #define KRATOS_WARNING_IF_ALL_RANKS(label, conditional) KRATOS_WARNING_IF(label, conditional) << Kratos::Logger::DistributedFilter::FromAllRanks()
277 #define KRATOS_WARNING_ONCE_ALL_RANKS(label) KRATOS_WARNING_ONCE(label) << Kratos::Logger::DistributedFilter::FromAllRanks()
278 #define KRATOS_WARNING_FIRST_N_ALL_RANKS(label, logger_count) KRATOS_WARNING_FIRST_N(label, logger_count) << Kratos::Logger::DistributedFilter::FromAllRanks()
279 
280 #define KRATOS_DETAIL(label) Kratos::Logger(label) << KRATOS_CODE_LOCATION << Kratos::Logger::Severity::DETAIL
281 #define KRATOS_DETAIL_IF(label, conditional) if(conditional) Kratos::Logger(label) << KRATOS_CODE_LOCATION << Kratos::Logger::Severity::DETAIL
282 #ifdef KRATOS_DEBUG
283  #define KRATOS_DETAIL_ONCE(label) static int KRATOS_LOG_OCCURRENCES = -1; if (++KRATOS_LOG_OCCURRENCES == 0) Kratos::Logger(label) << KRATOS_CODE_LOCATION << Kratos::Logger::Severity::DETAIL
284  #define KRATOS_DETAIL_FIRST_N(label, logger_count) static int KRATOS_LOG_OCCURRENCES = -1; if (++KRATOS_LOG_OCCURRENCES < logger_count) Kratos::Logger(label) << KRATOS_CODE_LOCATION << Kratos::Logger::Severity::DETAIL
285 #else
286  #define KRATOS_DETAIL_ONCE(label) if(false) KRATOS_DETAIL(label)
287  #define KRATOS_DETAIL_FIRST_N(label, logger_count) if(false) KRATOS_DETAIL(label)
288 #endif
289 
290 #define KRATOS_DETAIL_ALL_RANKS(label) KRATOS_DETAIL(label) << Kratos::Logger::DistributedFilter::FromAllRanks()
291 #define KRATOS_DETAIL_IF_ALL_RANKS(label, conditional) KRATOS_DETAIL_IF(label, conditional) << Kratos::Logger::DistributedFilter::FromAllRanks()
292 #define KRATOS_DETAIL_ONCE_ALL_RANKS(label) KRATOS_DETAIL_ONCE(label) << Kratos::Logger::DistributedFilter::FromAllRanks()
293 #define KRATOS_DETAIL_FIRST_N_ALL_RANKS(label, logger_count) KRATOS_DETAIL_FIRST_N(label, logger_count) << Kratos::Logger::DistributedFilter::FromAllRanks()
294 
295 #ifdef KRATOS_DEBUG
296 #define KRATOS_TRACE(label) Kratos::Logger(label) << KRATOS_CODE_LOCATION << Kratos::Logger::Severity::TRACE
297 #define KRATOS_TRACE_IF(label, conditional) if(conditional) Kratos::Logger(label) << KRATOS_CODE_LOCATION << Kratos::Logger::Severity::TRACE
298 #define KRATOS_TRACE_ONCE(label) static int KRATOS_LOG_OCCURRENCES = -1; if (++KRATOS_LOG_OCCURRENCES == 0) Kratos::Logger(label) << KRATOS_CODE_LOCATION << Kratos::Logger::Severity::TRACE
299 #define KRATOS_TRACE_FIRST_N(label, logger_count) static int KRATOS_LOG_OCCURRENCES = -1; if (++KRATOS_LOG_OCCURRENCES < logger_count) Kratos::Logger(label) << KRATOS_CODE_LOCATION << Kratos::Logger::Severity::TRACE
300 #else
301 #define KRATOS_TRACE(label) if(false) KRATOS_WARNING(label)
302 #define KRATOS_TRACE_IF(label, conditional) if(false) KRATOS_WARNING(label)
303 #define KRATOS_TRACE_ONCE(label) if(false) KRATOS_WARNING(label)
304 #define KRATOS_TRACE_FIRST_N(label, logger_count) if(false) KRATOS_WARNING(label)
305 #endif
306 
307 #define KRATOS_TRACE_ALL_RANKS(label) KRATOS_TRACE(label) << Kratos::Logger::DistributedFilter::FromAllRanks()
308 #define KRATOS_TRACE_IF_ALL_RANKS(label, conditional) KRATOS_TRACE_IF(label, conditional) << Kratos::Logger::DistributedFilter::FromAllRanks()
309 #define KRATOS_TRACE_ONCE_ALL_RANKS(label) KRATOS_TRACE_ONCE(label) << Kratos::Logger::DistributedFilter::FromAllRanks()
310 #define KRATOS_TRACE_FIRST_N_ALL_RANKS(label, logger_count) KRATOS_TRACE_FIRST_N(label, logger_count) << Kratos::Logger::DistributedFilter::FromAllRanks()
311 
312 #if defined(KRATOS_ENABLE_CHECK_POINT)
313 #define KRATOS_CHECK_POINT(label) Kratos::Logger(label) << Kratos::Logger::Category::CHECKING
314 #else
315 #define KRATOS_CHECK_POINT(label) \
316  if (false) \
317  Kratos::Logger(label) << Kratos::Logger::Category::CHECKING
318 #endif
320 
322 
323 } // namespace Kratos.
324 
325 #endif // KRATOS_LOGGER_H_INCLUDED defined
326 
327 
std::string Info() const override
Turn back information as a string.
Definition: periodic_interface_process.hpp:93
Definition: code_location.h:31
Logger is in charge of writing the messages to output streams.
Definition: logger.h:57
virtual void PrintData(std::ostream &rOStream) const
Print object's data.
Definition: logger.cpp:86
std::string const & GetCurrentMessage()
Definition: logger.h:128
std::vector< LoggerOutput::Pointer > LoggerOutputContainerType
Definition: logger.h:62
Logger(Logger const &rOther)=delete
Avoiding Logger to be copied.
static LoggerOutput & GetDefaultOutputInstance()
Definition: logger.h:111
Logger & operator=(Logger const &rOther)=delete
Loggers can not be assigned.
virtual void PrintInfo(std::ostream &rOStream) const
Print information about this object.
Definition: logger.cpp:82
static LoggerOutputContainerType & GetOutputsInstance()
Definition: logger.h:105
Definition: logger_message.h:80
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
def Flush(a)
Definition: DEM_procedures.py:13
REF: G. R. Cowper, GAUSSIAN QUADRATURE FORMULAS FOR TRIANGLES.
Definition: mesh_condition.cpp:21
std::istream & operator>>(std::istream &rIStream, LinearMasterSlaveConstraint &rThis)
input stream function
std::ostream & operator<<(std::ostream &rOStream, const LinearMasterSlaveConstraint &rThis)
output stream function
Definition: linear_master_slave_constraint.h:432