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 realy) 9 // concrete implementation should only overrid the _sink_it method. 10 // all locking is taken care of here so no locking needed by the implementers.. 11 // 12 13 #include <spdlog/sinks/sink.h> 14 #include <spdlog/formatter.h> 15 #include <spdlog/common.h> 16 #include <spdlog/details/log_msg.h> 17 18 #include <mutex> 19 20 namespace spdlog 21 { 22 namespace sinks 23 { 24 template<class Mutex> 25 class base_sink:public sink 26 { 27 public: base_sink()28 base_sink():_mutex() {} 29 virtual ~base_sink() = default; 30 31 base_sink(const base_sink&) = delete; 32 base_sink& operator=(const base_sink&) = delete; 33 log(const details::log_msg & msg)34 void log(const details::log_msg& msg) override 35 { 36 std::lock_guard<Mutex> lock(_mutex); 37 _sink_it(msg); 38 } 39 40 protected: 41 virtual void _sink_it(const details::log_msg& msg) = 0; 42 Mutex _mutex; 43 }; 44 } 45 } 46