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()
18  : level_(level::trace)
20  {
21  }
22 
23  explicit sink(std::unique_ptr<spdlog::pattern_formatter> formatter)
24  : level_(level::trace)
25  , formatter_(std::move(formatter))
26  {
27  }
28 
29  virtual ~sink() = default;
30  virtual void log(const details::log_msg &msg) = 0;
31  virtual void flush() = 0;
32  virtual void set_pattern(const std::string &pattern) = 0;
33  virtual void set_formatter(std::unique_ptr<spdlog::formatter> sink_formatter) = 0;
34 
35  bool should_log(level::level_enum msg_level) const
36  {
37  return msg_level >= level_.load(std::memory_order_relaxed);
38  }
39 
40  void set_level(level::level_enum log_level)
41  {
42  level_.store(log_level);
43  }
44 
46  {
47  return static_cast<spdlog::level::level_enum>(level_.load(std::memory_order_relaxed));
48  }
49 
50 protected:
51  // sink log level - default is all
53 
54  // sink formatter - default is full format
55  std::unique_ptr<spdlog::formatter> formatter_;
56 };
57 
58 } // namespace sinks
59 } // namespace spdlog
virtual void set_pattern(const std::string &pattern)=0
bool should_log(level::level_enum msg_level) const
Definition: sink.h:35
void msg(const char *fmt,...)
Definition: message.cpp:107
std::string string
Definition: nybbler.cc:12
std::unique_ptr< spdlog::formatter > formatter_
Definition: sink.h:55
sink(std::unique_ptr< spdlog::pattern_formatter > formatter)
Definition: sink.h:23
STL namespace.
Definition: async.h:27
virtual void log(const details::log_msg &msg)=0
def move(depos, offset)
Definition: depos.py:107
virtual void flush()=0
level::level_enum level() const
Definition: sink.h:45
std::string pattern
Definition: regex_t.cc:33
virtual ~sink()=default
level_t level_
Definition: sink.h:52
void set_level(level::level_enum log_level)
Definition: sink.h:40
std::atomic< int > level_t
Definition: common.h:94
void trace(const char *fmt, const Args &...args)
Definition: spdlog.h:177
virtual void set_formatter(std::unique_ptr< spdlog::formatter > sink_formatter)=0