mirror of
https://github.com/gabime/spdlog.git
synced 2025-10-02 03:19:02 +08:00
Clang format
This commit is contained in:
@@ -1,18 +1,16 @@
|
||||
// Copyright(c) 2015-present, Gabi Melman & spdlog contributors.
|
||||
// Distributed under the MIT License (http://opensource.org/licenses/MIT)
|
||||
|
||||
|
||||
#include <spdlog/sinks/ansicolor_sink.h>
|
||||
|
||||
#include <spdlog/pattern_formatter.h>
|
||||
#include <spdlog/details/os.h>
|
||||
|
||||
|
||||
namespace spdlog {
|
||||
namespace sinks {
|
||||
|
||||
template<typename ConsoleMutex>
|
||||
ansicolor_sink<ConsoleMutex>::ansicolor_sink(FILE *target_file, color_mode mode)
|
||||
ansicolor_sink<ConsoleMutex>::ansicolor_sink(FILE *target_file, color_mode mode)
|
||||
: target_file_(target_file)
|
||||
, mutex_(ConsoleMutex::mutex())
|
||||
, formatter_(std::make_unique<spdlog::pattern_formatter>())
|
||||
@@ -29,14 +27,14 @@ template<typename ConsoleMutex>
|
||||
}
|
||||
|
||||
template<typename ConsoleMutex>
|
||||
void ansicolor_sink<ConsoleMutex>::set_color(level color_level, string_view_t color)
|
||||
void ansicolor_sink<ConsoleMutex>::set_color(level color_level, string_view_t color)
|
||||
{
|
||||
std::lock_guard<mutex_t> lock(mutex_);
|
||||
colors_.at(level_to_number(color_level)) = to_string_(color);
|
||||
}
|
||||
|
||||
template<typename ConsoleMutex>
|
||||
void ansicolor_sink<ConsoleMutex>::log(const details::log_msg &msg)
|
||||
void ansicolor_sink<ConsoleMutex>::log(const details::log_msg &msg)
|
||||
{
|
||||
// Wrap the originally formatted message in color codes.
|
||||
// If color is not supported in the terminal, log as is instead.
|
||||
@@ -64,34 +62,34 @@ template<typename ConsoleMutex>
|
||||
}
|
||||
|
||||
template<typename ConsoleMutex>
|
||||
void ansicolor_sink<ConsoleMutex>::flush()
|
||||
void ansicolor_sink<ConsoleMutex>::flush()
|
||||
{
|
||||
std::lock_guard<mutex_t> lock(mutex_);
|
||||
fflush(target_file_);
|
||||
}
|
||||
|
||||
template<typename ConsoleMutex>
|
||||
void ansicolor_sink<ConsoleMutex>::set_pattern(const std::string &pattern)
|
||||
void ansicolor_sink<ConsoleMutex>::set_pattern(const std::string &pattern)
|
||||
{
|
||||
std::lock_guard<mutex_t> lock(mutex_);
|
||||
formatter_ = std::unique_ptr<spdlog::formatter>(new pattern_formatter(pattern));
|
||||
}
|
||||
|
||||
template<typename ConsoleMutex>
|
||||
void ansicolor_sink<ConsoleMutex>::set_formatter(std::unique_ptr<spdlog::formatter> sink_formatter)
|
||||
void ansicolor_sink<ConsoleMutex>::set_formatter(std::unique_ptr<spdlog::formatter> sink_formatter)
|
||||
{
|
||||
std::lock_guard<mutex_t> lock(mutex_);
|
||||
formatter_ = std::move(sink_formatter);
|
||||
}
|
||||
|
||||
template<typename ConsoleMutex>
|
||||
bool ansicolor_sink<ConsoleMutex>::should_color()
|
||||
bool ansicolor_sink<ConsoleMutex>::should_color()
|
||||
{
|
||||
return should_do_colors_;
|
||||
}
|
||||
|
||||
template<typename ConsoleMutex>
|
||||
void ansicolor_sink<ConsoleMutex>::set_color_mode(color_mode mode)
|
||||
void ansicolor_sink<ConsoleMutex>::set_color_mode(color_mode mode)
|
||||
{
|
||||
switch (mode)
|
||||
{
|
||||
@@ -110,32 +108,32 @@ template<typename ConsoleMutex>
|
||||
}
|
||||
|
||||
template<typename ConsoleMutex>
|
||||
void ansicolor_sink<ConsoleMutex>::print_ccode_(const string_view_t &color_code)
|
||||
void ansicolor_sink<ConsoleMutex>::print_ccode_(const string_view_t &color_code)
|
||||
{
|
||||
fwrite(color_code.data(), sizeof(char), color_code.size(), target_file_);
|
||||
}
|
||||
|
||||
template<typename ConsoleMutex>
|
||||
void ansicolor_sink<ConsoleMutex>::print_range_(const memory_buf_t &formatted, size_t start, size_t end)
|
||||
void ansicolor_sink<ConsoleMutex>::print_range_(const memory_buf_t &formatted, size_t start, size_t end)
|
||||
{
|
||||
fwrite(formatted.data() + start, sizeof(char), end - start, target_file_);
|
||||
}
|
||||
|
||||
template<typename ConsoleMutex>
|
||||
std::string ansicolor_sink<ConsoleMutex>::to_string_(const string_view_t &sv)
|
||||
std::string ansicolor_sink<ConsoleMutex>::to_string_(const string_view_t &sv)
|
||||
{
|
||||
return {sv.data(), sv.size()};
|
||||
}
|
||||
|
||||
// ansicolor_stdout_sink
|
||||
template<typename ConsoleMutex>
|
||||
ansicolor_stdout_sink<ConsoleMutex>::ansicolor_stdout_sink(color_mode mode)
|
||||
ansicolor_stdout_sink<ConsoleMutex>::ansicolor_stdout_sink(color_mode mode)
|
||||
: ansicolor_sink<ConsoleMutex>(stdout, mode)
|
||||
{}
|
||||
|
||||
// ansicolor_stderr_sink
|
||||
template<typename ConsoleMutex>
|
||||
ansicolor_stderr_sink<ConsoleMutex>::ansicolor_stderr_sink(color_mode mode)
|
||||
ansicolor_stderr_sink<ConsoleMutex>::ansicolor_stderr_sink(color_mode mode)
|
||||
: ansicolor_sink<ConsoleMutex>(stderr, mode)
|
||||
{}
|
||||
|
||||
|
@@ -1,8 +1,6 @@
|
||||
// Copyright(c) 2015-present, Gabi Melman & spdlog contributors.
|
||||
// Distributed under the MIT License (http://opensource.org/licenses/MIT)
|
||||
|
||||
|
||||
|
||||
#include <spdlog/sinks/base_sink.h>
|
||||
#include <spdlog/common.h>
|
||||
#include <spdlog/pattern_formatter.h>
|
||||
@@ -11,45 +9,45 @@
|
||||
#include <mutex>
|
||||
|
||||
template<typename Mutex>
|
||||
spdlog::sinks::base_sink<Mutex>::base_sink()
|
||||
spdlog::sinks::base_sink<Mutex>::base_sink()
|
||||
: formatter_{std::make_unique<spdlog::pattern_formatter>()}
|
||||
{}
|
||||
|
||||
template<typename Mutex>
|
||||
spdlog::sinks::base_sink<Mutex>::base_sink(std::unique_ptr<spdlog::formatter> formatter)
|
||||
spdlog::sinks::base_sink<Mutex>::base_sink(std::unique_ptr<spdlog::formatter> formatter)
|
||||
: formatter_{std::move(formatter)}
|
||||
{}
|
||||
|
||||
template<typename Mutex>
|
||||
void spdlog::sinks::base_sink<Mutex>::log(const details::log_msg &msg)
|
||||
void spdlog::sinks::base_sink<Mutex>::log(const details::log_msg &msg)
|
||||
{
|
||||
std::lock_guard<Mutex> lock(mutex_);
|
||||
sink_it_(msg);
|
||||
}
|
||||
|
||||
template<typename Mutex>
|
||||
void spdlog::sinks::base_sink<Mutex>::flush()
|
||||
void spdlog::sinks::base_sink<Mutex>::flush()
|
||||
{
|
||||
std::lock_guard<Mutex> lock(mutex_);
|
||||
flush_();
|
||||
}
|
||||
|
||||
template<typename Mutex>
|
||||
void spdlog::sinks::base_sink<Mutex>::set_pattern(const std::string &pattern)
|
||||
void spdlog::sinks::base_sink<Mutex>::set_pattern(const std::string &pattern)
|
||||
{
|
||||
std::lock_guard<Mutex> lock(mutex_);
|
||||
set_pattern_(pattern);
|
||||
}
|
||||
|
||||
template<typename Mutex>
|
||||
void spdlog::sinks::base_sink<Mutex>::set_formatter(std::unique_ptr<spdlog::formatter> sink_formatter)
|
||||
void 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));
|
||||
}
|
||||
|
||||
template<typename Mutex>
|
||||
void spdlog::sinks::base_sink<Mutex>::set_pattern_(const std::string &pattern)
|
||||
void spdlog::sinks::base_sink<Mutex>::set_pattern_(const std::string &pattern)
|
||||
{
|
||||
set_formatter_(std::make_unique<spdlog::pattern_formatter>(pattern));
|
||||
}
|
||||
|
@@ -10,20 +10,20 @@ namespace spdlog {
|
||||
namespace sinks {
|
||||
|
||||
template<typename Mutex>
|
||||
basic_file_sink<Mutex>::basic_file_sink(const filename_t &filename, bool truncate, const file_event_handlers &event_handlers)
|
||||
basic_file_sink<Mutex>::basic_file_sink(const filename_t &filename, bool truncate, const file_event_handlers &event_handlers)
|
||||
: file_helper_{event_handlers}
|
||||
{
|
||||
file_helper_.open(filename, truncate);
|
||||
}
|
||||
|
||||
template<typename Mutex>
|
||||
const filename_t &basic_file_sink<Mutex>::filename() const
|
||||
const filename_t &basic_file_sink<Mutex>::filename() const
|
||||
{
|
||||
return file_helper_.filename();
|
||||
}
|
||||
|
||||
template<typename Mutex>
|
||||
void basic_file_sink<Mutex>::sink_it_(const details::log_msg &msg)
|
||||
void basic_file_sink<Mutex>::sink_it_(const details::log_msg &msg)
|
||||
{
|
||||
memory_buf_t formatted;
|
||||
base_sink<Mutex>::formatter_->format(msg, formatted);
|
||||
@@ -31,7 +31,7 @@ template<typename Mutex>
|
||||
}
|
||||
|
||||
template<typename Mutex>
|
||||
void basic_file_sink<Mutex>::flush_()
|
||||
void basic_file_sink<Mutex>::flush_()
|
||||
{
|
||||
file_helper_.flush();
|
||||
}
|
||||
|
@@ -17,7 +17,7 @@ namespace spdlog {
|
||||
namespace sinks {
|
||||
|
||||
template<typename Mutex>
|
||||
rotating_file_sink<Mutex>::rotating_file_sink(
|
||||
rotating_file_sink<Mutex>::rotating_file_sink(
|
||||
filename_t base_filename, std::size_t max_size, std::size_t max_files, bool rotate_on_open, const file_event_handlers &event_handlers)
|
||||
: base_filename_(std::move(base_filename))
|
||||
, max_size_(max_size)
|
||||
@@ -45,7 +45,7 @@ template<typename Mutex>
|
||||
// calc filename according to index and file extension if exists.
|
||||
// e.g. calc_filename("logs/mylog.txt, 3) => "logs/mylog.3.txt".
|
||||
template<typename Mutex>
|
||||
filename_t rotating_file_sink<Mutex>::calc_filename(const filename_t &filename, std::size_t index)
|
||||
filename_t rotating_file_sink<Mutex>::calc_filename(const filename_t &filename, std::size_t index)
|
||||
{
|
||||
if (index == 0u)
|
||||
{
|
||||
@@ -58,14 +58,14 @@ template<typename Mutex>
|
||||
}
|
||||
|
||||
template<typename Mutex>
|
||||
filename_t rotating_file_sink<Mutex>::filename()
|
||||
filename_t rotating_file_sink<Mutex>::filename()
|
||||
{
|
||||
std::lock_guard<Mutex> lock(base_sink<Mutex>::mutex_);
|
||||
return file_helper_.filename();
|
||||
}
|
||||
|
||||
template<typename Mutex>
|
||||
void rotating_file_sink<Mutex>::sink_it_(const details::log_msg &msg)
|
||||
void rotating_file_sink<Mutex>::sink_it_(const details::log_msg &msg)
|
||||
{
|
||||
memory_buf_t formatted;
|
||||
base_sink<Mutex>::formatter_->format(msg, formatted);
|
||||
@@ -88,7 +88,7 @@ template<typename Mutex>
|
||||
}
|
||||
|
||||
template<typename Mutex>
|
||||
void rotating_file_sink<Mutex>::flush_()
|
||||
void rotating_file_sink<Mutex>::flush_()
|
||||
{
|
||||
file_helper_.flush();
|
||||
}
|
||||
@@ -99,7 +99,7 @@ template<typename Mutex>
|
||||
// log.2.txt -> log.3.txt
|
||||
// log.3.txt -> delete
|
||||
template<typename Mutex>
|
||||
void rotating_file_sink<Mutex>::rotate_()
|
||||
void rotating_file_sink<Mutex>::rotate_()
|
||||
{
|
||||
using details::os::filename_to_str;
|
||||
using details::os::path_exists;
|
||||
@@ -134,7 +134,7 @@ template<typename Mutex>
|
||||
// delete the target if exists, and rename the src file to target
|
||||
// return true on success, false otherwise.
|
||||
template<typename Mutex>
|
||||
bool rotating_file_sink<Mutex>::rename_file_(const filename_t &src_filename, const filename_t &target_filename)
|
||||
bool rotating_file_sink<Mutex>::rename_file_(const filename_t &src_filename, const filename_t &target_filename)
|
||||
{
|
||||
// try to delete the target file in case it already exists.
|
||||
(void)details::os::remove(target_filename);
|
||||
|
@@ -1,21 +1,21 @@
|
||||
// Copyright(c) 2015-present, Gabi Melman & spdlog contributors.
|
||||
// Distributed under the MIT License (http://opensource.org/licenses/MIT)
|
||||
|
||||
|
||||
#include <spdlog/sinks/sink.h>
|
||||
|
||||
#include <spdlog/common.h>
|
||||
|
||||
bool spdlog::sinks::sink::should_log(spdlog::level msg_level) const
|
||||
bool spdlog::sinks::sink::should_log(spdlog::level msg_level) const
|
||||
{
|
||||
return msg_level >= level_.load(std::memory_order_relaxed);
|
||||
}
|
||||
|
||||
void spdlog::sinks::sink::set_level(level level)
|
||||
void spdlog::sinks::sink::set_level(level level)
|
||||
{
|
||||
level_.store(level, std::memory_order_relaxed);
|
||||
}
|
||||
|
||||
spdlog::level spdlog::sinks::sink::log_level() const {
|
||||
spdlog::level spdlog::sinks::sink::log_level() const
|
||||
{
|
||||
return static_cast<spdlog::level>(level_.load(std::memory_order_relaxed));
|
||||
}
|
||||
|
@@ -9,50 +9,52 @@
|
||||
|
||||
namespace spdlog {
|
||||
|
||||
template<typename Factory>
|
||||
std::shared_ptr<logger> stdout_color_mt(const std::string &logger_name, color_mode mode) {
|
||||
return Factory::template create<sinks::stdout_color_sink_mt>(logger_name, mode);
|
||||
}
|
||||
template<typename Factory>
|
||||
std::shared_ptr<logger> stdout_color_mt(const std::string &logger_name, color_mode mode)
|
||||
{
|
||||
return Factory::template create<sinks::stdout_color_sink_mt>(logger_name, mode);
|
||||
}
|
||||
|
||||
template<typename Factory>
|
||||
std::shared_ptr<logger> stdout_color_st(const std::string &logger_name, color_mode mode) {
|
||||
return Factory::template create<sinks::stdout_color_sink_st>(logger_name, mode);
|
||||
}
|
||||
template<typename Factory>
|
||||
std::shared_ptr<logger> stdout_color_st(const std::string &logger_name, color_mode mode)
|
||||
{
|
||||
return Factory::template create<sinks::stdout_color_sink_st>(logger_name, mode);
|
||||
}
|
||||
|
||||
template<typename Factory>
|
||||
std::shared_ptr<logger> stderr_color_mt(const std::string &logger_name, color_mode mode) {
|
||||
return Factory::template create<sinks::stderr_color_sink_mt>(logger_name, mode);
|
||||
}
|
||||
template<typename Factory>
|
||||
std::shared_ptr<logger> stderr_color_mt(const std::string &logger_name, color_mode mode)
|
||||
{
|
||||
return Factory::template create<sinks::stderr_color_sink_mt>(logger_name, mode);
|
||||
}
|
||||
|
||||
template<typename Factory>
|
||||
std::shared_ptr<logger> stderr_color_st(const std::string &logger_name, color_mode mode) {
|
||||
return Factory::template create<sinks::stderr_color_sink_st>(logger_name, mode);
|
||||
}
|
||||
template<typename Factory>
|
||||
std::shared_ptr<logger> stderr_color_st(const std::string &logger_name, color_mode mode)
|
||||
{
|
||||
return Factory::template create<sinks::stderr_color_sink_st>(logger_name, mode);
|
||||
}
|
||||
} // namespace spdlog
|
||||
|
||||
// template instantiations
|
||||
template SPDLOG_API std::shared_ptr<spdlog::logger> spdlog::stdout_color_mt<spdlog::synchronous_factory>(
|
||||
const std::string &logger_name, color_mode mode);
|
||||
const std::string &logger_name, color_mode mode);
|
||||
|
||||
template SPDLOG_API std::shared_ptr<spdlog::logger> spdlog::stdout_color_st<spdlog::synchronous_factory>(
|
||||
const std::string &logger_name, color_mode mode);
|
||||
const std::string &logger_name, color_mode mode);
|
||||
|
||||
template SPDLOG_API std::shared_ptr<spdlog::logger> spdlog::stderr_color_mt<spdlog::synchronous_factory>(
|
||||
const std::string &logger_name, color_mode mode);
|
||||
const std::string &logger_name, color_mode mode);
|
||||
|
||||
template SPDLOG_API std::shared_ptr<spdlog::logger> spdlog::stderr_color_st<spdlog::synchronous_factory>(
|
||||
const std::string &logger_name, color_mode mode);
|
||||
const std::string &logger_name, color_mode mode);
|
||||
|
||||
template SPDLOG_API std::shared_ptr<spdlog::logger> spdlog::stdout_color_mt<spdlog::async_factory>(
|
||||
const std::string &logger_name, color_mode mode);
|
||||
const std::string &logger_name, color_mode mode);
|
||||
|
||||
template SPDLOG_API std::shared_ptr<spdlog::logger> spdlog::stdout_color_st<spdlog::async_factory>(
|
||||
const std::string &logger_name, color_mode mode);
|
||||
const std::string &logger_name, color_mode mode);
|
||||
|
||||
template SPDLOG_API std::shared_ptr<spdlog::logger> spdlog::stderr_color_mt<spdlog::async_factory>(
|
||||
const std::string &logger_name, color_mode mode);
|
||||
const std::string &logger_name, color_mode mode);
|
||||
|
||||
template SPDLOG_API std::shared_ptr<spdlog::logger> spdlog::stderr_color_st<spdlog::async_factory>(
|
||||
const std::string &logger_name, color_mode mode);
|
||||
|
||||
|
||||
const std::string &logger_name, color_mode mode);
|
||||
|
@@ -20,16 +20,16 @@
|
||||
|
||||
namespace spdlog {
|
||||
|
||||
namespace sinks {
|
||||
namespace sinks {
|
||||
|
||||
template<typename ConsoleMutex>
|
||||
stdout_sink_base<ConsoleMutex>::stdout_sink_base(FILE *file)
|
||||
: mutex_(ConsoleMutex::mutex())
|
||||
, file_(file)
|
||||
, formatter_(std::make_unique<spdlog::pattern_formatter>())
|
||||
{
|
||||
template<typename ConsoleMutex>
|
||||
stdout_sink_base<ConsoleMutex>::stdout_sink_base(FILE *file)
|
||||
: mutex_(ConsoleMutex::mutex())
|
||||
, file_(file)
|
||||
, formatter_(std::make_unique<spdlog::pattern_formatter>())
|
||||
{
|
||||
#ifdef _WIN32
|
||||
// get windows handle from the FILE* object
|
||||
// get windows handle from the FILE* object
|
||||
|
||||
handle_ = reinterpret_cast<HANDLE>(::_get_osfhandle(::_fileno(file_)));
|
||||
|
||||
@@ -41,13 +41,13 @@ namespace spdlog {
|
||||
throw_spdlog_ex("spdlog::stdout_sink_base: _get_osfhandle() failed", errno);
|
||||
}
|
||||
#endif // WIN32
|
||||
}
|
||||
}
|
||||
|
||||
template<typename ConsoleMutex>
|
||||
void stdout_sink_base<ConsoleMutex>::log(const details::log_msg &msg)
|
||||
{
|
||||
template<typename ConsoleMutex>
|
||||
void stdout_sink_base<ConsoleMutex>::log(const details::log_msg &msg)
|
||||
{
|
||||
#ifdef _WIN32
|
||||
if (handle_ == INVALID_HANDLE_VALUE)
|
||||
if (handle_ == INVALID_HANDLE_VALUE)
|
||||
{
|
||||
return;
|
||||
}
|
||||
@@ -62,73 +62,73 @@ namespace spdlog {
|
||||
throw_spdlog_ex("stdout_sink_base: WriteFile() failed. GetLastError(): " + std::to_string(::GetLastError()));
|
||||
}
|
||||
#else
|
||||
std::lock_guard<mutex_t> lock(mutex_);
|
||||
memory_buf_t formatted;
|
||||
formatter_->format(msg, formatted);
|
||||
::fwrite(formatted.data(), sizeof(char), formatted.size(), file_);
|
||||
std::lock_guard<mutex_t> lock(mutex_);
|
||||
memory_buf_t formatted;
|
||||
formatter_->format(msg, formatted);
|
||||
::fwrite(formatted.data(), sizeof(char), formatted.size(), file_);
|
||||
#endif // WIN32
|
||||
::fflush(file_); // flush every line to terminal
|
||||
}
|
||||
::fflush(file_); // flush every line to terminal
|
||||
}
|
||||
|
||||
template<typename ConsoleMutex>
|
||||
void stdout_sink_base<ConsoleMutex>::flush()
|
||||
{
|
||||
std::lock_guard<mutex_t> lock(mutex_);
|
||||
fflush(file_);
|
||||
}
|
||||
template<typename ConsoleMutex>
|
||||
void stdout_sink_base<ConsoleMutex>::flush()
|
||||
{
|
||||
std::lock_guard<mutex_t> lock(mutex_);
|
||||
fflush(file_);
|
||||
}
|
||||
|
||||
template<typename ConsoleMutex>
|
||||
void stdout_sink_base<ConsoleMutex>::set_pattern(const std::string &pattern)
|
||||
{
|
||||
std::lock_guard<mutex_t> lock(mutex_);
|
||||
formatter_ = std::unique_ptr<spdlog::formatter>(new pattern_formatter(pattern));
|
||||
}
|
||||
template<typename ConsoleMutex>
|
||||
void stdout_sink_base<ConsoleMutex>::set_pattern(const std::string &pattern)
|
||||
{
|
||||
std::lock_guard<mutex_t> lock(mutex_);
|
||||
formatter_ = std::unique_ptr<spdlog::formatter>(new pattern_formatter(pattern));
|
||||
}
|
||||
|
||||
template<typename ConsoleMutex>
|
||||
void stdout_sink_base<ConsoleMutex>::set_formatter(std::unique_ptr<spdlog::formatter> sink_formatter)
|
||||
{
|
||||
std::lock_guard<mutex_t> lock(mutex_);
|
||||
formatter_ = std::move(sink_formatter);
|
||||
}
|
||||
template<typename ConsoleMutex>
|
||||
void stdout_sink_base<ConsoleMutex>::set_formatter(std::unique_ptr<spdlog::formatter> sink_formatter)
|
||||
{
|
||||
std::lock_guard<mutex_t> lock(mutex_);
|
||||
formatter_ = std::move(sink_formatter);
|
||||
}
|
||||
|
||||
// stdout sink
|
||||
template<typename ConsoleMutex>
|
||||
stdout_sink<ConsoleMutex>::stdout_sink()
|
||||
: stdout_sink_base<ConsoleMutex>(stdout)
|
||||
{}
|
||||
template<typename ConsoleMutex>
|
||||
stdout_sink<ConsoleMutex>::stdout_sink()
|
||||
: stdout_sink_base<ConsoleMutex>(stdout)
|
||||
{}
|
||||
|
||||
// stderr sink
|
||||
template<typename ConsoleMutex>
|
||||
stderr_sink<ConsoleMutex>::stderr_sink()
|
||||
: stdout_sink_base<ConsoleMutex>(stderr)
|
||||
{}
|
||||
template<typename ConsoleMutex>
|
||||
stderr_sink<ConsoleMutex>::stderr_sink()
|
||||
: stdout_sink_base<ConsoleMutex>(stderr)
|
||||
{}
|
||||
|
||||
} // namespace sinks
|
||||
} // namespace sinks
|
||||
|
||||
// factory methods
|
||||
template<typename Factory>
|
||||
std::shared_ptr<logger> stdout_logger_mt(const std::string &logger_name)
|
||||
{
|
||||
return Factory::template create<sinks::stdout_sink_mt>(logger_name);
|
||||
}
|
||||
template<typename Factory>
|
||||
std::shared_ptr<logger> stdout_logger_mt(const std::string &logger_name)
|
||||
{
|
||||
return Factory::template create<sinks::stdout_sink_mt>(logger_name);
|
||||
}
|
||||
|
||||
template<typename Factory>
|
||||
std::shared_ptr<logger> stdout_logger_st(const std::string &logger_name)
|
||||
{
|
||||
return Factory::template create<sinks::stdout_sink_st>(logger_name);
|
||||
}
|
||||
template<typename Factory>
|
||||
std::shared_ptr<logger> stdout_logger_st(const std::string &logger_name)
|
||||
{
|
||||
return Factory::template create<sinks::stdout_sink_st>(logger_name);
|
||||
}
|
||||
|
||||
template<typename Factory>
|
||||
std::shared_ptr<logger> stderr_logger_mt(const std::string &logger_name)
|
||||
{
|
||||
return Factory::template create<sinks::stderr_sink_mt>(logger_name);
|
||||
}
|
||||
template<typename Factory>
|
||||
std::shared_ptr<logger> stderr_logger_mt(const std::string &logger_name)
|
||||
{
|
||||
return Factory::template create<sinks::stderr_sink_mt>(logger_name);
|
||||
}
|
||||
|
||||
template<typename Factory>
|
||||
std::shared_ptr<logger> stderr_logger_st(const std::string &logger_name)
|
||||
{
|
||||
return Factory::template create<sinks::stderr_sink_st>(logger_name);
|
||||
}
|
||||
template<typename Factory>
|
||||
std::shared_ptr<logger> stderr_logger_st(const std::string &logger_name)
|
||||
{
|
||||
return Factory::template create<sinks::stderr_sink_st>(logger_name);
|
||||
}
|
||||
} // namespace spdlog
|
||||
|
||||
// template instantiations for stdout/stderr loggers
|
||||
@@ -153,5 +153,3 @@ template SPDLOG_API std::shared_ptr<spdlog::logger> spdlog::stdout_logger_mt<spd
|
||||
template SPDLOG_API std::shared_ptr<spdlog::logger> spdlog::stdout_logger_st<spdlog::async_factory>(const std::string &logger_name);
|
||||
template SPDLOG_API std::shared_ptr<spdlog::logger> spdlog::stderr_logger_mt<spdlog::async_factory>(const std::string &logger_name);
|
||||
template SPDLOG_API std::shared_ptr<spdlog::logger> spdlog::stderr_logger_st<spdlog::async_factory>(const std::string &logger_name);
|
||||
|
||||
|
||||
|
@@ -2,20 +2,20 @@
|
||||
// Distributed under the MIT License (http://opensource.org/licenses/MIT)
|
||||
#ifdef _WIN32
|
||||
|
||||
#pragma once
|
||||
# pragma once
|
||||
|
||||
#include <spdlog/sinks/wincolor_sink.h>
|
||||
# include <spdlog/sinks/wincolor_sink.h>
|
||||
|
||||
#include <spdlog/details/windows_include.h>
|
||||
#include <wincon.h>
|
||||
# include <spdlog/details/windows_include.h>
|
||||
# include <wincon.h>
|
||||
|
||||
#include <spdlog/common.h>
|
||||
#include <spdlog/pattern_formatter.h>
|
||||
# include <spdlog/common.h>
|
||||
# include <spdlog/pattern_formatter.h>
|
||||
|
||||
namespace spdlog {
|
||||
namespace sinks {
|
||||
template<typename ConsoleMutex>
|
||||
wincolor_sink<ConsoleMutex>::wincolor_sink(void *out_handle, color_mode mode)
|
||||
wincolor_sink<ConsoleMutex>::wincolor_sink(void *out_handle, color_mode mode)
|
||||
: out_handle_(out_handle)
|
||||
, mutex_(ConsoleMutex::mutex())
|
||||
, formatter_(std::make_unique<spdlog::pattern_formatter>())
|
||||
@@ -24,7 +24,7 @@ template<typename ConsoleMutex>
|
||||
set_color_mode_impl(mode);
|
||||
// set level colors
|
||||
colors_.at(level_to_number(level::trace)) = FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE; // white
|
||||
colors_.at(level_to_number(level::debug)) = FOREGROUND_GREEN | FOREGROUND_BLUE; // cyan
|
||||
colors_.at(level_to_number(level::debug)) = FOREGROUND_GREEN | FOREGROUND_BLUE; // cyan
|
||||
colors_.at(level_to_number(level::info)) = FOREGROUND_GREEN; // green
|
||||
colors_.at(level_to_number(level::warn)) = FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_INTENSITY; // intense yellow
|
||||
colors_.at(level_to_number(level::err)) = FOREGROUND_RED | FOREGROUND_INTENSITY; // intense red
|
||||
@@ -34,21 +34,21 @@ template<typename ConsoleMutex>
|
||||
}
|
||||
|
||||
template<typename ConsoleMutex>
|
||||
wincolor_sink<ConsoleMutex>::~wincolor_sink()
|
||||
wincolor_sink<ConsoleMutex>::~wincolor_sink()
|
||||
{
|
||||
this->flush();
|
||||
}
|
||||
|
||||
// change the color for the given level
|
||||
template<typename ConsoleMutex>
|
||||
void wincolor_sink<ConsoleMutex>::set_color(level level, std::uint16_t color)
|
||||
void wincolor_sink<ConsoleMutex>::set_color(level level, std::uint16_t color)
|
||||
{
|
||||
std::lock_guard<mutex_t> lock(mutex_);
|
||||
colors_[level_to_number(level)] = color;
|
||||
}
|
||||
|
||||
template<typename ConsoleMutex>
|
||||
void wincolor_sink<ConsoleMutex>::log(const details::log_msg &msg)
|
||||
void wincolor_sink<ConsoleMutex>::log(const details::log_msg &msg)
|
||||
{
|
||||
if (out_handle_ == nullptr || out_handle_ == INVALID_HANDLE_VALUE)
|
||||
{
|
||||
@@ -78,34 +78,34 @@ void wincolor_sink<ConsoleMutex>::log(const details::log_msg &msg)
|
||||
}
|
||||
|
||||
template<typename ConsoleMutex>
|
||||
void wincolor_sink<ConsoleMutex>::flush()
|
||||
void wincolor_sink<ConsoleMutex>::flush()
|
||||
{
|
||||
// windows console always flushed?
|
||||
}
|
||||
|
||||
template<typename ConsoleMutex>
|
||||
void wincolor_sink<ConsoleMutex>::set_pattern(const std::string &pattern)
|
||||
void wincolor_sink<ConsoleMutex>::set_pattern(const std::string &pattern)
|
||||
{
|
||||
std::lock_guard<mutex_t> lock(mutex_);
|
||||
formatter_ = std::unique_ptr<spdlog::formatter>(new pattern_formatter(pattern));
|
||||
}
|
||||
|
||||
template<typename ConsoleMutex>
|
||||
void wincolor_sink<ConsoleMutex>::set_formatter(std::unique_ptr<spdlog::formatter> sink_formatter)
|
||||
void wincolor_sink<ConsoleMutex>::set_formatter(std::unique_ptr<spdlog::formatter> sink_formatter)
|
||||
{
|
||||
std::lock_guard<mutex_t> lock(mutex_);
|
||||
formatter_ = std::move(sink_formatter);
|
||||
}
|
||||
|
||||
template<typename ConsoleMutex>
|
||||
void wincolor_sink<ConsoleMutex>::set_color_mode(color_mode mode)
|
||||
void wincolor_sink<ConsoleMutex>::set_color_mode(color_mode mode)
|
||||
{
|
||||
std::lock_guard<mutex_t> lock(mutex_);
|
||||
set_color_mode_impl(mode);
|
||||
}
|
||||
|
||||
template<typename ConsoleMutex>
|
||||
void wincolor_sink<ConsoleMutex>::set_color_mode_impl(color_mode mode)
|
||||
void wincolor_sink<ConsoleMutex>::set_color_mode_impl(color_mode mode)
|
||||
{
|
||||
if (mode == color_mode::automatic)
|
||||
{
|
||||
@@ -122,7 +122,7 @@ void wincolor_sink<ConsoleMutex>::set_color_mode_impl(color_mode mode)
|
||||
|
||||
// set foreground color and return the orig console attributes (for resetting later)
|
||||
template<typename ConsoleMutex>
|
||||
std::uint16_t wincolor_sink<ConsoleMutex>::set_foreground_color_(std::uint16_t attribs)
|
||||
std::uint16_t wincolor_sink<ConsoleMutex>::set_foreground_color_(std::uint16_t attribs)
|
||||
{
|
||||
CONSOLE_SCREEN_BUFFER_INFO orig_buffer_info;
|
||||
if (!::GetConsoleScreenBufferInfo(static_cast<HANDLE>(out_handle_), &orig_buffer_info))
|
||||
@@ -140,7 +140,7 @@ std::uint16_t wincolor_sink<ConsoleMutex>::set_foreground_color_(std::uint16_t
|
||||
|
||||
// print a range of formatted message to console
|
||||
template<typename ConsoleMutex>
|
||||
void wincolor_sink<ConsoleMutex>::print_range_(const memory_buf_t &formatted, size_t start, size_t end)
|
||||
void wincolor_sink<ConsoleMutex>::print_range_(const memory_buf_t &formatted, size_t start, size_t end)
|
||||
{
|
||||
if (end > start)
|
||||
{
|
||||
@@ -151,7 +151,7 @@ void wincolor_sink<ConsoleMutex>::print_range_(const memory_buf_t &formatted, s
|
||||
}
|
||||
|
||||
template<typename ConsoleMutex>
|
||||
void wincolor_sink<ConsoleMutex>::write_to_file_(const memory_buf_t &formatted)
|
||||
void wincolor_sink<ConsoleMutex>::write_to_file_(const memory_buf_t &formatted)
|
||||
{
|
||||
auto size = static_cast<DWORD>(formatted.size());
|
||||
DWORD bytes_written = 0;
|
||||
@@ -161,19 +161,18 @@ void wincolor_sink<ConsoleMutex>::write_to_file_(const memory_buf_t &formatted)
|
||||
|
||||
// wincolor_stdout_sink
|
||||
template<typename ConsoleMutex>
|
||||
wincolor_stdout_sink<ConsoleMutex>::wincolor_stdout_sink(color_mode mode)
|
||||
wincolor_stdout_sink<ConsoleMutex>::wincolor_stdout_sink(color_mode mode)
|
||||
: wincolor_sink<ConsoleMutex>(::GetStdHandle(STD_OUTPUT_HANDLE), mode)
|
||||
{}
|
||||
|
||||
// wincolor_stderr_sink
|
||||
template<typename ConsoleMutex>
|
||||
wincolor_stderr_sink<ConsoleMutex>::wincolor_stderr_sink(color_mode mode)
|
||||
wincolor_stderr_sink<ConsoleMutex>::wincolor_stderr_sink(color_mode mode)
|
||||
: wincolor_sink<ConsoleMutex>(::GetStdHandle(STD_ERROR_HANDLE), mode)
|
||||
{}
|
||||
} // namespace sinks
|
||||
} // namespace spdlog
|
||||
|
||||
|
||||
// template instantiations
|
||||
template SPDLOG_API class spdlog::sinks::wincolor_stdout_sink<spdlog::details::console_mutex>;
|
||||
template SPDLOG_API class spdlog::sinks::wincolor_stdout_sink<spdlog::details::console_nullmutex>;
|
||||
|
Reference in New Issue
Block a user