2019-06-03 17:09:16 -04:00
|
|
|
// Copyright(c) 2015-present, Gabi Melman & spdlog contributors.
|
2019-05-11 13:06:17 -04:00
|
|
|
// Distributed under the MIT License (http://opensource.org/licenses/MIT)
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
2019-05-12 17:09:00 -04:00
|
|
|
#ifndef SPDLOG_HEADER_ONLY
|
|
|
|
#include "spdlog/sinks/base_sink.h"
|
|
|
|
#endif
|
|
|
|
|
2019-05-08 10:50:23 -04:00
|
|
|
#include "spdlog/common.h"
|
|
|
|
#include "spdlog/details/pattern_formatter.h"
|
|
|
|
|
2019-06-27 16:56:37 -04:00
|
|
|
#include <memory>
|
|
|
|
|
|
|
|
template<typename Mutex>
|
|
|
|
SPDLOG_INLINE spdlog::sinks::base_sink<Mutex>::base_sink()
|
|
|
|
: formatter_{details::make_unique<spdlog::pattern_formatter>()}
|
|
|
|
{}
|
|
|
|
|
|
|
|
template<typename Mutex>
|
|
|
|
SPDLOG_INLINE spdlog::sinks::base_sink<Mutex>::base_sink(std::unique_ptr<spdlog::formatter> formatter)
|
|
|
|
: formatter_{std::move(formatter)}
|
|
|
|
{}
|
|
|
|
|
2019-05-10 11:48:03 -04:00
|
|
|
template<typename Mutex>
|
2019-05-08 10:50:23 -04:00
|
|
|
void SPDLOG_INLINE spdlog::sinks::base_sink<Mutex>::log(const details::log_msg &msg)
|
|
|
|
{
|
|
|
|
std::lock_guard<Mutex> lock(mutex_);
|
|
|
|
sink_it_(msg);
|
|
|
|
}
|
|
|
|
|
2019-05-10 11:48:03 -04:00
|
|
|
template<typename Mutex>
|
2019-05-08 10:50:23 -04:00
|
|
|
void SPDLOG_INLINE spdlog::sinks::base_sink<Mutex>::flush()
|
|
|
|
{
|
|
|
|
std::lock_guard<Mutex> lock(mutex_);
|
|
|
|
flush_();
|
|
|
|
}
|
|
|
|
|
2019-05-10 11:48:03 -04:00
|
|
|
template<typename Mutex>
|
2019-05-08 10:50:23 -04:00
|
|
|
void SPDLOG_INLINE spdlog::sinks::base_sink<Mutex>::set_pattern(const std::string &pattern)
|
|
|
|
{
|
|
|
|
std::lock_guard<Mutex> lock(mutex_);
|
|
|
|
set_pattern_(pattern);
|
|
|
|
}
|
|
|
|
|
2019-05-10 11:48:03 -04:00
|
|
|
template<typename Mutex>
|
2019-05-08 10:50:23 -04:00
|
|
|
void SPDLOG_INLINE spdlog::sinks::base_sink<Mutex>::set_formatter(std::unique_ptr<spdlog::formatter> sink_formatter)
|
|
|
|
{
|
|
|
|
std::lock_guard<Mutex> lock(mutex_);
|
|
|
|
set_formatter_(std::move(sink_formatter));
|
|
|
|
}
|
|
|
|
|
2019-05-10 11:48:03 -04:00
|
|
|
template<typename Mutex>
|
2019-05-08 10:50:23 -04:00
|
|
|
void SPDLOG_INLINE spdlog::sinks::base_sink<Mutex>::set_pattern_(const std::string &pattern)
|
|
|
|
{
|
|
|
|
set_formatter_(details::make_unique<spdlog::pattern_formatter>(pattern));
|
|
|
|
}
|
|
|
|
|
2019-05-10 11:48:03 -04:00
|
|
|
template<typename Mutex>
|
2019-05-08 10:50:23 -04:00
|
|
|
void SPDLOG_INLINE spdlog::sinks::base_sink<Mutex>::set_formatter_(std::unique_ptr<spdlog::formatter> sink_formatter)
|
|
|
|
{
|
|
|
|
formatter_ = std::move(sink_formatter);
|
|
|
|
}
|