opm-common
OpmLog.hpp
1 /*
2  Copyright 2014 Statoil ASA.
3 
4  This file is part of the Open Porous Media project (OPM).
5 
6  OPM is free software: you can redistribute it and/or modify
7  it under the terms of the GNU General Public License as published by
8  the Free Software Foundation, either version 3 of the License, or
9  (at your option) any later version.
10 
11  OPM is distributed in the hope that it will be useful,
12  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  GNU General Public License for more details.
15 
16  You should have received a copy of the GNU General Public License
17  along with OPM. If not, see <http://www.gnu.org/licenses/>.
18 */
19 
20 #ifndef OPMLOG_HPP
21 #define OPMLOG_HPP
22 
23 #include <memory>
24 #include <cstdint>
25 
26 #include <opm/common/OpmLog/Logger.hpp>
27 #include <opm/common/OpmLog/LogUtil.hpp>
28 
29 namespace Opm {
30 
31  class LogBackend;
32 #ifdef EMBEDDED_PYTHON
33  class PyRunModule;
34 #endif
35 
36 /*
37  The OpmLog class is a fully static class which manages a proper
38  Logger instance.
39 */
40 
41 
42 class OpmLog {
43 
44 public:
45  constexpr static int defaultDebugVerbosityLevel = 1;
46 
47  static void addMessage(int64_t messageFlag , const std::string& message);
48  static void addTaggedMessage(int64_t messageFlag, const std::string& tag, const std::string& message);
49 
50  static void info(const std::string& message);
51  static void warning(const std::string& message);
52  static void error(const std::string& message);
53  static void problem(const std::string& message);
54  static void bug(const std::string& message);
55  static void debug(const std::string& message, const int verbosity_level = defaultDebugVerbosityLevel);
56  static void note(const std::string& message);
57 
58  static void info(const std::string& tag, const std::string& message);
59  static void warning(const std::string& tag, const std::string& message);
60  static void error(const std::string& tag, const std::string& message);
61  static void problem(const std::string& tag, const std::string& message);
62  static void bug(const std::string& tag, const std::string& message);
63  static void debug(const std::string& tag, const std::string& message);
64  static void note(const std::string& tag, const std::string& message);
65 
66  static bool hasBackend( const std::string& backendName );
67  static void addBackend(const std::string& name , std::shared_ptr<LogBackend> backend);
68  static bool removeBackend(const std::string& name);
69  static void removeAllBackends();
70  static bool enabledMessageType( int64_t messageType );
71  static void addMessageType( int64_t messageType , const std::string& prefix);
72 
73 
74  static int getDebugVerbosityLevel() { return debug_verbosity_level_; }
75  static void setDebugVerbosityLevel(const int verbosity_level) { debug_verbosity_level_ = verbosity_level; }
76 
83  static void setupSimpleDefaultLogging(const bool use_prefix = true,
84  const bool use_color_coding = true,
85  const int message_limit = 10);
86 
87  template <class BackendType>
88  static std::shared_ptr<BackendType> getBackend(const std::string& name) {
89  auto logger = getLogger();
90  return logger->getBackend<BackendType>(name);
91  }
92 
93  template <class BackendType>
94  static std::shared_ptr<BackendType> popBackend(const std::string& name) {
95  auto logger = getLogger();
96  return logger->popBackend<BackendType>(name);
97  }
98 
99 
100  static bool stdoutIsTerminal();
101 
116  static bool setLogger(std::shared_ptr<Logger> logger);
117 
118 private:
119 #ifdef EMBEDDED_PYTHON
120  friend class PyRunModule;
121 #endif
122  static int debug_verbosity_level_;
123  static std::shared_ptr<Logger> getLogger();
124  static std::shared_ptr<Logger> m_logger;
125 };
126 
127 
128 }
129 
130 
131 
132 
133 #endif
static bool setLogger(std::shared_ptr< Logger > logger)
Sets the global logger instance for the OpmLog class.
Definition: OpmLog.cpp:57
This class implements a small container which holds the transmissibility mulitpliers for all the face...
Definition: Exceptions.hpp:30
Definition: OpmLog.hpp:42
static void setupSimpleDefaultLogging(const bool use_prefix=true, const bool use_color_coding=true, const int message_limit=10)
Create a basic logging setup that will send all log messages to standard output.
Definition: OpmLog.cpp:221