opm-common
LogBackend.hpp
1 /*
2  Copyright 2015, 2016 Statoil ASA.
3  Copyright 2016 SINTEF ICT, Applied Mathematics.
4 
5  This file is part of the Open Porous Media project (OPM).
6 
7  OPM is free software: you can redistribute it and/or modify
8  it under the terms of the GNU General Public License as published by
9  the Free Software Foundation, either version 3 of the License, or
10  (at your option) any later version.
11 
12  OPM is distributed in the hope that it will be useful,
13  but WITHOUT ANY WARRANTY; without even the implied warranty of
14  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  GNU General Public License for more details.
16 
17  You should have received a copy of the GNU General Public License
18  along with OPM. If not, see <http://www.gnu.org/licenses/>.
19  */
20 
21 
22 #ifndef OPM_LOGBACKEND_HPP
23 #define OPM_LOGBACKEND_HPP
24 
25 #include <opm/common/OpmLog/MessageFormatter.hpp>
26 #include <opm/common/OpmLog/MessageLimiter.hpp>
27 
28 #include <cstdint>
29 #include <memory>
30 #include <string>
31 
32 namespace Opm
33 {
34 
36  class LogBackend
37  {
38  public:
40  explicit LogBackend(std::int64_t mask);
41 
43  virtual ~LogBackend();
44 
46  void setMessageFormatter(std::shared_ptr<MessageFormatterInterface> formatter);
47 
49  void setMessageLimiter(std::shared_ptr<MessageLimiter> limiter);
50 
52  void addMessage(std::int64_t messageFlag, const std::string& message);
53 
55  void addTaggedMessage(std::int64_t messageFlag,
56  const std::string& messageTag,
57  const std::string& message);
58 
61  std::int64_t getMask() const;
62 
63  protected:
68  virtual void addMessageUnconditionally(std::int64_t messageFlag,
69  const std::string& message) = 0;
70 
72  std::string formatMessage(std::int64_t messageFlag, const std::string& message);
73 
74  private:
77  bool includeMessage(std::int64_t messageFlag, const std::string& messageTag);
78 
79  std::int64_t m_mask;
80  std::shared_ptr<MessageFormatterInterface> m_formatter;
81  std::shared_ptr<MessageLimiter> m_limiter;
82  };
83 
84 } // namespace LogBackend
85 
86 
87 #endif
void addMessage(std::int64_t messageFlag, const std::string &message)
Add a message to the backend if accepted by the message limiter.
Definition: LogBackend.cpp:46
void addTaggedMessage(std::int64_t messageFlag, const std::string &messageTag, const std::string &message)
Add a tagged message to the backend if accepted by the message limiter.
Definition: LogBackend.cpp:52
virtual ~LogBackend()
Virtual destructor to enable inheritance.
Definition: LogBackend.cpp:32
LogBackend(std::int64_t mask)
Construct with given message mask.
Definition: LogBackend.cpp:27
std::int64_t getMask() const
The message mask types are specified in the Opm::Log::MessageType namespace, in file LogUtils...
Definition: LogBackend.cpp:58
void setMessageFormatter(std::shared_ptr< MessageFormatterInterface > formatter)
Configure how formatMessage() will modify message strings.
Definition: LogBackend.cpp:36
This class implements a small container which holds the transmissibility mulitpliers for all the face...
Definition: Exceptions.hpp:30
virtual void addMessageUnconditionally(std::int64_t messageFlag, const std::string &message)=0
This is the method subclasses should override.
Abstract interface class for log backends.
Definition: LogBackend.hpp:36
void setMessageLimiter(std::shared_ptr< MessageLimiter > limiter)
Configure how message tags will be used to limit messages.
Definition: LogBackend.cpp:41
std::string formatMessage(std::int64_t messageFlag, const std::string &message)
Return decorated version of message depending on configureDecoration() arguments. ...
Definition: LogBackend.cpp:90