You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
spdlog/include/spdlog/sinks/base_sink.h

48 lines
1.1 KiB
C

9 years ago
//
// Copyright(c) 2015 Gabi Melman.
// Distributed under the MIT License (http://opensource.org/licenses/MIT)
//
#pragma once
//
// base sink templated over a mutex (either dummy or real)
// concrete implementation should only override the _sink_it method.
9 years ago
// all locking is taken care of here so no locking needed by the implementers..
9 years ago
//
#include "spdlog/common.h"
#include "spdlog/details/log_msg.h"
#include "spdlog/formatter.h"
#include "spdlog/sinks/sink.h"
9 years ago
8 years ago
namespace spdlog {
namespace sinks {
8 years ago
template<class Mutex>
class base_sink : public sink
9 years ago
{
public:
base_sink() = default;
9 years ago
8 years ago
base_sink(const base_sink &) = delete;
base_sink &operator=(const base_sink &) = delete;
9 years ago
8 years ago
void log(const details::log_msg &msg) SPDLOG_FINAL override
9 years ago
{
std::lock_guard<Mutex> lock(_mutex);
_sink_it(msg);
}
void flush() SPDLOG_FINAL override
{
std::lock_guard<Mutex> lock(_mutex);
_flush();
}
9 years ago
protected:
8 years ago
virtual void _sink_it(const details::log_msg &msg) = 0;
virtual void _flush() = 0;
9 years ago
Mutex _mutex;
};
8 years ago
} // namespace sinks
} // namespace spdlog