https://mooseframework.inl.gov
Loading...
Searching...
No Matches
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
17class Logger
18{
19public:
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;
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:
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
78protected:
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};
Simple data structure to hold the messages.
Definition Logger.h:83
EMessageType _type
The type of the message.
Definition Logger.h:92
Message(EMessageType type, const std::string &msg)
Definition Logger.h:85
std::string _msg
The text of the message.
Definition Logger.h:94
Keeps the error and warning messages.
Definition Logger.h:18
unsigned int _n_warnings
The number of warnings.
Definition Logger.h:100
void add(EMessageType type, Args &&... args)
Add a message to the log.
Definition Logger.h:35
void emitLoggedErrors() const
Calls mooseError if there are any logged errors.
Definition Logger.C:21
std::vector< Message * > _msgs
The list of logged messages.
Definition Logger.h:102
unsigned int _n_errors
The number of errors.
Definition Logger.h:98
EMessageType
Definition Logger.h:24
@ ERROR
Definition Logger.h:25
@ WARNING
Definition Logger.h:26
Logger()
Definition Logger.C:12
unsigned int getNumberOfWarnings() const
Return the number of warnings.
Definition Logger.C:55
virtual ~Logger()
Definition Logger.C:14
void emitLoggedWarnings() const
Calls mooseWarning if there are any logged warnings.
Definition Logger.C:35
unsigned int getNumberOfErrors() const
Return the number of errors.
Definition Logger.C:49
void mooseStreamAll(std::ostringstream &ss)