https://mooseframework.inl.gov
Logger.h
Go to the documentation of this file.
1 //* This file is part of the MOOSE framework
2 //* https://mooseframework.inl.gov
3 //*
4 //* All rights reserved, see COPYRIGHT for full restrictions
5 //* https://github.com/idaholab/moose/blob/master/COPYRIGHT
6 //*
7 //* Licensed under LGPL 2.1, please see LICENSE for details
8 //* https://www.gnu.org/licenses/lgpl-2.1.html
9 
10 #pragma once
11 
12 #include "MooseError.h"
13 
17 class Logger
18 {
19 public:
20  Logger();
21  virtual ~Logger();
22 
24  {
25  ERROR = 0,
26  WARNING = 1
27  };
28 
34  template <typename... Args>
35  void add(EMessageType type, Args &&... args)
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  }
53 
57  void emitLoggedErrors() const;
58 
62  void emitLoggedWarnings() const;
63 
69  unsigned int getNumberOfErrors() const;
70 
76  unsigned int getNumberOfWarnings() const;
77 
78 protected:
82  class Message
83  {
84  public:
85  Message(EMessageType type, const std::string & msg)
86  {
87  _type = type;
88  _msg = msg;
89  }
90 
94  std::string _msg;
95  };
96 
98  unsigned int _n_errors;
100  unsigned int _n_warnings;
102  std::vector<Message *> _msgs;
103 };
Keeps the error and warning messages.
Definition: Logger.h:17
void mooseStreamAll(std::ostringstream &ss)
virtual ~Logger()
Definition: Logger.C:14
void emitLoggedErrors() const
Calls mooseError if there are any logged errors.
Definition: Logger.C:21
unsigned int getNumberOfWarnings() const
Return the number of warnings.
Definition: Logger.C:55
unsigned int _n_errors
The number of errors.
Definition: Logger.h:98
Logger()
Definition: Logger.C:12
EMessageType
Definition: Logger.h:23
Simple data structure to hold the messages.
Definition: Logger.h:82
EMessageType _type
The type of the message.
Definition: Logger.h:92
void emitLoggedWarnings() const
Calls mooseWarning if there are any logged warnings.
Definition: Logger.C:35
Message(EMessageType type, const std::string &msg)
Definition: Logger.h:85
std::vector< Message * > _msgs
The list of logged messages.
Definition: Logger.h:102
unsigned int getNumberOfErrors() const
Return the number of errors.
Definition: Logger.C:49
std::string _msg
The text of the message.
Definition: Logger.h:94
void add(EMessageType type, Args &&... args)
Add a message to the log.
Definition: Logger.h:35
unsigned int _n_warnings
The number of warnings.
Definition: Logger.h:100