PDI 1.4.3

the PDI data interface

logger.h
1 /*******************************************************************************
2  * Copyright (C) 2018-2021 Institute of Bioorganic Chemistry Polish Academy of Science (PSNC)
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions are met:
7  * * Redistributions of source code must retain the above copyright
8  * notice, this list of conditions and the following disclaimer.
9  * * Redistributions in binary form must reproduce the above copyright
10  * notice, this list of conditions and the following disclaimer in the
11  * documentation and/or other materials provided with the distribution.
12  * * Neither the name of CEA nor the names of its contributors may be used to
13  * endorse or promote products derived from this software without specific
14  * prior written permission.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22  * THE SOFTWARE.
23  ******************************************************************************/
24 
25 #ifndef PDI_LOGGER_H_
26 #define PDI_LOGGER_H_
27 
28 #include <utility>
29 #include <string>
30 #include <vector>
31 
32 #include <spdlog/logger.h>
33 #include <spdlog/spdlog.h>
34 
35 #include <pdi/pdi_fwd.h>
36 #include <pdi/paraconf_wrapper.h>
37 
38 namespace PDI {
39 
41 class PDI_EXPORT Logger
42 {
44  std::shared_ptr<spdlog::logger> m_logger;
45 
47  std::vector<std::reference_wrapper<Logger>> m_default_pattern_observers;
48 
50  std::string m_pattern = "[%T][%n] *** %^%l%$: %v";
51 
53  bool m_pattern_from_config = false;
54 
55 public:
57  Logger() = default;
58 
64  Logger(const std::string& logger_name, PC_tree_t config, spdlog::level::level_enum level = spdlog::level::info);
65 
71  Logger(Logger& parent_logger, const std::string& logger_name, PC_tree_t config);
72 
78  void setup(const std::string& logger_name, PC_tree_t config, spdlog::level::level_enum level = spdlog::level::info);
79 
85  void setup(Logger& parent_logger, const std::string& logger_name, PC_tree_t config);
86 
91  void pattern(const std::string& pattern);
92 
98  void default_pattern(const std::string& pattern);
99 
103  const std::string& pattern() const;
104 
108  void level(spdlog::level::level_enum log_level);
109 
113  spdlog::level::level_enum level() const;
114 
119  void evaluate_pattern(Context& ctx) const;
120 
125  template<typename... Args>
126  void trace(const char* fmt, Args&& ... args)
127  {
128  m_logger->trace(fmt, std::forward<Args>(args)...);
129  }
130 
135  template<typename... Args>
136  void debug(const char* fmt, Args&& ... args)
137  {
138  m_logger->debug(fmt, std::forward<Args>(args)...);
139  }
140 
145  template<typename... Args>
146  void info(const char* fmt, Args&& ... args)
147  {
148  m_logger->info(fmt, std::forward<Args>(args)...);
149  }
150 
155  template<typename... Args>
156  void warn(const char* fmt, Args&& ... args)
157  {
158  m_logger->warn(fmt, std::forward<Args>(args)...);
159  }
160 
165  template<typename... Args>
166  void error(const char* fmt, Args&& ... args)
167  {
168  m_logger->error(fmt, std::forward<Args>(args)...);
169  }
170 
174  std::shared_ptr<spdlog::logger> real_logger();
175 
176 };
177 
178 } // namespace PDI
179 
180 #endif // PDI_LOGGER_H_
Definition: context.h:44
Wrapper for spdlog::logger with additional pattern getter method.
Definition: logger.h:41
void info(const char *fmt, Args &&... args)
Writes info level message.
Definition: logger.h:146
void error(const char *fmt, Args &&... args)
Writes error level message.
Definition: logger.h:166
void debug(const char *fmt, Args &&... args)
Writes debug level message.
Definition: logger.h:136
Definition: array_datatype.h:37
void warn(const char *fmt, Args &&... args)
Writes warning level message.
Definition: logger.h:156
void trace(const char *fmt, Args &&... args)
Writes trace level message.
Definition: logger.h:126