mirror of
https://github.com/gabime/spdlog.git
synced 2024-12-25 01:51:38 +08:00
Clang format
This commit is contained in:
parent
5654205d6b
commit
e28eadcd52
@ -145,12 +145,7 @@ message(STATUS "Build type: " ${CMAKE_BUILD_TYPE})
|
||||
# ---------------------------------------------------------------------------------------
|
||||
# Static/Shared library
|
||||
# ---------------------------------------------------------------------------------------
|
||||
file(GLOB SPDLOG_SRCS
|
||||
src/*.cpp
|
||||
src/details/*.cpp
|
||||
src/sinks/*.cpp
|
||||
src/cfg/*.cpp
|
||||
)
|
||||
file(GLOB SPDLOG_SRCS src/*.cpp src/details/*.cpp src/sinks/*.cpp src/cfg/*.cpp)
|
||||
|
||||
if(NOT SPDLOG_USE_STD_FORMAT AND NOT SPDLOG_FMT_EXTERNAL AND NOT SPDLOG_FMT_EXTERNAL_HO)
|
||||
list(APPEND SPDLOG_SRCS src/fmt/bundled_fmtlib_format.cpp)
|
||||
|
@ -63,4 +63,3 @@ private:
|
||||
async_overflow_policy overflow_policy_;
|
||||
};
|
||||
} // namespace spdlog
|
||||
|
||||
|
@ -37,7 +37,6 @@
|
||||
# endif
|
||||
#endif
|
||||
|
||||
|
||||
#if defined(SPDLOG_SHARED_LIB)
|
||||
# if defined(_WIN32)
|
||||
# ifdef spdlog_EXPORTS
|
||||
@ -134,7 +133,6 @@ using wmemory_buf_t = fmt::basic_memory_buffer<wchar_t, 250>;
|
||||
# define SPDLOG_BUF_TO_STRING(x) fmt::to_string(x)
|
||||
#endif // SPDLOG_USE_STD_FORMAT
|
||||
|
||||
|
||||
#define SPDLOG_LEVEL_TRACE 0
|
||||
#define SPDLOG_LEVEL_DEBUG 1
|
||||
#define SPDLOG_LEVEL_INFO 2
|
||||
@ -165,17 +163,23 @@ enum class level
|
||||
};
|
||||
|
||||
#if defined(SPDLOG_NO_ATOMIC_LEVELS)
|
||||
using atomic_level_t = details::null_atomic<level>;
|
||||
using atomic_level_t = details::null_atomic<level>;
|
||||
#else
|
||||
using atomic_level_t = std::atomic<level>;
|
||||
using atomic_level_t = std::atomic<level>;
|
||||
#endif
|
||||
|
||||
#if !defined(SPDLOG_LEVEL_NAMES)
|
||||
#define SPDLOG_LEVEL_NAMES { "trace", "debug", "info", "warning", "error", "critical", "off"}
|
||||
# define SPDLOG_LEVEL_NAMES \
|
||||
{ \
|
||||
"trace", "debug", "info", "warning", "error", "critical", "off" \
|
||||
}
|
||||
#endif
|
||||
|
||||
#if !defined(SPDLOG_SHORT_LEVEL_NAMES)
|
||||
#define SPDLOG_SHORT_LEVEL_NAMES {"T", "D", "I", "W", "E", "C", "O"}
|
||||
# define SPDLOG_SHORT_LEVEL_NAMES \
|
||||
{ \
|
||||
"T", "D", "I", "W", "E", "C", "O" \
|
||||
}
|
||||
#endif
|
||||
|
||||
[[nodiscard]] constexpr size_t level_to_number(level lvl) noexcept
|
||||
@ -198,8 +202,6 @@ constexpr std::array<const char *, levels_count> short_level_names SPDLOG_SHORT_
|
||||
|
||||
SPDLOG_API [[nodiscard]] spdlog::level level_from_str(const std::string &name) noexcept;
|
||||
|
||||
|
||||
|
||||
//
|
||||
// Color mode used by sinks with color support.
|
||||
//
|
||||
|
@ -31,4 +31,3 @@ struct SPDLOG_API log_msg
|
||||
};
|
||||
} // namespace details
|
||||
} // namespace spdlog
|
||||
|
||||
|
@ -27,4 +27,3 @@ public:
|
||||
|
||||
} // namespace details
|
||||
} // namespace spdlog
|
||||
|
||||
|
@ -116,4 +116,3 @@ SPDLOG_API bool fsync(FILE *fp);
|
||||
} // namespace os
|
||||
} // namespace details
|
||||
} // namespace spdlog
|
||||
|
||||
|
@ -27,7 +27,7 @@
|
||||
{ \
|
||||
if (!location.empty()) \
|
||||
{ \
|
||||
err_handler_(fmt_lib::format("{} [{}({})]", ex.what(), location.filename, location.line)); \
|
||||
err_handler_(fmt_lib::format("{} [{}({})]", ex.what(), location.filename, location.line)); \
|
||||
} \
|
||||
else \
|
||||
{ \
|
||||
|
@ -122,4 +122,3 @@ private:
|
||||
void compile_pattern_(const std::string &pattern);
|
||||
};
|
||||
} // namespace spdlog
|
||||
|
||||
|
@ -46,4 +46,3 @@ protected:
|
||||
};
|
||||
} // namespace sinks
|
||||
} // namespace spdlog
|
||||
|
||||
|
@ -54,4 +54,3 @@ inline std::shared_ptr<logger> basic_logger_st(
|
||||
}
|
||||
|
||||
} // namespace spdlog
|
||||
|
||||
|
@ -33,8 +33,8 @@ struct daily_filename_calculator
|
||||
{
|
||||
filename_t basename, ext;
|
||||
std::tie(basename, ext) = details::file_helper::split_by_extension(filename);
|
||||
return fmt_lib::format(SPDLOG_FILENAME_T("{}_{:04d}-{:02d}-{:02d}{}"), basename, now_tm.tm_year + 1900,
|
||||
now_tm.tm_mon + 1, now_tm.tm_mday, ext);
|
||||
return fmt_lib::format(
|
||||
SPDLOG_FILENAME_T("{}_{:04d}-{:02d}-{:02d}{}"), basename, now_tm.tm_year + 1900, now_tm.tm_mon + 1, now_tm.tm_mday, ext);
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -66,9 +66,10 @@ protected:
|
||||
|
||||
if (client_ != nullptr)
|
||||
{
|
||||
auto doc = document{} << "timestamp" << bsoncxx::types::b_date(msg.time) << "level" << level::to_string_view(msg.log_level).data()
|
||||
<< "level_num" << msg.log_level << "message" << std::string(msg.payload.begin(), msg.payload.end())
|
||||
<< "logger_name" << std::string(msg.logger_name.begin(), msg.logger_name.end()) << "thread_id"
|
||||
auto doc = document{} << "timestamp" << bsoncxx::types::b_date(msg.time) << "level"
|
||||
<< level::to_string_view(msg.log_level).data() << "level_num" << msg.log_level << "message"
|
||||
<< std::string(msg.payload.begin(), msg.payload.end()) << "logger_name"
|
||||
<< std::string(msg.logger_name.begin(), msg.logger_name.end()) << "thread_id"
|
||||
<< static_cast<int>(msg.thread_id) << finalize;
|
||||
client_->database(db_name_).collection(coll_name_).insert_one(doc.view());
|
||||
}
|
||||
|
@ -185,7 +185,7 @@ protected:
|
||||
qt_text_edit_, // text edit to append to
|
||||
std::move(payload), // text to append
|
||||
default_color_, // default color
|
||||
colors_.at(msg.log_level), // color to apply
|
||||
colors_.at(msg.log_level), // color to apply
|
||||
color_range_start, // color range start
|
||||
color_range_end}; // color range end
|
||||
|
||||
|
@ -29,4 +29,3 @@ protected:
|
||||
|
||||
} // namespace sinks
|
||||
} // namespace spdlog
|
||||
|
||||
|
@ -81,4 +81,3 @@ template<typename Factory = spdlog::synchronous_factory>
|
||||
std::shared_ptr<logger> stderr_logger_st(const std::string &logger_name);
|
||||
|
||||
} // namespace spdlog
|
||||
|
||||
|
@ -8,18 +8,18 @@
|
||||
#include <memory>
|
||||
#include <string>
|
||||
|
||||
spdlog::async_logger::async_logger(
|
||||
spdlog::async_logger::async_logger(
|
||||
std::string logger_name, sinks_init_list sinks_list, std::weak_ptr<details::thread_pool> tp, async_overflow_policy overflow_policy)
|
||||
: async_logger(std::move(logger_name), sinks_list.begin(), sinks_list.end(), std::move(tp), overflow_policy)
|
||||
{}
|
||||
|
||||
spdlog::async_logger::async_logger(
|
||||
spdlog::async_logger::async_logger(
|
||||
std::string logger_name, sink_ptr single_sink, std::weak_ptr<details::thread_pool> tp, async_overflow_policy overflow_policy)
|
||||
: async_logger(std::move(logger_name), {std::move(single_sink)}, std::move(tp), overflow_policy)
|
||||
{}
|
||||
|
||||
// send the log message to the thread pool
|
||||
void spdlog::async_logger::sink_it_(const details::log_msg &msg)
|
||||
void spdlog::async_logger::sink_it_(const details::log_msg &msg)
|
||||
{
|
||||
SPDLOG_TRY
|
||||
{
|
||||
@ -36,7 +36,7 @@
|
||||
}
|
||||
|
||||
// send flush request to the thread pool
|
||||
void spdlog::async_logger::flush_()
|
||||
void spdlog::async_logger::flush_()
|
||||
{
|
||||
SPDLOG_TRY
|
||||
{
|
||||
@ -55,7 +55,7 @@
|
||||
//
|
||||
// backend functions - called from the thread pool to do the actual job
|
||||
//
|
||||
void spdlog::async_logger::backend_sink_it_(const details::log_msg &msg)
|
||||
void spdlog::async_logger::backend_sink_it_(const details::log_msg &msg)
|
||||
{
|
||||
for (auto &sink : sinks_)
|
||||
{
|
||||
@ -75,7 +75,7 @@
|
||||
}
|
||||
}
|
||||
|
||||
void spdlog::async_logger::backend_flush_()
|
||||
void spdlog::async_logger::backend_flush_()
|
||||
{
|
||||
for (auto &sink : sinks_)
|
||||
{
|
||||
@ -87,7 +87,7 @@
|
||||
}
|
||||
}
|
||||
|
||||
std::shared_ptr<spdlog::logger> spdlog::async_logger::clone(std::string new_name)
|
||||
std::shared_ptr<spdlog::logger> spdlog::async_logger::clone(std::string new_name)
|
||||
{
|
||||
auto cloned = std::make_shared<spdlog::async_logger>(*this);
|
||||
cloned->name_ = std::move(new_name);
|
||||
|
@ -1,7 +1,6 @@
|
||||
// Copyright(c) 2015-present, Gabi Melman & spdlog contributors.
|
||||
// Distributed under the MIT License (http://opensource.org/licenses/MIT)
|
||||
|
||||
|
||||
#include <spdlog/cfg/helpers.h>
|
||||
#include <spdlog/spdlog.h>
|
||||
#include <spdlog/details/registry.h>
|
||||
@ -74,7 +73,7 @@ inline std::unordered_map<std::string, std::string> extract_key_vals_(const std:
|
||||
return rv;
|
||||
}
|
||||
|
||||
void load_levels(const std::string &input)
|
||||
void load_levels(const std::string &input)
|
||||
{
|
||||
if (input.empty() || input.size() > 512)
|
||||
{
|
||||
|
@ -8,7 +8,7 @@
|
||||
|
||||
namespace spdlog {
|
||||
|
||||
spdlog::level level_from_str(const std::string &name) noexcept
|
||||
spdlog::level level_from_str(const std::string &name) noexcept
|
||||
{
|
||||
auto it = std::find(std::begin(level_string_views), std::end(level_string_views), name);
|
||||
if (it != std::end(level_string_views))
|
||||
@ -26,11 +26,11 @@ namespace spdlog {
|
||||
return level::off;
|
||||
}
|
||||
|
||||
spdlog_ex::spdlog_ex(std::string msg)
|
||||
spdlog_ex::spdlog_ex(std::string msg)
|
||||
: msg_(std::move(msg))
|
||||
{}
|
||||
|
||||
spdlog_ex::spdlog_ex(const std::string &msg, int last_errno)
|
||||
spdlog_ex::spdlog_ex(const std::string &msg, int last_errno)
|
||||
{
|
||||
#ifdef SPDLOG_USE_STD_FORMAT
|
||||
msg_ = std::system_error(std::error_code(last_errno, std::generic_category()), msg).what();
|
||||
@ -41,17 +41,17 @@ namespace spdlog {
|
||||
#endif
|
||||
}
|
||||
|
||||
const char *spdlog_ex::what() const noexcept
|
||||
const char *spdlog_ex::what() const noexcept
|
||||
{
|
||||
return msg_.c_str();
|
||||
}
|
||||
|
||||
void throw_spdlog_ex(const std::string &msg, int last_errno)
|
||||
void throw_spdlog_ex(const std::string &msg, int last_errno)
|
||||
{
|
||||
SPDLOG_THROW(spdlog_ex(msg, last_errno));
|
||||
}
|
||||
|
||||
void throw_spdlog_ex(std::string msg)
|
||||
void throw_spdlog_ex(std::string msg)
|
||||
{
|
||||
SPDLOG_THROW(spdlog_ex(std::move(msg)));
|
||||
}
|
||||
|
@ -13,16 +13,16 @@
|
||||
namespace spdlog {
|
||||
namespace details {
|
||||
|
||||
file_helper::file_helper(const file_event_handlers &event_handlers)
|
||||
file_helper::file_helper(const file_event_handlers &event_handlers)
|
||||
: event_handlers_(event_handlers)
|
||||
{}
|
||||
|
||||
file_helper::~file_helper()
|
||||
file_helper::~file_helper()
|
||||
{
|
||||
close();
|
||||
}
|
||||
|
||||
void file_helper::open(const filename_t &fname, bool truncate)
|
||||
void file_helper::open(const filename_t &fname, bool truncate)
|
||||
{
|
||||
close();
|
||||
filename_ = fname;
|
||||
@ -66,7 +66,7 @@ namespace details {
|
||||
throw_spdlog_ex("Failed opening file " + os::filename_to_str(filename_) + " for writing", errno);
|
||||
}
|
||||
|
||||
void file_helper::reopen(bool truncate)
|
||||
void file_helper::reopen(bool truncate)
|
||||
{
|
||||
if (filename_.empty())
|
||||
{
|
||||
@ -75,7 +75,7 @@ namespace details {
|
||||
this->open(filename_, truncate);
|
||||
}
|
||||
|
||||
void file_helper::flush()
|
||||
void file_helper::flush()
|
||||
{
|
||||
if (std::fflush(fd_) != 0)
|
||||
{
|
||||
@ -83,7 +83,7 @@ namespace details {
|
||||
}
|
||||
}
|
||||
|
||||
void file_helper::sync()
|
||||
void file_helper::sync()
|
||||
{
|
||||
if (!os::fsync(fd_))
|
||||
{
|
||||
@ -91,7 +91,7 @@ namespace details {
|
||||
}
|
||||
}
|
||||
|
||||
void file_helper::close()
|
||||
void file_helper::close()
|
||||
{
|
||||
if (fd_ != nullptr)
|
||||
{
|
||||
@ -110,7 +110,7 @@ namespace details {
|
||||
}
|
||||
}
|
||||
|
||||
void file_helper::write(const memory_buf_t &buf)
|
||||
void file_helper::write(const memory_buf_t &buf)
|
||||
{
|
||||
size_t msg_size = buf.size();
|
||||
auto data = buf.data();
|
||||
@ -120,7 +120,7 @@ namespace details {
|
||||
}
|
||||
}
|
||||
|
||||
size_t file_helper::size() const
|
||||
size_t file_helper::size() const
|
||||
{
|
||||
if (fd_ == nullptr)
|
||||
{
|
||||
@ -129,7 +129,7 @@ namespace details {
|
||||
return os::filesize(fd_);
|
||||
}
|
||||
|
||||
const filename_t &file_helper::filename() const
|
||||
const filename_t &file_helper::filename() const
|
||||
{
|
||||
return filename_;
|
||||
}
|
||||
@ -147,7 +147,7 @@ namespace details {
|
||||
// ".mylog" => (".mylog". "")
|
||||
// "my_folder/.mylog" => ("my_folder/.mylog", "")
|
||||
// "my_folder/.mylog.txt" => ("my_folder/.mylog", ".txt")
|
||||
std::tuple<filename_t, filename_t> file_helper::split_by_extension(const filename_t &fname)
|
||||
std::tuple<filename_t, filename_t> file_helper::split_by_extension(const filename_t &fname)
|
||||
{
|
||||
auto ext_index = fname.rfind('.');
|
||||
|
||||
|
@ -7,8 +7,8 @@
|
||||
namespace spdlog {
|
||||
namespace details {
|
||||
|
||||
log_msg::log_msg(spdlog::log_clock::time_point log_time, spdlog::source_loc loc, string_view_t a_logger_name,
|
||||
spdlog::level lvl, spdlog::string_view_t msg)
|
||||
log_msg::log_msg(spdlog::log_clock::time_point log_time, spdlog::source_loc loc, string_view_t a_logger_name, spdlog::level lvl,
|
||||
spdlog::string_view_t msg)
|
||||
: logger_name(a_logger_name)
|
||||
, log_level(lvl)
|
||||
, time(log_time)
|
||||
@ -19,12 +19,11 @@ namespace details {
|
||||
, payload(msg)
|
||||
{}
|
||||
|
||||
log_msg::log_msg(
|
||||
spdlog::source_loc loc, string_view_t a_logger_name, spdlog::level lvl, spdlog::string_view_t msg)
|
||||
log_msg::log_msg(spdlog::source_loc loc, string_view_t a_logger_name, spdlog::level lvl, spdlog::string_view_t msg)
|
||||
: log_msg(os::now(), loc, a_logger_name, lvl, msg)
|
||||
{}
|
||||
|
||||
log_msg::log_msg(string_view_t a_logger_name, spdlog::level lvl, spdlog::string_view_t msg)
|
||||
log_msg::log_msg(string_view_t a_logger_name, spdlog::level lvl, spdlog::string_view_t msg)
|
||||
: log_msg(os::now(), source_loc{}, a_logger_name, lvl, msg)
|
||||
{}
|
||||
|
||||
|
@ -6,7 +6,7 @@
|
||||
namespace spdlog {
|
||||
namespace details {
|
||||
|
||||
log_msg_buffer::log_msg_buffer(const log_msg &orig_msg)
|
||||
log_msg_buffer::log_msg_buffer(const log_msg &orig_msg)
|
||||
: log_msg{orig_msg}
|
||||
{
|
||||
buffer.append(logger_name.begin(), logger_name.end());
|
||||
@ -14,7 +14,7 @@ namespace details {
|
||||
update_string_views();
|
||||
}
|
||||
|
||||
log_msg_buffer::log_msg_buffer(const log_msg_buffer &other)
|
||||
log_msg_buffer::log_msg_buffer(const log_msg_buffer &other)
|
||||
: log_msg{other}
|
||||
{
|
||||
buffer.append(logger_name.begin(), logger_name.end());
|
||||
@ -22,14 +22,14 @@ namespace details {
|
||||
update_string_views();
|
||||
}
|
||||
|
||||
log_msg_buffer::log_msg_buffer(log_msg_buffer &&other) noexcept
|
||||
log_msg_buffer::log_msg_buffer(log_msg_buffer &&other) noexcept
|
||||
: log_msg{other}
|
||||
, buffer{std::move(other.buffer)}
|
||||
{
|
||||
update_string_views();
|
||||
}
|
||||
|
||||
log_msg_buffer &log_msg_buffer::operator=(const log_msg_buffer &other)
|
||||
log_msg_buffer &log_msg_buffer::operator=(const log_msg_buffer &other)
|
||||
{
|
||||
log_msg::operator=(other);
|
||||
buffer.clear();
|
||||
@ -38,7 +38,7 @@ namespace details {
|
||||
return *this;
|
||||
}
|
||||
|
||||
log_msg_buffer &log_msg_buffer::operator=(log_msg_buffer &&other) noexcept
|
||||
log_msg_buffer &log_msg_buffer::operator=(log_msg_buffer &&other) noexcept
|
||||
{
|
||||
log_msg::operator=(other);
|
||||
buffer = std::move(other.buffer);
|
||||
@ -46,7 +46,7 @@ namespace details {
|
||||
return *this;
|
||||
}
|
||||
|
||||
void log_msg_buffer::update_string_views()
|
||||
void log_msg_buffer::update_string_views()
|
||||
{
|
||||
logger_name = string_view_t{buffer.data(), logger_name.size()};
|
||||
payload = string_view_t{buffer.data() + logger_name.size(), payload.size()};
|
||||
|
@ -68,7 +68,7 @@ namespace spdlog {
|
||||
namespace details {
|
||||
namespace os {
|
||||
|
||||
spdlog::log_clock::time_point now() noexcept
|
||||
spdlog::log_clock::time_point now() noexcept
|
||||
{
|
||||
|
||||
#if defined __linux__ && defined SPDLOG_CLOCK_COARSE
|
||||
@ -81,7 +81,7 @@ namespace os {
|
||||
return log_clock::now();
|
||||
#endif
|
||||
}
|
||||
std::tm localtime(const std::time_t &time_tt) noexcept
|
||||
std::tm localtime(const std::time_t &time_tt) noexcept
|
||||
{
|
||||
|
||||
#ifdef _WIN32
|
||||
@ -94,13 +94,13 @@ namespace os {
|
||||
return tm;
|
||||
}
|
||||
|
||||
std::tm localtime() noexcept
|
||||
std::tm localtime() noexcept
|
||||
{
|
||||
std::time_t now_t = ::time(nullptr);
|
||||
return localtime(now_t);
|
||||
}
|
||||
|
||||
std::tm gmtime(const std::time_t &time_tt) noexcept
|
||||
std::tm gmtime(const std::time_t &time_tt) noexcept
|
||||
{
|
||||
|
||||
#ifdef _WIN32
|
||||
@ -113,14 +113,14 @@ namespace os {
|
||||
return tm;
|
||||
}
|
||||
|
||||
std::tm gmtime() noexcept
|
||||
std::tm gmtime() noexcept
|
||||
{
|
||||
std::time_t now_t = ::time(nullptr);
|
||||
return gmtime(now_t);
|
||||
}
|
||||
|
||||
// fopen_s on non windows for writing
|
||||
bool fopen_s(FILE **fp, const filename_t &filename, const filename_t &mode)
|
||||
bool fopen_s(FILE **fp, const filename_t &filename, const filename_t &mode)
|
||||
{
|
||||
#ifdef _WIN32
|
||||
# ifdef SPDLOG_WCHAR_FILENAMES
|
||||
@ -160,7 +160,7 @@ namespace os {
|
||||
return *fp == nullptr;
|
||||
}
|
||||
|
||||
int remove(const filename_t &filename) noexcept
|
||||
int remove(const filename_t &filename) noexcept
|
||||
{
|
||||
#if defined(_WIN32) && defined(SPDLOG_WCHAR_FILENAMES)
|
||||
return ::_wremove(filename.c_str());
|
||||
@ -169,12 +169,12 @@ namespace os {
|
||||
#endif
|
||||
}
|
||||
|
||||
int remove_if_exists(const filename_t &filename) noexcept
|
||||
int remove_if_exists(const filename_t &filename) noexcept
|
||||
{
|
||||
return path_exists(filename) ? remove(filename) : 0;
|
||||
}
|
||||
|
||||
int rename(const filename_t &filename1, const filename_t &filename2) noexcept
|
||||
int rename(const filename_t &filename1, const filename_t &filename2) noexcept
|
||||
{
|
||||
#if defined(_WIN32) && defined(SPDLOG_WCHAR_FILENAMES)
|
||||
return ::_wrename(filename1.c_str(), filename2.c_str());
|
||||
@ -184,7 +184,7 @@ namespace os {
|
||||
}
|
||||
|
||||
// Return true if path exists (file or directory)
|
||||
bool path_exists(const filename_t &filename) noexcept
|
||||
bool path_exists(const filename_t &filename) noexcept
|
||||
{
|
||||
#ifdef _WIN32
|
||||
# ifdef SPDLOG_WCHAR_FILENAMES
|
||||
@ -206,7 +206,7 @@ namespace os {
|
||||
#endif
|
||||
|
||||
// Return file size according to open FILE* object
|
||||
size_t filesize(FILE *f)
|
||||
size_t filesize(FILE *f)
|
||||
{
|
||||
if (f == nullptr)
|
||||
{
|
||||
@ -260,7 +260,7 @@ namespace os {
|
||||
#endif
|
||||
|
||||
// Return utc offset in minutes or throw spdlog_ex on failure
|
||||
int utc_minutes_offset(const std::tm &tm)
|
||||
int utc_minutes_offset(const std::tm &tm)
|
||||
{
|
||||
|
||||
#ifdef _WIN32
|
||||
@ -328,7 +328,7 @@ namespace os {
|
||||
// Return current thread id as size_t
|
||||
// It exists because the std::this_thread::get_id() is much slower(especially
|
||||
// under VS 2013)
|
||||
size_t _thread_id() noexcept
|
||||
size_t _thread_id() noexcept
|
||||
{
|
||||
#ifdef _WIN32
|
||||
return static_cast<size_t>(::GetCurrentThreadId());
|
||||
@ -377,7 +377,7 @@ namespace os {
|
||||
}
|
||||
|
||||
// Return current thread id as size_t (from thread local storage)
|
||||
size_t thread_id() noexcept
|
||||
size_t thread_id() noexcept
|
||||
{
|
||||
// cache thread id in tls
|
||||
static thread_local const size_t tid = _thread_id();
|
||||
@ -386,7 +386,7 @@ namespace os {
|
||||
|
||||
// This is avoid msvc issue in sleep_for that happens if the clock changes.
|
||||
// See https://github.com/gabime/spdlog/issues/609
|
||||
void sleep_for_millis(unsigned int milliseconds) noexcept
|
||||
void sleep_for_millis(unsigned int milliseconds) noexcept
|
||||
{
|
||||
#if defined(_WIN32)
|
||||
::Sleep(milliseconds);
|
||||
@ -397,20 +397,20 @@ namespace os {
|
||||
|
||||
// wchar support for windows file names (SPDLOG_WCHAR_FILENAMES must be defined)
|
||||
#if defined(_WIN32) && defined(SPDLOG_WCHAR_FILENAMES)
|
||||
std::string filename_to_str(const filename_t &filename)
|
||||
std::string filename_to_str(const filename_t &filename)
|
||||
{
|
||||
memory_buf_t buf;
|
||||
wstr_to_utf8buf(filename, buf);
|
||||
return SPDLOG_BUF_TO_STRING(buf);
|
||||
}
|
||||
#else
|
||||
std::string filename_to_str(const filename_t &filename)
|
||||
std::string filename_to_str(const filename_t &filename)
|
||||
{
|
||||
return filename;
|
||||
}
|
||||
#endif
|
||||
|
||||
int pid() noexcept
|
||||
int pid() noexcept
|
||||
{
|
||||
|
||||
#ifdef _WIN32
|
||||
@ -422,7 +422,7 @@ namespace os {
|
||||
|
||||
// Determine if the terminal supports colors
|
||||
// Based on: https://github.com/agauniyal/rang/
|
||||
bool is_color_terminal() noexcept
|
||||
bool is_color_terminal() noexcept
|
||||
{
|
||||
#ifdef _WIN32
|
||||
return true;
|
||||
@ -453,7 +453,7 @@ namespace os {
|
||||
|
||||
// Determine if the terminal attached
|
||||
// Source: https://github.com/agauniyal/rang/
|
||||
bool in_terminal(FILE *file) noexcept
|
||||
bool in_terminal(FILE *file) noexcept
|
||||
{
|
||||
|
||||
#ifdef _WIN32
|
||||
@ -464,7 +464,7 @@ namespace os {
|
||||
}
|
||||
|
||||
#if defined(SPDLOG_WCHAR_FILENAMES) && defined(_WIN32)
|
||||
void wstr_to_utf8buf(wstring_view_t wstr, memory_buf_t &target)
|
||||
void wstr_to_utf8buf(wstring_view_t wstr, memory_buf_t &target)
|
||||
{
|
||||
if (wstr.size() > static_cast<size_t>((std::numeric_limits<int>::max)()) / 2 - 1)
|
||||
{
|
||||
@ -499,7 +499,7 @@ namespace os {
|
||||
throw_spdlog_ex(fmt_lib::format("WideCharToMultiByte failed. Last error: {}", ::GetLastError()));
|
||||
}
|
||||
|
||||
void utf8_to_wstrbuf(string_view_t str, wmemory_buf_t &target)
|
||||
void utf8_to_wstrbuf(string_view_t str, wmemory_buf_t &target)
|
||||
{
|
||||
if (str.size() > static_cast<size_t>((std::numeric_limits<int>::max)()) - 1)
|
||||
{
|
||||
@ -532,7 +532,7 @@ namespace os {
|
||||
#endif // defined(SPDLOG_WCHAR_FILENAMES) && defined(_WIN32)
|
||||
|
||||
// return true on success
|
||||
static bool mkdir_(const filename_t &path)
|
||||
static bool mkdir_(const filename_t &path)
|
||||
{
|
||||
#ifdef _WIN32
|
||||
# ifdef SPDLOG_WCHAR_FILENAMES
|
||||
@ -547,7 +547,7 @@ static bool mkdir_(const filename_t &path)
|
||||
|
||||
// create the given directory - and all directories leading to it
|
||||
// return true on success or if the directory already exists
|
||||
bool create_dir(const filename_t &path)
|
||||
bool create_dir(const filename_t &path)
|
||||
{
|
||||
if (path_exists(path))
|
||||
{
|
||||
@ -586,13 +586,13 @@ static bool mkdir_(const filename_t &path)
|
||||
// "abc/" => "abc"
|
||||
// "abc" => ""
|
||||
// "abc///" => "abc//"
|
||||
filename_t dir_name(const filename_t &path)
|
||||
filename_t dir_name(const filename_t &path)
|
||||
{
|
||||
auto pos = path.find_last_of(folder_seps_filename);
|
||||
return pos != filename_t::npos ? path.substr(0, pos) : filename_t{};
|
||||
}
|
||||
|
||||
std::string getenv(const char *field)
|
||||
std::string getenv(const char *field)
|
||||
{
|
||||
|
||||
#if defined(_MSC_VER)
|
||||
@ -612,7 +612,7 @@ std::string getenv(const char *field)
|
||||
|
||||
// Do fsync by FILE handlerpointer
|
||||
// Return true on success
|
||||
bool fsync(FILE *fp)
|
||||
bool fsync(FILE *fp)
|
||||
{
|
||||
#ifdef _WIN32
|
||||
return FlushFileBuffers(reinterpret_cast<HANDLE>(_get_osfhandle(_fileno(fp)))) != 0;
|
||||
|
@ -7,7 +7,7 @@ namespace spdlog {
|
||||
namespace details {
|
||||
|
||||
// stop the worker thread and join it
|
||||
periodic_worker::~periodic_worker()
|
||||
periodic_worker::~periodic_worker()
|
||||
{
|
||||
if (worker_thread_.joinable())
|
||||
{
|
||||
|
@ -26,7 +26,7 @@
|
||||
namespace spdlog {
|
||||
namespace details {
|
||||
|
||||
registry::registry()
|
||||
registry::registry()
|
||||
: formatter_(new pattern_formatter())
|
||||
{
|
||||
|
||||
@ -45,15 +45,15 @@ namespace details {
|
||||
#endif // SPDLOG_DISABLE_DEFAULT_LOGGER
|
||||
}
|
||||
|
||||
registry::~registry() = default;
|
||||
registry::~registry() = default;
|
||||
|
||||
void registry::register_logger(std::shared_ptr<logger> new_logger)
|
||||
void registry::register_logger(std::shared_ptr<logger> new_logger)
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(logger_map_mutex_);
|
||||
register_logger_(std::move(new_logger));
|
||||
}
|
||||
|
||||
void registry::initialize_logger(std::shared_ptr<logger> new_logger)
|
||||
void registry::initialize_logger(std::shared_ptr<logger> new_logger)
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(logger_map_mutex_);
|
||||
new_logger->set_formatter(formatter_->clone());
|
||||
@ -76,14 +76,14 @@ namespace details {
|
||||
}
|
||||
}
|
||||
|
||||
std::shared_ptr<logger> registry::get(const std::string &logger_name)
|
||||
std::shared_ptr<logger> registry::get(const std::string &logger_name)
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(logger_map_mutex_);
|
||||
auto found = loggers_.find(logger_name);
|
||||
return found == loggers_.end() ? nullptr : found->second;
|
||||
}
|
||||
|
||||
std::shared_ptr<logger> registry::default_logger()
|
||||
std::shared_ptr<logger> registry::default_logger()
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(logger_map_mutex_);
|
||||
return default_logger_;
|
||||
@ -93,14 +93,14 @@ namespace details {
|
||||
// To be used directly by the spdlog default api (e.g. spdlog::info)
|
||||
// This make the default API faster, but cannot be used concurrently with set_default_logger().
|
||||
// e.g do not call set_default_logger() from one thread while calling spdlog::info() from another.
|
||||
logger *registry::get_default_raw()
|
||||
logger *registry::get_default_raw()
|
||||
{
|
||||
return default_logger_.get();
|
||||
}
|
||||
|
||||
// set default logger.
|
||||
// default logger is stored in default_logger_ (for faster retrieval) and in the loggers_ map.
|
||||
void registry::set_default_logger(std::shared_ptr<logger> new_default_logger)
|
||||
void registry::set_default_logger(std::shared_ptr<logger> new_default_logger)
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(logger_map_mutex_);
|
||||
// remove previous default logger from the map
|
||||
@ -115,20 +115,20 @@ namespace details {
|
||||
default_logger_ = std::move(new_default_logger);
|
||||
}
|
||||
|
||||
void registry::set_tp(std::shared_ptr<thread_pool> tp)
|
||||
void registry::set_tp(std::shared_ptr<thread_pool> tp)
|
||||
{
|
||||
std::lock_guard<std::recursive_mutex> lock(tp_mutex_);
|
||||
tp_ = std::move(tp);
|
||||
}
|
||||
|
||||
std::shared_ptr<thread_pool> registry::get_tp()
|
||||
std::shared_ptr<thread_pool> registry::get_tp()
|
||||
{
|
||||
std::lock_guard<std::recursive_mutex> lock(tp_mutex_);
|
||||
return tp_;
|
||||
}
|
||||
|
||||
// Set global formatter. Each sink in each logger will get a clone of this object
|
||||
void registry::set_formatter(std::unique_ptr<formatter> formatter)
|
||||
void registry::set_formatter(std::unique_ptr<formatter> formatter)
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(logger_map_mutex_);
|
||||
formatter_ = std::move(formatter);
|
||||
@ -138,7 +138,7 @@ namespace details {
|
||||
}
|
||||
}
|
||||
|
||||
void registry::set_level(level level)
|
||||
void registry::set_level(level level)
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(logger_map_mutex_);
|
||||
for (auto &l : loggers_)
|
||||
@ -148,7 +148,7 @@ namespace details {
|
||||
global_log_level_ = level;
|
||||
}
|
||||
|
||||
void registry::flush_on(level level)
|
||||
void registry::flush_on(level level)
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(logger_map_mutex_);
|
||||
for (auto &l : loggers_)
|
||||
@ -158,7 +158,7 @@ namespace details {
|
||||
flush_level_ = level;
|
||||
}
|
||||
|
||||
void registry::set_error_handler(err_handler handler)
|
||||
void registry::set_error_handler(err_handler handler)
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(logger_map_mutex_);
|
||||
for (auto &l : loggers_)
|
||||
@ -168,7 +168,7 @@ namespace details {
|
||||
err_handler_ = std::move(handler);
|
||||
}
|
||||
|
||||
void registry::apply_all(const std::function<void(const std::shared_ptr<logger>)> &fun)
|
||||
void registry::apply_all(const std::function<void(const std::shared_ptr<logger>)> &fun)
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(logger_map_mutex_);
|
||||
for (auto &l : loggers_)
|
||||
@ -177,7 +177,7 @@ namespace details {
|
||||
}
|
||||
}
|
||||
|
||||
void registry::flush_all()
|
||||
void registry::flush_all()
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(logger_map_mutex_);
|
||||
for (auto &l : loggers_)
|
||||
@ -186,7 +186,7 @@ namespace details {
|
||||
}
|
||||
}
|
||||
|
||||
void registry::drop(const std::string &logger_name)
|
||||
void registry::drop(const std::string &logger_name)
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(logger_map_mutex_);
|
||||
auto is_default_logger = default_logger_ && default_logger_->name() == logger_name;
|
||||
@ -197,7 +197,7 @@ namespace details {
|
||||
}
|
||||
}
|
||||
|
||||
void registry::drop_all()
|
||||
void registry::drop_all()
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(logger_map_mutex_);
|
||||
loggers_.clear();
|
||||
@ -205,7 +205,7 @@ namespace details {
|
||||
}
|
||||
|
||||
// clean all resources and threads started by the registry
|
||||
void registry::shutdown()
|
||||
void registry::shutdown()
|
||||
{
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(flusher_mutex_);
|
||||
@ -220,18 +220,18 @@ namespace details {
|
||||
}
|
||||
}
|
||||
|
||||
std::recursive_mutex ®istry::tp_mutex()
|
||||
std::recursive_mutex ®istry::tp_mutex()
|
||||
{
|
||||
return tp_mutex_;
|
||||
}
|
||||
|
||||
void registry::set_automatic_registration(bool automatic_registration)
|
||||
void registry::set_automatic_registration(bool automatic_registration)
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(logger_map_mutex_);
|
||||
automatic_registration_ = automatic_registration;
|
||||
}
|
||||
|
||||
void registry::set_levels(log_levels levels, level *global_level)
|
||||
void registry::set_levels(log_levels levels, level *global_level)
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(logger_map_mutex_);
|
||||
log_levels_ = std::move(levels);
|
||||
@ -252,13 +252,13 @@ namespace details {
|
||||
}
|
||||
}
|
||||
|
||||
registry ®istry::instance()
|
||||
registry ®istry::instance()
|
||||
{
|
||||
static registry s_instance;
|
||||
return s_instance;
|
||||
}
|
||||
|
||||
void registry::apply_logger_env_levels(std::shared_ptr<logger> new_logger)
|
||||
void registry::apply_logger_env_levels(std::shared_ptr<logger> new_logger)
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(logger_map_mutex_);
|
||||
auto it = log_levels_.find(new_logger->name());
|
||||
@ -266,7 +266,7 @@ namespace details {
|
||||
new_logger->set_level(new_level);
|
||||
}
|
||||
|
||||
void registry::throw_if_exists_(const std::string &logger_name)
|
||||
void registry::throw_if_exists_(const std::string &logger_name)
|
||||
{
|
||||
if (loggers_.find(logger_name) != loggers_.end())
|
||||
{
|
||||
@ -274,7 +274,7 @@ namespace details {
|
||||
}
|
||||
}
|
||||
|
||||
void registry::register_logger_(std::shared_ptr<logger> new_logger)
|
||||
void registry::register_logger_(std::shared_ptr<logger> new_logger)
|
||||
{
|
||||
auto logger_name = new_logger->name();
|
||||
throw_if_exists_(logger_name);
|
||||
|
@ -8,8 +8,7 @@
|
||||
namespace spdlog {
|
||||
namespace details {
|
||||
|
||||
thread_pool::thread_pool(
|
||||
size_t q_max_items, size_t threads_n, std::function<void()> on_thread_start, std::function<void()> on_thread_stop)
|
||||
thread_pool::thread_pool(size_t q_max_items, size_t threads_n, std::function<void()> on_thread_start, std::function<void()> on_thread_stop)
|
||||
: q_(q_max_items)
|
||||
{
|
||||
if (threads_n == 0 || threads_n > 1000)
|
||||
@ -27,17 +26,17 @@ namespace details {
|
||||
}
|
||||
}
|
||||
|
||||
thread_pool::thread_pool(size_t q_max_items, size_t threads_n, std::function<void()> on_thread_start)
|
||||
thread_pool::thread_pool(size_t q_max_items, size_t threads_n, std::function<void()> on_thread_start)
|
||||
: thread_pool(q_max_items, threads_n, on_thread_start, [] {})
|
||||
{}
|
||||
|
||||
thread_pool::thread_pool(size_t q_max_items, size_t threads_n)
|
||||
thread_pool::thread_pool(size_t q_max_items, size_t threads_n)
|
||||
: thread_pool(
|
||||
q_max_items, threads_n, [] {}, [] {})
|
||||
{}
|
||||
|
||||
// message all threads to terminate gracefully join them
|
||||
thread_pool::~thread_pool()
|
||||
thread_pool::~thread_pool()
|
||||
{
|
||||
SPDLOG_TRY
|
||||
{
|
||||
@ -54,43 +53,43 @@ namespace details {
|
||||
SPDLOG_CATCH_STD
|
||||
}
|
||||
|
||||
void thread_pool::post_log(async_logger_ptr &&worker_ptr, const details::log_msg &msg, async_overflow_policy overflow_policy)
|
||||
void thread_pool::post_log(async_logger_ptr &&worker_ptr, const details::log_msg &msg, async_overflow_policy overflow_policy)
|
||||
{
|
||||
async_msg async_m(std::move(worker_ptr), async_msg_type::log, msg);
|
||||
post_async_msg_(std::move(async_m), overflow_policy);
|
||||
}
|
||||
|
||||
void thread_pool::post_flush(async_logger_ptr &&worker_ptr, async_overflow_policy overflow_policy)
|
||||
void thread_pool::post_flush(async_logger_ptr &&worker_ptr, async_overflow_policy overflow_policy)
|
||||
{
|
||||
post_async_msg_(async_msg(std::move(worker_ptr), async_msg_type::flush), overflow_policy);
|
||||
}
|
||||
|
||||
size_t thread_pool::overrun_counter()
|
||||
size_t thread_pool::overrun_counter()
|
||||
{
|
||||
return q_.overrun_counter();
|
||||
}
|
||||
|
||||
void thread_pool::reset_overrun_counter()
|
||||
void thread_pool::reset_overrun_counter()
|
||||
{
|
||||
q_.reset_overrun_counter();
|
||||
}
|
||||
|
||||
size_t thread_pool::discard_counter()
|
||||
size_t thread_pool::discard_counter()
|
||||
{
|
||||
return q_.discard_counter();
|
||||
}
|
||||
|
||||
void thread_pool::reset_discard_counter()
|
||||
void thread_pool::reset_discard_counter()
|
||||
{
|
||||
q_.reset_discard_counter();
|
||||
}
|
||||
|
||||
size_t thread_pool::queue_size()
|
||||
size_t thread_pool::queue_size()
|
||||
{
|
||||
return q_.size();
|
||||
}
|
||||
|
||||
void thread_pool::post_async_msg_(async_msg &&new_msg, async_overflow_policy overflow_policy)
|
||||
void thread_pool::post_async_msg_(async_msg &&new_msg, async_overflow_policy overflow_policy)
|
||||
{
|
||||
if (overflow_policy == async_overflow_policy::block)
|
||||
{
|
||||
@ -107,7 +106,7 @@ void thread_pool::post_async_msg_(async_msg &&new_msg, async_overflow_policy ov
|
||||
}
|
||||
}
|
||||
|
||||
void thread_pool::worker_loop_()
|
||||
void thread_pool::worker_loop_()
|
||||
{
|
||||
while (process_next_msg_()) {}
|
||||
}
|
||||
@ -115,7 +114,7 @@ void thread_pool::worker_loop_()
|
||||
// process next message in the queue
|
||||
// return true if this thread should still be active (while no terminate msg
|
||||
// was received)
|
||||
bool thread_pool::process_next_msg_()
|
||||
bool thread_pool::process_next_msg_()
|
||||
{
|
||||
async_msg incoming_async_msg;
|
||||
q_.dequeue(incoming_async_msg);
|
||||
|
@ -11,7 +11,7 @@
|
||||
namespace spdlog {
|
||||
|
||||
// public methods
|
||||
logger::logger(const logger &other) noexcept
|
||||
logger::logger(const logger &other) noexcept
|
||||
: name_(other.name_)
|
||||
, sinks_(other.sinks_)
|
||||
, level_(other.level_.load(std::memory_order_relaxed))
|
||||
@ -19,7 +19,7 @@ namespace spdlog {
|
||||
, custom_err_handler_(other.custom_err_handler_)
|
||||
{}
|
||||
|
||||
logger::logger(logger &&other) noexcept
|
||||
logger::logger(logger &&other) noexcept
|
||||
: name_(std::move(other.name_))
|
||||
, sinks_(std::move(other.sinks_))
|
||||
, level_(other.level_.load(std::memory_order_relaxed))
|
||||
@ -27,24 +27,24 @@ namespace spdlog {
|
||||
, custom_err_handler_(std::move(other.custom_err_handler_))
|
||||
{}
|
||||
|
||||
void logger::set_level(level level)
|
||||
void logger::set_level(level level)
|
||||
{
|
||||
level_.store(level);
|
||||
}
|
||||
|
||||
level logger::log_level() const
|
||||
level logger::log_level() const
|
||||
{
|
||||
return static_cast<level>(level_.load(std::memory_order_relaxed));
|
||||
}
|
||||
|
||||
const std::string &logger::name() const
|
||||
const std::string &logger::name() const
|
||||
{
|
||||
return name_;
|
||||
}
|
||||
|
||||
// set formatting for the sinks in this logger.
|
||||
// each sink will get a separate instance of the formatter object.
|
||||
void logger::set_formatter(std::unique_ptr<formatter> f)
|
||||
void logger::set_formatter(std::unique_ptr<formatter> f)
|
||||
{
|
||||
for (auto it = sinks_.begin(); it != sinks_.end(); ++it)
|
||||
{
|
||||
@ -61,54 +61,54 @@ namespace spdlog {
|
||||
}
|
||||
}
|
||||
|
||||
void logger::set_pattern(std::string pattern, pattern_time_type time_type)
|
||||
void logger::set_pattern(std::string pattern, pattern_time_type time_type)
|
||||
{
|
||||
auto new_formatter = std::make_unique<pattern_formatter>(std::move(pattern), time_type);
|
||||
set_formatter(std::move(new_formatter));
|
||||
}
|
||||
|
||||
// flush functions
|
||||
void logger::flush()
|
||||
void logger::flush()
|
||||
{
|
||||
flush_();
|
||||
}
|
||||
|
||||
void logger::flush_on(level level)
|
||||
void logger::flush_on(level level)
|
||||
{
|
||||
flush_level_.store(level);
|
||||
}
|
||||
|
||||
level logger::flush_level() const
|
||||
level logger::flush_level() const
|
||||
{
|
||||
return static_cast<level>(flush_level_.load(std::memory_order_relaxed));
|
||||
}
|
||||
|
||||
// sinks
|
||||
const std::vector<sink_ptr> &logger::sinks() const
|
||||
const std::vector<sink_ptr> &logger::sinks() const
|
||||
{
|
||||
return sinks_;
|
||||
}
|
||||
|
||||
std::vector<sink_ptr> &logger::sinks()
|
||||
std::vector<sink_ptr> &logger::sinks()
|
||||
{
|
||||
return sinks_;
|
||||
}
|
||||
|
||||
// error handler
|
||||
void logger::set_error_handler(err_handler handler)
|
||||
void logger::set_error_handler(err_handler handler)
|
||||
{
|
||||
custom_err_handler_ = std::move(handler);
|
||||
}
|
||||
|
||||
// create new logger with same sinks and configuration.
|
||||
std::shared_ptr<logger> logger::clone(std::string logger_name)
|
||||
std::shared_ptr<logger> logger::clone(std::string logger_name)
|
||||
{
|
||||
auto cloned = std::make_shared<logger>(*this);
|
||||
cloned->name_ = std::move(logger_name);
|
||||
return cloned;
|
||||
}
|
||||
|
||||
void logger::flush_()
|
||||
void logger::flush_()
|
||||
{
|
||||
for (auto &sink : sinks_)
|
||||
{
|
||||
@ -120,13 +120,13 @@ namespace spdlog {
|
||||
}
|
||||
}
|
||||
|
||||
bool logger::should_flush_(const details::log_msg &msg)
|
||||
bool logger::should_flush_(const details::log_msg &msg)
|
||||
{
|
||||
auto flush_level = flush_level_.load(std::memory_order_relaxed);
|
||||
return (msg.log_level >= flush_level) && (msg.log_level != level::off);
|
||||
}
|
||||
|
||||
void logger::err_handler_(const std::string &msg)
|
||||
void logger::err_handler_(const std::string &msg)
|
||||
{
|
||||
if (custom_err_handler_)
|
||||
{
|
||||
|
@ -1009,8 +1009,7 @@ private:
|
||||
|
||||
} // namespace details
|
||||
|
||||
pattern_formatter::pattern_formatter(
|
||||
std::string pattern, pattern_time_type time_type, std::string eol, custom_flags custom_user_flags)
|
||||
pattern_formatter::pattern_formatter(std::string pattern, pattern_time_type time_type, std::string eol, custom_flags custom_user_flags)
|
||||
: pattern_(std::move(pattern))
|
||||
, eol_(std::move(eol))
|
||||
, pattern_time_type_(time_type)
|
||||
@ -1023,7 +1022,7 @@ private:
|
||||
}
|
||||
|
||||
// use by default full formatter for if pattern is not given
|
||||
pattern_formatter::pattern_formatter(pattern_time_type time_type, std::string eol)
|
||||
pattern_formatter::pattern_formatter(pattern_time_type time_type, std::string eol)
|
||||
: pattern_("%+")
|
||||
, eol_(std::move(eol))
|
||||
, pattern_time_type_(time_type)
|
||||
@ -1034,7 +1033,7 @@ private:
|
||||
formatters_.push_back(std::make_unique<details::full_formatter>(details::padding_info{}));
|
||||
}
|
||||
|
||||
std::unique_ptr<formatter> pattern_formatter::clone() const
|
||||
std::unique_ptr<formatter> pattern_formatter::clone() const
|
||||
{
|
||||
custom_flags cloned_custom_formatters;
|
||||
for (auto &it : custom_handlers_)
|
||||
@ -1050,7 +1049,7 @@ private:
|
||||
#endif
|
||||
}
|
||||
|
||||
void pattern_formatter::format(const details::log_msg &msg, memory_buf_t &dest)
|
||||
void pattern_formatter::format(const details::log_msg &msg, memory_buf_t &dest)
|
||||
{
|
||||
if (need_localtime_)
|
||||
{
|
||||
@ -1070,19 +1069,19 @@ private:
|
||||
details::fmt_helper::append_string_view(eol_, dest);
|
||||
}
|
||||
|
||||
void pattern_formatter::set_pattern(std::string pattern)
|
||||
void pattern_formatter::set_pattern(std::string pattern)
|
||||
{
|
||||
pattern_ = std::move(pattern);
|
||||
need_localtime_ = false;
|
||||
compile_pattern_(pattern_);
|
||||
}
|
||||
|
||||
void pattern_formatter::need_localtime(bool need)
|
||||
void pattern_formatter::need_localtime(bool need)
|
||||
{
|
||||
need_localtime_ = need;
|
||||
}
|
||||
|
||||
std::tm pattern_formatter::get_time_(const details::log_msg &msg)
|
||||
std::tm pattern_formatter::get_time_(const details::log_msg &msg)
|
||||
{
|
||||
if (pattern_time_type_ == pattern_time_type::local)
|
||||
{
|
||||
@ -1092,7 +1091,7 @@ private:
|
||||
}
|
||||
|
||||
template<typename Padder>
|
||||
void pattern_formatter::handle_flag_(char flag, details::padding_info padding)
|
||||
void pattern_formatter::handle_flag_(char flag, details::padding_info padding)
|
||||
{
|
||||
// process custom flags
|
||||
auto it = custom_handlers_.find(flag);
|
||||
@ -1325,7 +1324,7 @@ template<typename Padder>
|
||||
// Extract given pad spec (e.g. %8X, %=8X, %-8!X, %8!X, %=8!X, %-8!X, %+8!X)
|
||||
// Advance the given it pass the end of the padding spec found (if any)
|
||||
// Return padding.
|
||||
details::padding_info pattern_formatter::handle_padspec_(std::string::const_iterator &it, std::string::const_iterator end)
|
||||
details::padding_info pattern_formatter::handle_padspec_(std::string::const_iterator &it, std::string::const_iterator end)
|
||||
{
|
||||
using details::padding_info;
|
||||
using details::scoped_padder;
|
||||
@ -1377,7 +1376,7 @@ template<typename Padder>
|
||||
return details::padding_info{std::min<size_t>(width, max_width), side, truncate};
|
||||
}
|
||||
|
||||
void pattern_formatter::compile_pattern_(const std::string &pattern)
|
||||
void pattern_formatter::compile_pattern_(const std::string &pattern)
|
||||
{
|
||||
auto end = pattern.end();
|
||||
std::unique_ptr<details::aggregate_formatter> user_chars;
|
||||
|
@ -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>;
|
||||
|
@ -12,92 +12,92 @@ void initialize_logger(std::shared_ptr<logger> logger)
|
||||
details::registry::instance().initialize_logger(std::move(logger));
|
||||
}
|
||||
|
||||
std::shared_ptr<logger> get(const std::string &name)
|
||||
std::shared_ptr<logger> get(const std::string &name)
|
||||
{
|
||||
return details::registry::instance().get(name);
|
||||
}
|
||||
|
||||
void set_formatter(std::unique_ptr<spdlog::formatter> formatter)
|
||||
void set_formatter(std::unique_ptr<spdlog::formatter> formatter)
|
||||
{
|
||||
details::registry::instance().set_formatter(std::move(formatter));
|
||||
}
|
||||
|
||||
void set_pattern(std::string pattern, pattern_time_type time_type)
|
||||
void set_pattern(std::string pattern, pattern_time_type time_type)
|
||||
{
|
||||
set_formatter(std::unique_ptr<spdlog::formatter>(new pattern_formatter(std::move(pattern), time_type)));
|
||||
}
|
||||
|
||||
level get_level()
|
||||
level get_level()
|
||||
{
|
||||
return default_logger_raw()->log_level();
|
||||
}
|
||||
|
||||
bool should_log(level level)
|
||||
bool should_log(level level)
|
||||
{
|
||||
return default_logger_raw()->should_log(level);
|
||||
}
|
||||
|
||||
void set_level(level level)
|
||||
void set_level(level level)
|
||||
{
|
||||
details::registry::instance().set_level(level);
|
||||
}
|
||||
|
||||
void flush_on(level level)
|
||||
void flush_on(level level)
|
||||
{
|
||||
details::registry::instance().flush_on(level);
|
||||
}
|
||||
|
||||
void set_error_handler(void (*handler)(const std::string &msg))
|
||||
void set_error_handler(void (*handler)(const std::string &msg))
|
||||
{
|
||||
details::registry::instance().set_error_handler(handler);
|
||||
}
|
||||
|
||||
void register_logger(std::shared_ptr<logger> logger)
|
||||
void register_logger(std::shared_ptr<logger> logger)
|
||||
{
|
||||
details::registry::instance().register_logger(std::move(logger));
|
||||
}
|
||||
|
||||
void apply_all(const std::function<void(std::shared_ptr<logger>)> &fun)
|
||||
void apply_all(const std::function<void(std::shared_ptr<logger>)> &fun)
|
||||
{
|
||||
details::registry::instance().apply_all(fun);
|
||||
}
|
||||
|
||||
void drop(const std::string &name)
|
||||
void drop(const std::string &name)
|
||||
{
|
||||
details::registry::instance().drop(name);
|
||||
}
|
||||
|
||||
void drop_all()
|
||||
void drop_all()
|
||||
{
|
||||
details::registry::instance().drop_all();
|
||||
}
|
||||
|
||||
void shutdown()
|
||||
void shutdown()
|
||||
{
|
||||
details::registry::instance().shutdown();
|
||||
}
|
||||
|
||||
void set_automatic_registration(bool automatic_registration)
|
||||
void set_automatic_registration(bool automatic_registration)
|
||||
{
|
||||
details::registry::instance().set_automatic_registration(automatic_registration);
|
||||
}
|
||||
|
||||
std::shared_ptr<spdlog::logger> default_logger()
|
||||
std::shared_ptr<spdlog::logger> default_logger()
|
||||
{
|
||||
return details::registry::instance().default_logger();
|
||||
}
|
||||
|
||||
spdlog::logger *default_logger_raw()
|
||||
spdlog::logger *default_logger_raw()
|
||||
{
|
||||
return details::registry::instance().get_default_raw();
|
||||
}
|
||||
|
||||
void set_default_logger(std::shared_ptr<spdlog::logger> default_logger)
|
||||
void set_default_logger(std::shared_ptr<spdlog::logger> default_logger)
|
||||
{
|
||||
details::registry::instance().set_default_logger(std::move(default_logger));
|
||||
}
|
||||
|
||||
void apply_logger_env_levels(std::shared_ptr<logger> logger)
|
||||
void apply_logger_env_levels(std::shared_ptr<logger> logger)
|
||||
{
|
||||
details::registry::instance().apply_logger_env_levels(std::move(logger));
|
||||
}
|
||||
|
@ -47,8 +47,7 @@ set(SPDLOG_UTESTS_SOURCES
|
||||
test_circular_q.cpp
|
||||
test_ringbuffer_sink.cpp
|
||||
test_source_location.cpp
|
||||
test_log_level.cpp
|
||||
)
|
||||
test_log_level.cpp)
|
||||
|
||||
if(NOT SPDLOG_NO_EXCEPTIONS)
|
||||
list(APPEND SPDLOG_UTESTS_SOURCES test_errors.cpp)
|
||||
@ -82,4 +81,3 @@ endfunction()
|
||||
if(SPDLOG_BUILD_TESTS OR SPDLOG_BUILD_ALL)
|
||||
spdlog_prepare_test(spdlog-utests spdlog::spdlog)
|
||||
endif()
|
||||
|
||||
|
@ -8,11 +8,10 @@ TEST_CASE("test_default_level", "[log_level]")
|
||||
auto test_sink = std::make_shared<spdlog::sinks::test_sink_st>();
|
||||
REQUIRE(test_sink->log_level() == spdlog::level::trace);
|
||||
spdlog::logger logger("test-level", test_sink);
|
||||
REQUIRE(test_sink->log_level() == spdlog::level::trace);\
|
||||
REQUIRE(test_sink->log_level() == spdlog::level::trace);
|
||||
REQUIRE(logger.log_level() == spdlog::level::info);
|
||||
}
|
||||
|
||||
|
||||
// test that logger log only messages with level bigger or equal to its level
|
||||
void test_logger_level(spdlog::level level);
|
||||
TEST_CASE("test_logger_levels", "[log_level]")
|
||||
@ -24,7 +23,6 @@ TEST_CASE("test_logger_levels", "[log_level]")
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// test that logger log all messages with level bigger or equal to its level
|
||||
void test_sink_level(spdlog::level level);
|
||||
TEST_CASE("test_sink_levels", "[log_level]")
|
||||
@ -36,7 +34,6 @@ TEST_CASE("test_sink_levels", "[log_level]")
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//
|
||||
// test helpers to check that logger/sink displays only messages with level bigger or equal to its level
|
||||
//
|
||||
@ -44,15 +41,11 @@ auto get_expected_messages(spdlog::level level)
|
||||
{
|
||||
// expected messages for each level
|
||||
static const std::map<spdlog::level, std::vector<std::string>> messages = {
|
||||
{spdlog::level::trace, {"trace hello", "debug hello", "info hello", "warning hello", "error hello", "critical hello"}},
|
||||
{spdlog::level::debug, {"debug hello", "info hello", "warning hello", "error hello", "critical hello"}},
|
||||
{spdlog::level::info, {"info hello", "warning hello", "error hello", "critical hello"}},
|
||||
{spdlog::level::warn, {"warning hello", "error hello", "critical hello"}},
|
||||
{spdlog::level::err, {"error hello", "critical hello"}},
|
||||
{spdlog::level::critical, {"critical hello"}},
|
||||
{spdlog::level::off, {}},
|
||||
{spdlog::level::n_levels, {}}
|
||||
};
|
||||
{spdlog::level::trace, {"trace hello", "debug hello", "info hello", "warning hello", "error hello", "critical hello"}},
|
||||
{spdlog::level::debug, {"debug hello", "info hello", "warning hello", "error hello", "critical hello"}},
|
||||
{spdlog::level::info, {"info hello", "warning hello", "error hello", "critical hello"}},
|
||||
{spdlog::level::warn, {"warning hello", "error hello", "critical hello"}}, {spdlog::level::err, {"error hello", "critical hello"}},
|
||||
{spdlog::level::critical, {"critical hello"}}, {spdlog::level::off, {}}, {spdlog::level::n_levels, {}}};
|
||||
return messages.at(level);
|
||||
}
|
||||
|
||||
@ -73,10 +66,9 @@ void test_logger_level(spdlog::level level)
|
||||
logger.critical("hello");
|
||||
|
||||
auto lines = test_sink->lines();
|
||||
REQUIRE(lines == get_expected_messages(level));
|
||||
REQUIRE(lines == get_expected_messages(level));
|
||||
}
|
||||
|
||||
|
||||
// test that sink displays all messages with level bigger or equal to its level
|
||||
void test_sink_level(spdlog::level level)
|
||||
{
|
||||
@ -98,5 +90,5 @@ void test_sink_level(spdlog::level level)
|
||||
logger.critical("hello");
|
||||
|
||||
auto lines = test_sink->lines();
|
||||
REQUIRE(lines == get_expected_messages(level));
|
||||
REQUIRE(lines == get_expected_messages(level));
|
||||
}
|
Loading…
Reference in New Issue
Block a user