bitz-server  2.0.0
base_sink.h
1 //
2 // Copyright(c) 2015 Gabi Melman.
3 // Distributed under the MIT License (http://opensource.org/licenses/MIT)
4 //
5 
6 #pragma once
7 //
8 // base sink templated over a mutex (either dummy or real)
9 // concrete implementation should only override the _sink_it method.
10 // all locking is taken care of here so no locking needed by the implementers..
11 //
12 
13 #include "../common.h"
14 #include "../details/log_msg.h"
15 #include "../formatter.h"
16 #include "sink.h"
17 
18 #include <mutex>
19 
20 namespace spdlog {
21 namespace sinks {
22 template<class Mutex>
23 class base_sink : public sink
24 {
25 public:
26  base_sink() = default;
27 
28  base_sink(const base_sink &) = delete;
29  base_sink &operator=(const base_sink &) = delete;
30 
31  void log(const details::log_msg &msg) SPDLOG_FINAL override
32  {
33  std::lock_guard<Mutex> lock(_mutex);
34  _sink_it(msg);
35  }
36 
37  void flush() SPDLOG_FINAL override
38  {
39  std::lock_guard<Mutex> lock(_mutex);
40  _flush();
41  }
42 
43 protected:
44  virtual void _sink_it(const details::log_msg &msg) = 0;
45  virtual void _flush() = 0;
46  Mutex _mutex;
47 };
48 } // namespace sinks
49 } // namespace spdlog
Definition: async_logger.h:26
Definition: log_msg.h:16
Definition: step_file_sink.h:68
Definition: sink.h:12
Definition: base_sink.h:23