Livox SDK API  V2.2.0
sink.h
Go to the documentation of this file.
1 //
2 // Copyright(c) 2015 Gabi Melman.
3 // Distributed under the MIT License (http://opensource.org/licenses/MIT)
4 //
5 
6 #pragma once
7 
10 #include "spdlog/formatter.h"
11 
12 namespace spdlog {
13 namespace sinks {
14 class sink
15 {
16 public:
17  sink() = default;
18 
19  explicit sink(std::unique_ptr<spdlog::formatter> formatter)
20  : formatter_{std::move(formatter)}
21  {
22  }
23 
24  virtual ~sink() = default;
25  virtual void log(const details::log_msg &msg) = 0;
26  virtual void flush() = 0;
27  virtual void set_pattern(const std::string &pattern) = 0;
28  virtual void set_formatter(std::unique_ptr<spdlog::formatter> sink_formatter) = 0;
29 
30  bool should_log(level::level_enum msg_level) const
31  {
32  return msg_level >= level_.load(std::memory_order_relaxed);
33  }
34 
35  void set_level(level::level_enum log_level)
36  {
37  level_.store(log_level);
38  }
39 
41  {
42  return static_cast<spdlog::level::level_enum>(level_.load(std::memory_order_relaxed));
43  }
44 
45 protected:
46  // sink log level - default is all
48 
49  // sink formatter - default is full format
50  std::unique_ptr<spdlog::formatter> formatter_{details::make_unique<spdlog::pattern_formatter>()};
51 };
52 
53 } // namespace sinks
54 } // namespace spdlog
virtual void set_pattern(const std::string &pattern)=0
sink(std::unique_ptr< spdlog::formatter > formatter)
Definition: sink.h:19
bool should_log(level::level_enum msg_level) const
Definition: sink.h:30
std::unique_ptr< spdlog::formatter > formatter_
Definition: sink.h:50
Definition: async.h:27
virtual void log(const details::log_msg &msg)=0
virtual void flush()=0
level::level_enum level() const
Definition: sink.h:40
virtual ~sink()=default
level_t level_
Definition: sink.h:47
void set_level(level::level_enum log_level)
Definition: sink.h:35
std::atomic< int > level_t
Definition: common.h:94
virtual void set_formatter(std::unique_ptr< spdlog::formatter > sink_formatter)=0