https://mooseframework.inl.gov
Classes | Public Types | Public Member Functions | Protected Attributes | List of all members
Logger Class Reference

Keeps the error and warning messages. More...

#include <Logger.h>

Classes

class  Message
 Simple data structure to hold the messages. More...
 

Public Types

enum  EMessageType { ERROR = 0, WARNING = 1 }
 

Public Member Functions

 Logger ()
 
virtual ~Logger ()
 
template<typename... Args>
void add (EMessageType type, Args &&... args)
 Add a message to the log. More...
 
void emitLoggedErrors () const
 Calls mooseError if there are any logged errors. More...
 
void emitLoggedWarnings () const
 Calls mooseWarning if there are any logged warnings. More...
 
unsigned int getNumberOfErrors () const
 Return the number of errors. More...
 
unsigned int getNumberOfWarnings () const
 Return the number of warnings. More...
 

Protected Attributes

unsigned int _n_errors
 The number of errors. More...
 
unsigned int _n_warnings
 The number of warnings. More...
 
std::vector< Message * > _msgs
 The list of logged messages. More...
 

Detailed Description

Keeps the error and warning messages.

Definition at line 17 of file Logger.h.

Member Enumeration Documentation

◆ EMessageType

Enumerator
ERROR 
WARNING 

Definition at line 23 of file Logger.h.

24  {
25  ERROR = 0,
26  WARNING = 1
27  };

Constructor & Destructor Documentation

◆ Logger()

Logger::Logger ( )

Definition at line 12 of file Logger.C.

12 : _n_errors(0), _n_warnings(0) {}
unsigned int _n_errors
The number of errors.
Definition: Logger.h:98
unsigned int _n_warnings
The number of warnings.
Definition: Logger.h:100

◆ ~Logger()

Logger::~Logger ( )
virtual

Definition at line 14 of file Logger.C.

15 {
16  for (auto && it : _msgs)
17  delete it;
18 }
std::vector< Message * > _msgs
The list of logged messages.
Definition: Logger.h:102

Member Function Documentation

◆ add()

template<typename... Args>
void Logger::add ( EMessageType  type,
Args &&...  args 
)
inline

Add a message to the log.

Parameters
typeThe type of the message

Definition at line 35 of file Logger.h.

Referenced by LoggingInterface::logComponentError(), LoggingInterface::logComponentWarning(), LoggingInterface::logError(), and LoggingInterface::logWarning().

36  {
37  std::ostringstream oss;
38  moose::internal::mooseStreamAll(oss, args...);
39 
40  Logger::Message * msg = new Logger::Message(type, oss.str());
41  _msgs.push_back(msg);
42 
43  switch (type)
44  {
45  case ERROR:
46  _n_errors++;
47  break;
48  case WARNING:
49  _n_warnings++;
50  break;
51  }
52  }
void mooseStreamAll(std::ostringstream &ss)
unsigned int _n_errors
The number of errors.
Definition: Logger.h:98
Simple data structure to hold the messages.
Definition: Logger.h:82
std::vector< Message * > _msgs
The list of logged messages.
Definition: Logger.h:102
unsigned int _n_warnings
The number of warnings.
Definition: Logger.h:100

◆ emitLoggedErrors()

void Logger::emitLoggedErrors ( ) const

Calls mooseError if there are any logged errors.

Definition at line 21 of file Logger.C.

Referenced by Simulation::controlDataIntegrityCheck(), and Simulation::integrityCheck().

22 {
23  if (_n_errors > 0)
24  {
25  std::ostringstream oss;
26  oss << "The following errors were encountered:\n";
27  for (const auto & msg_it : _msgs)
28  if (msg_it->_type == ERROR)
29  oss << " - " << msg_it->_msg << "\n";
30  mooseError(oss.str());
31  }
32 }
void mooseError(Args &&... args)
unsigned int _n_errors
The number of errors.
Definition: Logger.h:98
std::vector< Message * > _msgs
The list of logged messages.
Definition: Logger.h:102

◆ emitLoggedWarnings()

void Logger::emitLoggedWarnings ( ) const

Calls mooseWarning if there are any logged warnings.

Definition at line 35 of file Logger.C.

Referenced by Simulation::integrityCheck().

36 {
37  if (_n_warnings > 0)
38  {
39  std::ostringstream oss;
40  oss << "The following warnings were encountered:\n";
41  for (const auto & msg_it : _msgs)
42  if (msg_it->_type == WARNING)
43  oss << " - " << msg_it->_msg << "\n";
44  mooseWarning(oss.str());
45  }
46 }
void mooseWarning(Args &&... args)
std::vector< Message * > _msgs
The list of logged messages.
Definition: Logger.h:102
unsigned int _n_warnings
The number of warnings.
Definition: Logger.h:100

◆ getNumberOfErrors()

unsigned int Logger::getNumberOfErrors ( ) const

Return the number of errors.

Returns
The number of errors in this log

Definition at line 49 of file Logger.C.

50 {
51  return _n_errors;
52 }
unsigned int _n_errors
The number of errors.
Definition: Logger.h:98

◆ getNumberOfWarnings()

unsigned int Logger::getNumberOfWarnings ( ) const

Return the number of warnings.

Returns
The number of warnings in this log

Definition at line 55 of file Logger.C.

56 {
57  return _n_warnings;
58 }
unsigned int _n_warnings
The number of warnings.
Definition: Logger.h:100

Member Data Documentation

◆ _msgs

std::vector<Message *> Logger::_msgs
protected

The list of logged messages.

Definition at line 102 of file Logger.h.

Referenced by add(), emitLoggedErrors(), emitLoggedWarnings(), and ~Logger().

◆ _n_errors

unsigned int Logger::_n_errors
protected

The number of errors.

Definition at line 98 of file Logger.h.

Referenced by add(), emitLoggedErrors(), and getNumberOfErrors().

◆ _n_warnings

unsigned int Logger::_n_warnings
protected

The number of warnings.

Definition at line 100 of file Logger.h.

Referenced by add(), emitLoggedWarnings(), and getNumberOfWarnings().


The documentation for this class was generated from the following files: