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 <opm/common/OpmLog/Logger.hpp>
24 #include <opm/common/OpmLog/LogUtil.hpp>
25 
26 #include <cstdint>
27 #include <memory>
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 class OpmLog {
42 
43 public:
44  constexpr static int defaultDebugVerbosityLevel = 1;
45 
46  static void addMessage(std::int64_t messageFlag , const std::string& message);
47  static void addTaggedMessage(std::int64_t messageFlag, const std::string& tag, const std::string& message);
48 
49  static void info(const std::string& message);
50  static void warning(const std::string& message);
51  static void error(const std::string& message);
52  static void problem(const std::string& message);
53  static void bug(const std::string& message);
54  static void debug(const std::string& message, const int verbosity_level = defaultDebugVerbosityLevel);
55  static void note(const std::string& message);
56 
57  static void info(const std::string& tag, const std::string& message);
58  static void warning(const std::string& tag, const std::string& message);
59  static void error(const std::string& tag, const std::string& message);
60  static void problem(const std::string& tag, const std::string& message);
61  static void bug(const std::string& tag, const std::string& message);
62  static void debug(const std::string& tag, const std::string& message);
63  static void note(const std::string& tag, const std::string& message);
64 
65  static bool hasBackend( const std::string& backendName );
66  static void addBackend(const std::string& name , std::shared_ptr<LogBackend> backend);
67  static bool removeBackend(const std::string& name);
68  static void removeAllBackends();
69  static bool enabledMessageType( std::int64_t messageType );
70  static void addMessageType( std::int64_t messageType , const std::string& prefix);
71 
72  static int getDebugVerbosityLevel() { return debug_verbosity_level_; }
73  static void setDebugVerbosityLevel(const int verbosity_level) { debug_verbosity_level_ = verbosity_level; }
74 
81  static void setupSimpleDefaultLogging(const bool use_prefix = true,
82  const bool use_color_coding = true,
83  const int message_limit = 10);
84 
85  template <class BackendType>
86  static std::shared_ptr<BackendType> getBackend(const std::string& name) {
87  auto logger = getLogger();
88  return logger->getBackend<BackendType>(name);
89  }
90 
91  template <class BackendType>
92  static std::shared_ptr<BackendType> popBackend(const std::string& name) {
93  auto logger = getLogger();
94  return logger->popBackend<BackendType>(name);
95  }
96 
97  static bool stdoutIsTerminal();
98 
113  static bool setLogger(std::shared_ptr<Logger> logger);
114 
115 private:
116 #ifdef EMBEDDED_PYTHON
117  friend class PyRunModule;
118 #endif
119  static int debug_verbosity_level_;
120  static std::shared_ptr<Logger> getLogger();
121  static std::shared_ptr<Logger> m_logger;
122 };
123 
124 }
125 
126 #endif
static bool setLogger(std::shared_ptr< Logger > logger)
Sets the global logger instance for the OpmLog class.
Definition: OpmLog.cpp:60
This class implements a small container which holds the transmissibility mulitpliers for all the face...
Definition: Exceptions.hpp:30
Definition: OpmLog.hpp:41
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:197