The MAUVE Toolchain
logger.hpp
1 /*
2  * Copyright 2017 ONERA
3  *
4  * This file is part of the MAUVE Runtime project.
5  *
6  * MAUVE Runtime is free software: you can redistribute it and/or modify
7  * it under the terms of the GNU Lesser General Public License version 3 as
8  * published by the Free Software Foundation.
9  *
10  * MAUVE Runtime is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public License
16  * along with MAUVE. If not, see <https://www.gnu.org/licenses/lgpl-3.0>.
17  */
18 #ifndef MAUVE_RUNTIME_LOGGER_HPP
19 #define MAUVE_RUNTIME_LOGGER_HPP
20 
21 #include <iostream>
22 
23 #include "spdlog/spdlog.h"
24 #include "spdlog/fmt/bundled/ostream.h"
25 
26 namespace YAML {
27  class Node;
28 }
29 
30 namespace mauve {
31  namespace runtime {
32 
33  class AbstractComponent;
34  class AbstractResource;
35 
40  public:
43 
45  virtual ~AbstractLogger();
46 
50  static void initialize();
51 
56  static void initialize(std::istream& is);
57 
62  static void initialize(const std::string& s);
63 
68  static void initialize(const YAML::Node& n);
69 
73  static void clear();
74 
81  static AbstractLogger* get_logger(const std::string& name);
82 
89  template <typename... Args>
90  void trace(const char* fmt, const Args&... args);
91 
98  template <typename... Args>
99  void debug(const char* fmt, const Args&... args);
100 
107  template <typename... Args>
108  void info(const char* fmt, const Args&... args);
109 
116  template <typename... Args>
117  void warn(const char* fmt, const Args&... args);
118 
125  template <typename... Args>
126  void error(const char* fmt, const Args&... args);
127 
134  template <typename... Args>
135  void critical(const char* fmt, const Args&... args);
136 
137  protected:
141  static std::map<std::string,
142  std::vector< std::shared_ptr<spdlog::logger> > > loggers;
146  static std::shared_ptr<spdlog::logger> default_logger_;
152  virtual std::string prepend(const char* fmt) = 0;
157  virtual std::string name() = 0;
163  static spdlog::level::level_enum level_enum(const std::string& lvl);
164 
165  };
166 
170  class CategoryLogger final : public AbstractLogger {
171  public:
177  CategoryLogger(const std::string& name);
178  protected:
179  std::string prepend(const char* fmt) override;
180  std::string name() override;
181  private:
182  std::string name_;
183  };
184 
188  class ComponentLogger final : public AbstractLogger {
189  public:
195  protected:
196  std::string prepend(const char* fmt) override;
197  std::string name() override;
198  private:
202  AbstractComponent* component_;
203  std::string status();
204  };
205 
209  class ResourceLogger final : public AbstractLogger {
210  public:
215  ResourceLogger(AbstractResource* resource);
216  protected:
217  std::string prepend(const char* fmt) override;
218  std::string name() override;
219  private:
223  AbstractResource* resource_;
224  std::string status();
225  };
226 
230  class DeployerLogger final : public AbstractLogger {
231  public:
232  DeployerLogger();
233  protected:
234  std::string name() override;
235  std::string prepend(const char* fmt) override;
236 
237  };
238 
239 }}
240 
241 #include "ipp/logger.ipp"
242 
243 #endif
Class of a MAUVE logger for the deployer.
Definition: logger.hpp:230
Class of a MAUVE logger for a component.
Definition: logger.hpp:188
Class of a MAUVE logger for a custom category.
Definition: logger.hpp:170
static std::map< std::string, std::vector< std::shared_ptr< spdlog::logger > > > loggers
Store spdlog loggers associated to the categories.
Definition: logger.hpp:142
static std::shared_ptr< spdlog::logger > default_logger_
Default logger when no category specified.
Definition: logger.hpp:146
Class of a generic MAUVE logger.
Definition: logger.hpp:39
The MAUVE namespace.
Definition: tracing.hpp:24
Definition: factory.hpp:23
Abstract Resource class.
Definition: AbstractResource.hpp:37
Class of a MAUVE logger for a resrouce.
Definition: logger.hpp:209
Abstract Component class.
Definition: AbstractComponent.hpp:43