Files
spdlog/include/spdlog/sinks/base_sink.h

48 lines
1.1 KiB
C
Raw Normal View History

2016-04-20 11:57:49 +03:00
//
// Copyright(c) 2015 Gabi Melman.
// Distributed under the MIT License (http://opensource.org/licenses/MIT)
//
#pragma once
//
2017-04-06 20:16:49 -04:00
// base sink templated over a mutex (either dummy or real)
// concrete implementation should only override the _sink_it method.
2016-08-01 00:38:59 +03:00
// all locking is taken care of here so no locking needed by the implementers..
2016-04-20 11:57:49 +03:00
//
2018-04-29 01:31:09 +03:00
#include "spdlog/common.h"
#include "spdlog/details/log_msg.h"
#include "spdlog/formatter.h"
#include "spdlog/sinks/sink.h"
2016-04-20 11:57:49 +03:00
2018-03-17 12:47:46 +02:00
namespace spdlog {
namespace sinks {
2018-03-16 17:35:56 +02:00
template<class Mutex>
class base_sink : public sink
2016-04-20 11:57:49 +03:00
{
public:
2018-02-25 02:43:26 +01:00
base_sink() = default;
2016-04-20 11:57:49 +03:00
2018-03-09 15:26:33 +02:00
base_sink(const base_sink &) = delete;
base_sink &operator=(const base_sink &) = delete;
2016-04-20 11:57:49 +03:00
2018-03-09 15:26:33 +02:00
void log(const details::log_msg &msg) SPDLOG_FINAL override
2016-04-20 11:57:49 +03:00
{
std::lock_guard<Mutex> lock(_mutex);
_sink_it(msg);
}
2018-02-24 23:56:56 +01:00
void flush() SPDLOG_FINAL override
{
2017-12-02 17:06:59 +02:00
std::lock_guard<Mutex> lock(_mutex);
_flush();
}
2016-04-20 11:57:49 +03:00
protected:
2018-03-09 15:26:33 +02:00
virtual void _sink_it(const details::log_msg &msg) = 0;
virtual void _flush() = 0;
2016-04-20 11:57:49 +03:00
Mutex _mutex;
};
2018-03-17 12:47:46 +02:00
} // namespace sinks
} // namespace spdlog