spdlog/include/c11log/sinks/base_sink.h

44 lines
869 B
C
Raw Normal View History

2014-03-22 20:11:17 +08:00
#pragma once
2014-10-26 08:23:14 +08:00
//
// base sink templated over a mutex (either dummy or realy)
// concrete implementation should only overrid the _sink_it method.
// all locking is taken care of here so no locking needed by the implementors..
//
2014-03-22 20:11:17 +08:00
#include<string>
#include<mutex>
2014-03-22 20:11:17 +08:00
#include<atomic>
#include "./sink.h"
2014-03-22 20:11:17 +08:00
#include "../formatter.h"
2014-10-10 08:36:50 +08:00
#include "../common.h"
2014-03-29 00:03:24 +08:00
#include "../details/log_msg.h"
2014-03-22 20:11:17 +08:00
2014-03-22 20:11:17 +08:00
namespace c11log
{
namespace sinks
{
template<class Mutex>
2014-10-14 09:26:51 +08:00
class base_sink:public sink
2014-03-22 20:11:17 +08:00
{
public:
2014-10-11 02:17:26 +08:00
base_sink():_mutex() {}
2014-03-22 20:11:17 +08:00
virtual ~base_sink() = default;
base_sink(const base_sink&) = delete;
base_sink& operator=(const base_sink&) = delete;
2014-10-10 08:36:50 +08:00
void log(const details::log_msg& msg) override
2014-03-22 20:11:17 +08:00
{
2014-10-11 02:17:26 +08:00
std::lock_guard<Mutex> lock(_mutex);
_sink_it(msg);
2014-03-22 20:11:17 +08:00
};
protected:
2014-03-29 00:03:24 +08:00
virtual void _sink_it(const details::log_msg& msg) = 0;
Mutex _mutex;
2014-03-22 20:11:17 +08:00
};
}
}