mirror of
https://github.com/gabime/spdlog.git
synced 2024-12-25 01:51:38 +08:00
Removed SPDLOG_COMPILED_LIB/HEADER_ONLY macros from common.h
This commit is contained in:
parent
b16a8951bc
commit
fc81e0390b
@ -13,18 +13,18 @@
|
||||
#include <memory>
|
||||
#include <string>
|
||||
|
||||
SPDLOG_INLINE 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_INLINE 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
|
||||
SPDLOG_INLINE void spdlog::async_logger::sink_it_(const details::log_msg &msg)
|
||||
void spdlog::async_logger::sink_it_(const details::log_msg &msg)
|
||||
{
|
||||
SPDLOG_TRY
|
||||
{
|
||||
@ -41,7 +41,7 @@ SPDLOG_INLINE void spdlog::async_logger::sink_it_(const details::log_msg &msg)
|
||||
}
|
||||
|
||||
// send flush request to the thread pool
|
||||
SPDLOG_INLINE void spdlog::async_logger::flush_()
|
||||
void spdlog::async_logger::flush_()
|
||||
{
|
||||
SPDLOG_TRY
|
||||
{
|
||||
@ -60,7 +60,7 @@ SPDLOG_INLINE void spdlog::async_logger::flush_()
|
||||
//
|
||||
// backend functions - called from the thread pool to do the actual job
|
||||
//
|
||||
SPDLOG_INLINE 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_)
|
||||
{
|
||||
@ -80,7 +80,7 @@ SPDLOG_INLINE void spdlog::async_logger::backend_sink_it_(const details::log_msg
|
||||
}
|
||||
}
|
||||
|
||||
SPDLOG_INLINE void spdlog::async_logger::backend_flush_()
|
||||
void spdlog::async_logger::backend_flush_()
|
||||
{
|
||||
for (auto &sink : sinks_)
|
||||
{
|
||||
@ -92,7 +92,7 @@ SPDLOG_INLINE void spdlog::async_logger::backend_flush_()
|
||||
}
|
||||
}
|
||||
|
||||
SPDLOG_INLINE 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);
|
||||
|
@ -64,6 +64,3 @@ private:
|
||||
};
|
||||
} // namespace spdlog
|
||||
|
||||
#ifdef SPDLOG_HEADER_ONLY
|
||||
# include "async_logger-inl.h"
|
||||
#endif
|
||||
|
@ -79,7 +79,7 @@ inline std::unordered_map<std::string, std::string> extract_key_vals_(const std:
|
||||
return rv;
|
||||
}
|
||||
|
||||
SPDLOG_INLINE void load_levels(const std::string &input)
|
||||
void load_levels(const std::string &input)
|
||||
{
|
||||
if (input.empty() || input.size() > 512)
|
||||
{
|
||||
|
@ -12,7 +12,7 @@
|
||||
|
||||
namespace spdlog {
|
||||
|
||||
SPDLOG_INLINE 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))
|
||||
@ -30,11 +30,11 @@ SPDLOG_INLINE spdlog::level level_from_str(const std::string &name) noexcept
|
||||
return level::off;
|
||||
}
|
||||
|
||||
SPDLOG_INLINE spdlog_ex::spdlog_ex(std::string msg)
|
||||
spdlog_ex::spdlog_ex(std::string msg)
|
||||
: msg_(std::move(msg))
|
||||
{}
|
||||
|
||||
SPDLOG_INLINE 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();
|
||||
@ -45,17 +45,17 @@ SPDLOG_INLINE spdlog_ex::spdlog_ex(const std::string &msg, int last_errno)
|
||||
#endif
|
||||
}
|
||||
|
||||
SPDLOG_INLINE const char *spdlog_ex::what() const noexcept
|
||||
const char *spdlog_ex::what() const noexcept
|
||||
{
|
||||
return msg_.c_str();
|
||||
}
|
||||
|
||||
SPDLOG_INLINE 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));
|
||||
}
|
||||
|
||||
SPDLOG_INLINE void throw_spdlog_ex(std::string msg)
|
||||
void throw_spdlog_ex(std::string msg)
|
||||
{
|
||||
SPDLOG_THROW(spdlog_ex(std::move(msg)));
|
||||
}
|
||||
|
@ -38,27 +38,44 @@
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#ifdef SPDLOG_COMPILED_LIB
|
||||
# undef SPDLOG_HEADER_ONLY
|
||||
# if defined(SPDLOG_SHARED_LIB)
|
||||
# if defined(_WIN32)
|
||||
# ifdef spdlog_EXPORTS
|
||||
# define SPDLOG_API __declspec(dllexport)
|
||||
# else // !spdlog_EXPORTS
|
||||
# define SPDLOG_API __declspec(dllimport)
|
||||
# endif
|
||||
# else // !defined(_WIN32)
|
||||
# define SPDLOG_API __attribute__((visibility("default")))
|
||||
|
||||
#if defined(SPDLOG_SHARED_LIB)
|
||||
# if defined(_WIN32)
|
||||
# ifdef spdlog_EXPORTS
|
||||
# define SPDLOG_API __declspec(dllexport)
|
||||
# else // !spdlog_EXPORTS
|
||||
# define SPDLOG_API __declspec(dllimport)
|
||||
# endif
|
||||
# else // !defined(SPDLOG_SHARED_LIB)
|
||||
# define SPDLOG_API
|
||||
# else // !defined(_WIN32)
|
||||
# define SPDLOG_API __attribute__((visibility("default")))
|
||||
# endif
|
||||
# define SPDLOG_INLINE
|
||||
#else // !defined(SPDLOG_COMPILED_LIB)
|
||||
#else // !defined(SPDLOG_SHARED_LIB)
|
||||
# define SPDLOG_API
|
||||
# define SPDLOG_HEADER_ONLY
|
||||
# define SPDLOG_INLINE inline
|
||||
#endif // #ifdef SPDLOG_COMPILED_LIB
|
||||
#endif
|
||||
|
||||
//
|
||||
//
|
||||
//#ifdef SPDLOG_COMPILED_LIB
|
||||
//# undef SPDLOG_HEADER_ONLY
|
||||
//# if defined(SPDLOG_SHARED_LIB)
|
||||
//# if defined(_WIN32)
|
||||
//# ifdef spdlog_EXPORTS
|
||||
//# define SPDLOG_API __declspec(dllexport)
|
||||
//# else // !spdlog_EXPORTS
|
||||
//# define SPDLOG_API __declspec(dllimport)
|
||||
//# endif
|
||||
//# else // !defined(_WIN32)
|
||||
//# define SPDLOG_API __attribute__((visibility("default")))
|
||||
//# endif
|
||||
//# else // !defined(SPDLOG_SHARED_LIB)
|
||||
//# define SPDLOG_API
|
||||
//# endif
|
||||
//# define
|
||||
//#else // !defined(SPDLOG_COMPILED_LIB)
|
||||
//# define SPDLOG_API
|
||||
//# define SPDLOG_HEADER_ONLY
|
||||
//# define inline
|
||||
//#endif // #ifdef SPDLOG_COMPILED_LIB
|
||||
|
||||
#include <spdlog/fmt/fmt.h>
|
||||
|
||||
|
@ -20,16 +20,16 @@
|
||||
namespace spdlog {
|
||||
namespace details {
|
||||
|
||||
SPDLOG_INLINE file_helper::file_helper(const file_event_handlers &event_handlers)
|
||||
file_helper::file_helper(const file_event_handlers &event_handlers)
|
||||
: event_handlers_(event_handlers)
|
||||
{}
|
||||
|
||||
SPDLOG_INLINE file_helper::~file_helper()
|
||||
file_helper::~file_helper()
|
||||
{
|
||||
close();
|
||||
}
|
||||
|
||||
SPDLOG_INLINE void file_helper::open(const filename_t &fname, bool truncate)
|
||||
void file_helper::open(const filename_t &fname, bool truncate)
|
||||
{
|
||||
close();
|
||||
filename_ = fname;
|
||||
@ -73,7 +73,7 @@ SPDLOG_INLINE void file_helper::open(const filename_t &fname, bool truncate)
|
||||
throw_spdlog_ex("Failed opening file " + os::filename_to_str(filename_) + " for writing", errno);
|
||||
}
|
||||
|
||||
SPDLOG_INLINE void file_helper::reopen(bool truncate)
|
||||
void file_helper::reopen(bool truncate)
|
||||
{
|
||||
if (filename_.empty())
|
||||
{
|
||||
@ -82,7 +82,7 @@ SPDLOG_INLINE void file_helper::reopen(bool truncate)
|
||||
this->open(filename_, truncate);
|
||||
}
|
||||
|
||||
SPDLOG_INLINE void file_helper::flush()
|
||||
void file_helper::flush()
|
||||
{
|
||||
if (std::fflush(fd_) != 0)
|
||||
{
|
||||
@ -90,7 +90,7 @@ SPDLOG_INLINE void file_helper::flush()
|
||||
}
|
||||
}
|
||||
|
||||
SPDLOG_INLINE void file_helper::sync()
|
||||
void file_helper::sync()
|
||||
{
|
||||
if (!os::fsync(fd_))
|
||||
{
|
||||
@ -98,7 +98,7 @@ SPDLOG_INLINE void file_helper::sync()
|
||||
}
|
||||
}
|
||||
|
||||
SPDLOG_INLINE void file_helper::close()
|
||||
void file_helper::close()
|
||||
{
|
||||
if (fd_ != nullptr)
|
||||
{
|
||||
@ -117,7 +117,7 @@ SPDLOG_INLINE void file_helper::close()
|
||||
}
|
||||
}
|
||||
|
||||
SPDLOG_INLINE 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();
|
||||
@ -127,7 +127,7 @@ SPDLOG_INLINE void file_helper::write(const memory_buf_t &buf)
|
||||
}
|
||||
}
|
||||
|
||||
SPDLOG_INLINE size_t file_helper::size() const
|
||||
size_t file_helper::size() const
|
||||
{
|
||||
if (fd_ == nullptr)
|
||||
{
|
||||
@ -136,7 +136,7 @@ SPDLOG_INLINE size_t file_helper::size() const
|
||||
return os::filesize(fd_);
|
||||
}
|
||||
|
||||
SPDLOG_INLINE const filename_t &file_helper::filename() const
|
||||
const filename_t &file_helper::filename() const
|
||||
{
|
||||
return filename_;
|
||||
}
|
||||
@ -154,7 +154,7 @@ SPDLOG_INLINE const filename_t &file_helper::filename() const
|
||||
// ".mylog" => (".mylog". "")
|
||||
// "my_folder/.mylog" => ("my_folder/.mylog", "")
|
||||
// "my_folder/.mylog.txt" => ("my_folder/.mylog", ".txt")
|
||||
SPDLOG_INLINE 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('.');
|
||||
|
||||
|
@ -12,7 +12,7 @@
|
||||
namespace spdlog {
|
||||
namespace details {
|
||||
|
||||
SPDLOG_INLINE log_msg::log_msg(spdlog::log_clock::time_point log_time, spdlog::source_loc loc, string_view_t a_logger_name,
|
||||
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)
|
||||
@ -24,12 +24,12 @@ SPDLOG_INLINE log_msg::log_msg(spdlog::log_clock::time_point log_time, spdlog::s
|
||||
, payload(msg)
|
||||
{}
|
||||
|
||||
SPDLOG_INLINE log_msg::log_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)
|
||||
{}
|
||||
|
||||
SPDLOG_INLINE 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)
|
||||
{}
|
||||
|
||||
|
@ -10,7 +10,7 @@
|
||||
namespace spdlog {
|
||||
namespace details {
|
||||
|
||||
SPDLOG_INLINE 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());
|
||||
@ -18,7 +18,7 @@ SPDLOG_INLINE log_msg_buffer::log_msg_buffer(const log_msg &orig_msg)
|
||||
update_string_views();
|
||||
}
|
||||
|
||||
SPDLOG_INLINE 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());
|
||||
@ -26,14 +26,14 @@ SPDLOG_INLINE log_msg_buffer::log_msg_buffer(const log_msg_buffer &other)
|
||||
update_string_views();
|
||||
}
|
||||
|
||||
SPDLOG_INLINE 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();
|
||||
}
|
||||
|
||||
SPDLOG_INLINE 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();
|
||||
@ -42,7 +42,7 @@ SPDLOG_INLINE log_msg_buffer &log_msg_buffer::operator=(const log_msg_buffer &ot
|
||||
return *this;
|
||||
}
|
||||
|
||||
SPDLOG_INLINE 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);
|
||||
@ -50,7 +50,7 @@ SPDLOG_INLINE log_msg_buffer &log_msg_buffer::operator=(log_msg_buffer &&other)
|
||||
return *this;
|
||||
}
|
||||
|
||||
SPDLOG_INLINE 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()};
|
||||
|
@ -74,7 +74,7 @@ namespace spdlog {
|
||||
namespace details {
|
||||
namespace os {
|
||||
|
||||
SPDLOG_INLINE spdlog::log_clock::time_point now() noexcept
|
||||
spdlog::log_clock::time_point now() noexcept
|
||||
{
|
||||
|
||||
#if defined __linux__ && defined SPDLOG_CLOCK_COARSE
|
||||
@ -87,7 +87,7 @@ SPDLOG_INLINE spdlog::log_clock::time_point now() noexcept
|
||||
return log_clock::now();
|
||||
#endif
|
||||
}
|
||||
SPDLOG_INLINE std::tm localtime(const std::time_t &time_tt) noexcept
|
||||
std::tm localtime(const std::time_t &time_tt) noexcept
|
||||
{
|
||||
|
||||
#ifdef _WIN32
|
||||
@ -100,13 +100,13 @@ SPDLOG_INLINE std::tm localtime(const std::time_t &time_tt) noexcept
|
||||
return tm;
|
||||
}
|
||||
|
||||
SPDLOG_INLINE std::tm localtime() noexcept
|
||||
std::tm localtime() noexcept
|
||||
{
|
||||
std::time_t now_t = ::time(nullptr);
|
||||
return localtime(now_t);
|
||||
}
|
||||
|
||||
SPDLOG_INLINE std::tm gmtime(const std::time_t &time_tt) noexcept
|
||||
std::tm gmtime(const std::time_t &time_tt) noexcept
|
||||
{
|
||||
|
||||
#ifdef _WIN32
|
||||
@ -119,14 +119,14 @@ SPDLOG_INLINE std::tm gmtime(const std::time_t &time_tt) noexcept
|
||||
return tm;
|
||||
}
|
||||
|
||||
SPDLOG_INLINE 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
|
||||
SPDLOG_INLINE 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
|
||||
@ -166,7 +166,7 @@ SPDLOG_INLINE bool fopen_s(FILE **fp, const filename_t &filename, const filename
|
||||
return *fp == nullptr;
|
||||
}
|
||||
|
||||
SPDLOG_INLINE 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());
|
||||
@ -175,12 +175,12 @@ SPDLOG_INLINE int remove(const filename_t &filename) noexcept
|
||||
#endif
|
||||
}
|
||||
|
||||
SPDLOG_INLINE 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;
|
||||
}
|
||||
|
||||
SPDLOG_INLINE 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());
|
||||
@ -190,7 +190,7 @@ SPDLOG_INLINE int rename(const filename_t &filename1, const filename_t &filename
|
||||
}
|
||||
|
||||
// Return true if path exists (file or directory)
|
||||
SPDLOG_INLINE bool path_exists(const filename_t &filename) noexcept
|
||||
bool path_exists(const filename_t &filename) noexcept
|
||||
{
|
||||
#ifdef _WIN32
|
||||
# ifdef SPDLOG_WCHAR_FILENAMES
|
||||
@ -212,7 +212,7 @@ SPDLOG_INLINE bool path_exists(const filename_t &filename) noexcept
|
||||
#endif
|
||||
|
||||
// Return file size according to open FILE* object
|
||||
SPDLOG_INLINE size_t filesize(FILE *f)
|
||||
size_t filesize(FILE *f)
|
||||
{
|
||||
if (f == nullptr)
|
||||
{
|
||||
@ -266,7 +266,7 @@ SPDLOG_INLINE size_t filesize(FILE *f)
|
||||
#endif
|
||||
|
||||
// Return utc offset in minutes or throw spdlog_ex on failure
|
||||
SPDLOG_INLINE int utc_minutes_offset(const std::tm &tm)
|
||||
int utc_minutes_offset(const std::tm &tm)
|
||||
{
|
||||
|
||||
#ifdef _WIN32
|
||||
@ -334,7 +334,7 @@ SPDLOG_INLINE int utc_minutes_offset(const std::tm &tm)
|
||||
// Return current thread id as size_t
|
||||
// It exists because the std::this_thread::get_id() is much slower(especially
|
||||
// under VS 2013)
|
||||
SPDLOG_INLINE size_t _thread_id() noexcept
|
||||
size_t _thread_id() noexcept
|
||||
{
|
||||
#ifdef _WIN32
|
||||
return static_cast<size_t>(::GetCurrentThreadId());
|
||||
@ -383,7 +383,7 @@ SPDLOG_INLINE size_t _thread_id() noexcept
|
||||
}
|
||||
|
||||
// Return current thread id as size_t (from thread local storage)
|
||||
SPDLOG_INLINE size_t thread_id() noexcept
|
||||
size_t thread_id() noexcept
|
||||
{
|
||||
// cache thread id in tls
|
||||
static thread_local const size_t tid = _thread_id();
|
||||
@ -392,7 +392,7 @@ SPDLOG_INLINE size_t thread_id() noexcept
|
||||
|
||||
// This is avoid msvc issue in sleep_for that happens if the clock changes.
|
||||
// See https://github.com/gabime/spdlog/issues/609
|
||||
SPDLOG_INLINE void sleep_for_millis(unsigned int milliseconds) noexcept
|
||||
void sleep_for_millis(unsigned int milliseconds) noexcept
|
||||
{
|
||||
#if defined(_WIN32)
|
||||
::Sleep(milliseconds);
|
||||
@ -403,20 +403,20 @@ SPDLOG_INLINE void sleep_for_millis(unsigned int milliseconds) noexcept
|
||||
|
||||
// wchar support for windows file names (SPDLOG_WCHAR_FILENAMES must be defined)
|
||||
#if defined(_WIN32) && defined(SPDLOG_WCHAR_FILENAMES)
|
||||
SPDLOG_INLINE 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
|
||||
SPDLOG_INLINE std::string filename_to_str(const filename_t &filename)
|
||||
std::string filename_to_str(const filename_t &filename)
|
||||
{
|
||||
return filename;
|
||||
}
|
||||
#endif
|
||||
|
||||
SPDLOG_INLINE int pid() noexcept
|
||||
int pid() noexcept
|
||||
{
|
||||
|
||||
#ifdef _WIN32
|
||||
@ -428,7 +428,7 @@ SPDLOG_INLINE int pid() noexcept
|
||||
|
||||
// Determine if the terminal supports colors
|
||||
// Based on: https://github.com/agauniyal/rang/
|
||||
SPDLOG_INLINE bool is_color_terminal() noexcept
|
||||
bool is_color_terminal() noexcept
|
||||
{
|
||||
#ifdef _WIN32
|
||||
return true;
|
||||
@ -459,7 +459,7 @@ SPDLOG_INLINE bool is_color_terminal() noexcept
|
||||
|
||||
// Determine if the terminal attached
|
||||
// Source: https://github.com/agauniyal/rang/
|
||||
SPDLOG_INLINE bool in_terminal(FILE *file) noexcept
|
||||
bool in_terminal(FILE *file) noexcept
|
||||
{
|
||||
|
||||
#ifdef _WIN32
|
||||
@ -470,7 +470,7 @@ SPDLOG_INLINE bool in_terminal(FILE *file) noexcept
|
||||
}
|
||||
|
||||
#if defined(SPDLOG_WCHAR_FILENAMES) && defined(_WIN32)
|
||||
SPDLOG_INLINE 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)
|
||||
{
|
||||
@ -505,7 +505,7 @@ SPDLOG_INLINE void wstr_to_utf8buf(wstring_view_t wstr, memory_buf_t &target)
|
||||
throw_spdlog_ex(fmt_lib::format("WideCharToMultiByte failed. Last error: {}", ::GetLastError()));
|
||||
}
|
||||
|
||||
SPDLOG_INLINE 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)
|
||||
{
|
||||
@ -538,7 +538,7 @@ SPDLOG_INLINE void utf8_to_wstrbuf(string_view_t str, wmemory_buf_t &target)
|
||||
#endif // defined(SPDLOG_WCHAR_FILENAMES) && defined(_WIN32)
|
||||
|
||||
// return true on success
|
||||
static SPDLOG_INLINE bool mkdir_(const filename_t &path)
|
||||
static bool mkdir_(const filename_t &path)
|
||||
{
|
||||
#ifdef _WIN32
|
||||
# ifdef SPDLOG_WCHAR_FILENAMES
|
||||
@ -553,7 +553,7 @@ static SPDLOG_INLINE 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
|
||||
SPDLOG_INLINE bool create_dir(const filename_t &path)
|
||||
bool create_dir(const filename_t &path)
|
||||
{
|
||||
if (path_exists(path))
|
||||
{
|
||||
@ -592,13 +592,13 @@ SPDLOG_INLINE bool create_dir(const filename_t &path)
|
||||
// "abc/" => "abc"
|
||||
// "abc" => ""
|
||||
// "abc///" => "abc//"
|
||||
SPDLOG_INLINE 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 SPDLOG_INLINE getenv(const char *field)
|
||||
std::string getenv(const char *field)
|
||||
{
|
||||
|
||||
#if defined(_MSC_VER)
|
||||
@ -618,7 +618,7 @@ std::string SPDLOG_INLINE getenv(const char *field)
|
||||
|
||||
// Do fsync by FILE handlerpointer
|
||||
// Return true on success
|
||||
SPDLOG_INLINE bool fsync(FILE *fp)
|
||||
bool fsync(FILE *fp)
|
||||
{
|
||||
#ifdef _WIN32
|
||||
return FlushFileBuffers(reinterpret_cast<HANDLE>(_get_osfhandle(_fileno(fp)))) != 0;
|
||||
|
@ -11,7 +11,7 @@ namespace spdlog {
|
||||
namespace details {
|
||||
|
||||
// stop the worker thread and join it
|
||||
SPDLOG_INLINE periodic_worker::~periodic_worker()
|
||||
periodic_worker::~periodic_worker()
|
||||
{
|
||||
if (worker_thread_.joinable())
|
||||
{
|
||||
|
@ -30,7 +30,7 @@
|
||||
namespace spdlog {
|
||||
namespace details {
|
||||
|
||||
SPDLOG_INLINE registry::registry()
|
||||
registry::registry()
|
||||
: formatter_(new pattern_formatter())
|
||||
{
|
||||
|
||||
@ -49,15 +49,15 @@ SPDLOG_INLINE registry::registry()
|
||||
#endif // SPDLOG_DISABLE_DEFAULT_LOGGER
|
||||
}
|
||||
|
||||
SPDLOG_INLINE registry::~registry() = default;
|
||||
registry::~registry() = default;
|
||||
|
||||
SPDLOG_INLINE 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));
|
||||
}
|
||||
|
||||
SPDLOG_INLINE 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());
|
||||
@ -80,14 +80,14 @@ SPDLOG_INLINE void registry::initialize_logger(std::shared_ptr<logger> new_logge
|
||||
}
|
||||
}
|
||||
|
||||
SPDLOG_INLINE 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;
|
||||
}
|
||||
|
||||
SPDLOG_INLINE 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_;
|
||||
@ -97,14 +97,14 @@ SPDLOG_INLINE std::shared_ptr<logger> registry::default_logger()
|
||||
// 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.
|
||||
SPDLOG_INLINE 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.
|
||||
SPDLOG_INLINE 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
|
||||
@ -119,20 +119,20 @@ SPDLOG_INLINE void registry::set_default_logger(std::shared_ptr<logger> new_defa
|
||||
default_logger_ = std::move(new_default_logger);
|
||||
}
|
||||
|
||||
SPDLOG_INLINE 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);
|
||||
}
|
||||
|
||||
SPDLOG_INLINE 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
|
||||
SPDLOG_INLINE 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);
|
||||
@ -142,7 +142,7 @@ SPDLOG_INLINE void registry::set_formatter(std::unique_ptr<formatter> formatter)
|
||||
}
|
||||
}
|
||||
|
||||
SPDLOG_INLINE 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_)
|
||||
@ -152,7 +152,7 @@ SPDLOG_INLINE void registry::set_level(level level)
|
||||
global_log_level_ = level;
|
||||
}
|
||||
|
||||
SPDLOG_INLINE 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_)
|
||||
@ -162,7 +162,7 @@ SPDLOG_INLINE void registry::flush_on(level level)
|
||||
flush_level_ = level;
|
||||
}
|
||||
|
||||
SPDLOG_INLINE 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_)
|
||||
@ -172,7 +172,7 @@ SPDLOG_INLINE void registry::set_error_handler(err_handler handler)
|
||||
err_handler_ = std::move(handler);
|
||||
}
|
||||
|
||||
SPDLOG_INLINE 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_)
|
||||
@ -181,7 +181,7 @@ SPDLOG_INLINE void registry::apply_all(const std::function<void(const std::share
|
||||
}
|
||||
}
|
||||
|
||||
SPDLOG_INLINE void registry::flush_all()
|
||||
void registry::flush_all()
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(logger_map_mutex_);
|
||||
for (auto &l : loggers_)
|
||||
@ -190,7 +190,7 @@ SPDLOG_INLINE void registry::flush_all()
|
||||
}
|
||||
}
|
||||
|
||||
SPDLOG_INLINE 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;
|
||||
@ -201,7 +201,7 @@ SPDLOG_INLINE void registry::drop(const std::string &logger_name)
|
||||
}
|
||||
}
|
||||
|
||||
SPDLOG_INLINE void registry::drop_all()
|
||||
void registry::drop_all()
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(logger_map_mutex_);
|
||||
loggers_.clear();
|
||||
@ -209,7 +209,7 @@ SPDLOG_INLINE void registry::drop_all()
|
||||
}
|
||||
|
||||
// clean all resources and threads started by the registry
|
||||
SPDLOG_INLINE void registry::shutdown()
|
||||
void registry::shutdown()
|
||||
{
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(flusher_mutex_);
|
||||
@ -224,18 +224,18 @@ SPDLOG_INLINE void registry::shutdown()
|
||||
}
|
||||
}
|
||||
|
||||
SPDLOG_INLINE std::recursive_mutex ®istry::tp_mutex()
|
||||
std::recursive_mutex ®istry::tp_mutex()
|
||||
{
|
||||
return tp_mutex_;
|
||||
}
|
||||
|
||||
SPDLOG_INLINE 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;
|
||||
}
|
||||
|
||||
SPDLOG_INLINE 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);
|
||||
@ -256,13 +256,13 @@ SPDLOG_INLINE void registry::set_levels(log_levels levels, level *global_level)
|
||||
}
|
||||
}
|
||||
|
||||
SPDLOG_INLINE registry ®istry::instance()
|
||||
registry ®istry::instance()
|
||||
{
|
||||
static registry s_instance;
|
||||
return s_instance;
|
||||
}
|
||||
|
||||
SPDLOG_INLINE 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());
|
||||
@ -270,7 +270,7 @@ SPDLOG_INLINE void registry::apply_logger_env_levels(std::shared_ptr<logger> new
|
||||
new_logger->set_level(new_level);
|
||||
}
|
||||
|
||||
SPDLOG_INLINE 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())
|
||||
{
|
||||
@ -278,7 +278,7 @@ SPDLOG_INLINE void registry::throw_if_exists_(const std::string &logger_name)
|
||||
}
|
||||
}
|
||||
|
||||
SPDLOG_INLINE 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);
|
||||
|
@ -13,7 +13,7 @@
|
||||
namespace spdlog {
|
||||
namespace details {
|
||||
|
||||
SPDLOG_INLINE thread_pool::thread_pool(
|
||||
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)
|
||||
{
|
||||
@ -32,17 +32,17 @@ SPDLOG_INLINE thread_pool::thread_pool(
|
||||
}
|
||||
}
|
||||
|
||||
SPDLOG_INLINE 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, [] {})
|
||||
{}
|
||||
|
||||
SPDLOG_INLINE 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
|
||||
SPDLOG_INLINE thread_pool::~thread_pool()
|
||||
thread_pool::~thread_pool()
|
||||
{
|
||||
SPDLOG_TRY
|
||||
{
|
||||
@ -59,43 +59,43 @@ SPDLOG_INLINE thread_pool::~thread_pool()
|
||||
SPDLOG_CATCH_STD
|
||||
}
|
||||
|
||||
void SPDLOG_INLINE 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 SPDLOG_INLINE 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 SPDLOG_INLINE thread_pool::overrun_counter()
|
||||
size_t thread_pool::overrun_counter()
|
||||
{
|
||||
return q_.overrun_counter();
|
||||
}
|
||||
|
||||
void SPDLOG_INLINE thread_pool::reset_overrun_counter()
|
||||
void thread_pool::reset_overrun_counter()
|
||||
{
|
||||
q_.reset_overrun_counter();
|
||||
}
|
||||
|
||||
size_t SPDLOG_INLINE thread_pool::discard_counter()
|
||||
size_t thread_pool::discard_counter()
|
||||
{
|
||||
return q_.discard_counter();
|
||||
}
|
||||
|
||||
void SPDLOG_INLINE thread_pool::reset_discard_counter()
|
||||
void thread_pool::reset_discard_counter()
|
||||
{
|
||||
q_.reset_discard_counter();
|
||||
}
|
||||
|
||||
size_t SPDLOG_INLINE thread_pool::queue_size()
|
||||
size_t thread_pool::queue_size()
|
||||
{
|
||||
return q_.size();
|
||||
}
|
||||
|
||||
void SPDLOG_INLINE 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)
|
||||
{
|
||||
@ -112,7 +112,7 @@ void SPDLOG_INLINE thread_pool::post_async_msg_(async_msg &&new_msg, async_overf
|
||||
}
|
||||
}
|
||||
|
||||
void SPDLOG_INLINE thread_pool::worker_loop_()
|
||||
void thread_pool::worker_loop_()
|
||||
{
|
||||
while (process_next_msg_()) {}
|
||||
}
|
||||
@ -120,7 +120,7 @@ void SPDLOG_INLINE 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 SPDLOG_INLINE thread_pool::process_next_msg_()
|
||||
bool thread_pool::process_next_msg_()
|
||||
{
|
||||
async_msg incoming_async_msg;
|
||||
q_.dequeue(incoming_async_msg);
|
||||
|
@ -15,7 +15,7 @@
|
||||
namespace spdlog {
|
||||
|
||||
// public methods
|
||||
SPDLOG_INLINE 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))
|
||||
@ -23,7 +23,7 @@ SPDLOG_INLINE logger::logger(const logger &other) noexcept
|
||||
, custom_err_handler_(other.custom_err_handler_)
|
||||
{}
|
||||
|
||||
SPDLOG_INLINE 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))
|
||||
@ -31,24 +31,24 @@ SPDLOG_INLINE logger::logger(logger &&other) noexcept
|
||||
, custom_err_handler_(std::move(other.custom_err_handler_))
|
||||
{}
|
||||
|
||||
SPDLOG_INLINE void logger::set_level(level level)
|
||||
void logger::set_level(level level)
|
||||
{
|
||||
level_.store(level);
|
||||
}
|
||||
|
||||
SPDLOG_INLINE level logger::log_level() const
|
||||
level logger::log_level() const
|
||||
{
|
||||
return static_cast<level>(level_.load(std::memory_order_relaxed));
|
||||
}
|
||||
|
||||
SPDLOG_INLINE 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.
|
||||
SPDLOG_INLINE 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)
|
||||
{
|
||||
@ -65,54 +65,54 @@ SPDLOG_INLINE void logger::set_formatter(std::unique_ptr<formatter> f)
|
||||
}
|
||||
}
|
||||
|
||||
SPDLOG_INLINE 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
|
||||
SPDLOG_INLINE void logger::flush()
|
||||
void logger::flush()
|
||||
{
|
||||
flush_();
|
||||
}
|
||||
|
||||
SPDLOG_INLINE void logger::flush_on(level level)
|
||||
void logger::flush_on(level level)
|
||||
{
|
||||
flush_level_.store(level);
|
||||
}
|
||||
|
||||
SPDLOG_INLINE level logger::flush_level() const
|
||||
level logger::flush_level() const
|
||||
{
|
||||
return static_cast<level>(flush_level_.load(std::memory_order_relaxed));
|
||||
}
|
||||
|
||||
// sinks
|
||||
SPDLOG_INLINE const std::vector<sink_ptr> &logger::sinks() const
|
||||
const std::vector<sink_ptr> &logger::sinks() const
|
||||
{
|
||||
return sinks_;
|
||||
}
|
||||
|
||||
SPDLOG_INLINE std::vector<sink_ptr> &logger::sinks()
|
||||
std::vector<sink_ptr> &logger::sinks()
|
||||
{
|
||||
return sinks_;
|
||||
}
|
||||
|
||||
// error handler
|
||||
SPDLOG_INLINE 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.
|
||||
SPDLOG_INLINE 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;
|
||||
}
|
||||
|
||||
SPDLOG_INLINE void logger::flush_()
|
||||
void logger::flush_()
|
||||
{
|
||||
for (auto &sink : sinks_)
|
||||
{
|
||||
@ -124,13 +124,13 @@ SPDLOG_INLINE void logger::flush_()
|
||||
}
|
||||
}
|
||||
|
||||
SPDLOG_INLINE 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);
|
||||
}
|
||||
|
||||
SPDLOG_INLINE void logger::err_handler_(const std::string &msg)
|
||||
void logger::err_handler_(const std::string &msg)
|
||||
{
|
||||
if (custom_err_handler_)
|
||||
{
|
||||
|
@ -1019,7 +1019,7 @@ private:
|
||||
|
||||
} // namespace details
|
||||
|
||||
SPDLOG_INLINE pattern_formatter::pattern_formatter(
|
||||
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))
|
||||
@ -1033,7 +1033,7 @@ SPDLOG_INLINE pattern_formatter::pattern_formatter(
|
||||
}
|
||||
|
||||
// use by default full formatter for if pattern is not given
|
||||
SPDLOG_INLINE 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)
|
||||
@ -1044,7 +1044,7 @@ SPDLOG_INLINE pattern_formatter::pattern_formatter(pattern_time_type time_type,
|
||||
formatters_.push_back(std::make_unique<details::full_formatter>(details::padding_info{}));
|
||||
}
|
||||
|
||||
SPDLOG_INLINE 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_)
|
||||
@ -1060,7 +1060,7 @@ SPDLOG_INLINE std::unique_ptr<formatter> pattern_formatter::clone() const
|
||||
#endif
|
||||
}
|
||||
|
||||
SPDLOG_INLINE 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_)
|
||||
{
|
||||
@ -1080,19 +1080,19 @@ SPDLOG_INLINE void pattern_formatter::format(const details::log_msg &msg, memory
|
||||
details::fmt_helper::append_string_view(eol_, dest);
|
||||
}
|
||||
|
||||
SPDLOG_INLINE 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_);
|
||||
}
|
||||
|
||||
SPDLOG_INLINE void pattern_formatter::need_localtime(bool need)
|
||||
void pattern_formatter::need_localtime(bool need)
|
||||
{
|
||||
need_localtime_ = need;
|
||||
}
|
||||
|
||||
SPDLOG_INLINE 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)
|
||||
{
|
||||
@ -1102,7 +1102,7 @@ SPDLOG_INLINE std::tm pattern_formatter::get_time_(const details::log_msg &msg)
|
||||
}
|
||||
|
||||
template<typename Padder>
|
||||
SPDLOG_INLINE 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);
|
||||
@ -1335,7 +1335,7 @@ SPDLOG_INLINE void pattern_formatter::handle_flag_(char flag, details::padding_i
|
||||
// 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.
|
||||
SPDLOG_INLINE 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;
|
||||
@ -1387,7 +1387,7 @@ SPDLOG_INLINE details::padding_info pattern_formatter::handle_padspec_(std::stri
|
||||
return details::padding_info{std::min<size_t>(width, max_width), side, truncate};
|
||||
}
|
||||
|
||||
SPDLOG_INLINE 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;
|
||||
|
@ -14,7 +14,7 @@ namespace spdlog {
|
||||
namespace sinks {
|
||||
|
||||
template<typename ConsoleMutex>
|
||||
SPDLOG_INLINE 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>())
|
||||
@ -31,14 +31,14 @@ SPDLOG_INLINE ansicolor_sink<ConsoleMutex>::ansicolor_sink(FILE *target_file, co
|
||||
}
|
||||
|
||||
template<typename ConsoleMutex>
|
||||
SPDLOG_INLINE 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>
|
||||
SPDLOG_INLINE 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.
|
||||
@ -66,34 +66,34 @@ SPDLOG_INLINE void ansicolor_sink<ConsoleMutex>::log(const details::log_msg &msg
|
||||
}
|
||||
|
||||
template<typename ConsoleMutex>
|
||||
SPDLOG_INLINE void ansicolor_sink<ConsoleMutex>::flush()
|
||||
void ansicolor_sink<ConsoleMutex>::flush()
|
||||
{
|
||||
std::lock_guard<mutex_t> lock(mutex_);
|
||||
fflush(target_file_);
|
||||
}
|
||||
|
||||
template<typename ConsoleMutex>
|
||||
SPDLOG_INLINE 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>
|
||||
SPDLOG_INLINE 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>
|
||||
SPDLOG_INLINE bool ansicolor_sink<ConsoleMutex>::should_color()
|
||||
bool ansicolor_sink<ConsoleMutex>::should_color()
|
||||
{
|
||||
return should_do_colors_;
|
||||
}
|
||||
|
||||
template<typename ConsoleMutex>
|
||||
SPDLOG_INLINE void ansicolor_sink<ConsoleMutex>::set_color_mode(color_mode mode)
|
||||
void ansicolor_sink<ConsoleMutex>::set_color_mode(color_mode mode)
|
||||
{
|
||||
switch (mode)
|
||||
{
|
||||
@ -112,32 +112,32 @@ SPDLOG_INLINE void ansicolor_sink<ConsoleMutex>::set_color_mode(color_mode mode)
|
||||
}
|
||||
|
||||
template<typename ConsoleMutex>
|
||||
SPDLOG_INLINE 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>
|
||||
SPDLOG_INLINE 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>
|
||||
SPDLOG_INLINE 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>
|
||||
SPDLOG_INLINE 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>
|
||||
SPDLOG_INLINE 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)
|
||||
{}
|
||||
|
||||
|
@ -13,51 +13,51 @@
|
||||
#include <memory>
|
||||
|
||||
template<typename Mutex>
|
||||
SPDLOG_INLINE 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_INLINE 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_INLINE 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_INLINE 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_INLINE 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_INLINE 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_INLINE 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));
|
||||
}
|
||||
|
||||
template<typename Mutex>
|
||||
void SPDLOG_INLINE 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)
|
||||
{
|
||||
formatter_ = std::move(sink_formatter);
|
||||
}
|
||||
|
@ -14,20 +14,20 @@ namespace spdlog {
|
||||
namespace sinks {
|
||||
|
||||
template<typename Mutex>
|
||||
SPDLOG_INLINE 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>
|
||||
SPDLOG_INLINE 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>
|
||||
SPDLOG_INLINE 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);
|
||||
@ -35,7 +35,7 @@ SPDLOG_INLINE void basic_file_sink<Mutex>::sink_it_(const details::log_msg &msg)
|
||||
}
|
||||
|
||||
template<typename Mutex>
|
||||
SPDLOG_INLINE void basic_file_sink<Mutex>::flush_()
|
||||
void basic_file_sink<Mutex>::flush_()
|
||||
{
|
||||
file_helper_.flush();
|
||||
}
|
||||
|
@ -24,7 +24,7 @@ namespace spdlog {
|
||||
namespace sinks {
|
||||
|
||||
template<typename Mutex>
|
||||
SPDLOG_INLINE 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)
|
||||
@ -52,7 +52,7 @@ SPDLOG_INLINE rotating_file_sink<Mutex>::rotating_file_sink(
|
||||
// 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>
|
||||
SPDLOG_INLINE 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)
|
||||
{
|
||||
@ -65,14 +65,14 @@ SPDLOG_INLINE filename_t rotating_file_sink<Mutex>::calc_filename(const filename
|
||||
}
|
||||
|
||||
template<typename Mutex>
|
||||
SPDLOG_INLINE 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>
|
||||
SPDLOG_INLINE 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);
|
||||
@ -95,7 +95,7 @@ SPDLOG_INLINE void rotating_file_sink<Mutex>::sink_it_(const details::log_msg &m
|
||||
}
|
||||
|
||||
template<typename Mutex>
|
||||
SPDLOG_INLINE void rotating_file_sink<Mutex>::flush_()
|
||||
void rotating_file_sink<Mutex>::flush_()
|
||||
{
|
||||
file_helper_.flush();
|
||||
}
|
||||
@ -106,7 +106,7 @@ SPDLOG_INLINE void rotating_file_sink<Mutex>::flush_()
|
||||
// log.2.txt -> log.3.txt
|
||||
// log.3.txt -> delete
|
||||
template<typename Mutex>
|
||||
SPDLOG_INLINE void rotating_file_sink<Mutex>::rotate_()
|
||||
void rotating_file_sink<Mutex>::rotate_()
|
||||
{
|
||||
using details::os::filename_to_str;
|
||||
using details::os::path_exists;
|
||||
@ -141,7 +141,7 @@ SPDLOG_INLINE void rotating_file_sink<Mutex>::rotate_()
|
||||
// delete the target if exists, and rename the src file to target
|
||||
// return true on success, false otherwise.
|
||||
template<typename Mutex>
|
||||
SPDLOG_INLINE 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);
|
||||
|
@ -9,16 +9,16 @@
|
||||
|
||||
#include <spdlog/common.h>
|
||||
|
||||
SPDLOG_INLINE 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);
|
||||
}
|
||||
|
||||
SPDLOG_INLINE void spdlog::sinks::sink::set_level(level level)
|
||||
void spdlog::sinks::sink::set_level(level level)
|
||||
{
|
||||
level_.store(level, std::memory_order_relaxed);
|
||||
}
|
||||
|
||||
SPDLOG_INLINE 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));
|
||||
}
|
||||
|
@ -13,25 +13,25 @@
|
||||
namespace spdlog {
|
||||
|
||||
template<typename Factory>
|
||||
SPDLOG_INLINE std::shared_ptr<logger> stdout_color_mt(const std::string &logger_name, color_mode mode)
|
||||
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>
|
||||
SPDLOG_INLINE std::shared_ptr<logger> stdout_color_st(const std::string &logger_name, color_mode mode)
|
||||
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>
|
||||
SPDLOG_INLINE std::shared_ptr<logger> stderr_color_mt(const std::string &logger_name, color_mode mode)
|
||||
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>
|
||||
SPDLOG_INLINE std::shared_ptr<logger> stderr_color_st(const std::string &logger_name, color_mode mode)
|
||||
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);
|
||||
}
|
||||
|
@ -29,7 +29,7 @@ namespace spdlog {
|
||||
namespace sinks {
|
||||
|
||||
template<typename ConsoleMutex>
|
||||
SPDLOG_INLINE stdout_sink_base<ConsoleMutex>::stdout_sink_base(FILE *file)
|
||||
stdout_sink_base<ConsoleMutex>::stdout_sink_base(FILE *file)
|
||||
: mutex_(ConsoleMutex::mutex())
|
||||
, file_(file)
|
||||
, formatter_(std::make_unique<spdlog::pattern_formatter>())
|
||||
@ -50,7 +50,7 @@ SPDLOG_INLINE stdout_sink_base<ConsoleMutex>::stdout_sink_base(FILE *file)
|
||||
}
|
||||
|
||||
template<typename ConsoleMutex>
|
||||
SPDLOG_INLINE void stdout_sink_base<ConsoleMutex>::log(const details::log_msg &msg)
|
||||
void stdout_sink_base<ConsoleMutex>::log(const details::log_msg &msg)
|
||||
{
|
||||
#ifdef _WIN32
|
||||
if (handle_ == INVALID_HANDLE_VALUE)
|
||||
@ -77,21 +77,21 @@ SPDLOG_INLINE void stdout_sink_base<ConsoleMutex>::log(const details::log_msg &m
|
||||
}
|
||||
|
||||
template<typename ConsoleMutex>
|
||||
SPDLOG_INLINE void stdout_sink_base<ConsoleMutex>::flush()
|
||||
void stdout_sink_base<ConsoleMutex>::flush()
|
||||
{
|
||||
std::lock_guard<mutex_t> lock(mutex_);
|
||||
fflush(file_);
|
||||
}
|
||||
|
||||
template<typename ConsoleMutex>
|
||||
SPDLOG_INLINE void stdout_sink_base<ConsoleMutex>::set_pattern(const std::string &pattern)
|
||||
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>
|
||||
SPDLOG_INLINE void stdout_sink_base<ConsoleMutex>::set_formatter(std::unique_ptr<spdlog::formatter> sink_formatter)
|
||||
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);
|
||||
@ -99,13 +99,13 @@ SPDLOG_INLINE void stdout_sink_base<ConsoleMutex>::set_formatter(std::unique_ptr
|
||||
|
||||
// stdout sink
|
||||
template<typename ConsoleMutex>
|
||||
SPDLOG_INLINE stdout_sink<ConsoleMutex>::stdout_sink()
|
||||
stdout_sink<ConsoleMutex>::stdout_sink()
|
||||
: stdout_sink_base<ConsoleMutex>(stdout)
|
||||
{}
|
||||
|
||||
// stderr sink
|
||||
template<typename ConsoleMutex>
|
||||
SPDLOG_INLINE stderr_sink<ConsoleMutex>::stderr_sink()
|
||||
stderr_sink<ConsoleMutex>::stderr_sink()
|
||||
: stdout_sink_base<ConsoleMutex>(stderr)
|
||||
{}
|
||||
|
||||
@ -113,25 +113,25 @@ SPDLOG_INLINE stderr_sink<ConsoleMutex>::stderr_sink()
|
||||
|
||||
// factory methods
|
||||
template<typename Factory>
|
||||
SPDLOG_INLINE std::shared_ptr<logger> stdout_logger_mt(const std::string &logger_name)
|
||||
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>
|
||||
SPDLOG_INLINE std::shared_ptr<logger> stdout_logger_st(const std::string &logger_name)
|
||||
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>
|
||||
SPDLOG_INLINE std::shared_ptr<logger> stderr_logger_mt(const std::string &logger_name)
|
||||
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>
|
||||
SPDLOG_INLINE std::shared_ptr<logger> stderr_logger_st(const std::string &logger_name)
|
||||
std::shared_ptr<logger> stderr_logger_st(const std::string &logger_name)
|
||||
{
|
||||
return Factory::template create<sinks::stderr_sink_st>(logger_name);
|
||||
}
|
||||
|
@ -16,7 +16,7 @@
|
||||
namespace spdlog {
|
||||
namespace sinks {
|
||||
template<typename ConsoleMutex>
|
||||
SPDLOG_INLINE 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>())
|
||||
@ -35,21 +35,21 @@ SPDLOG_INLINE wincolor_sink<ConsoleMutex>::wincolor_sink(void *out_handle, color
|
||||
}
|
||||
|
||||
template<typename ConsoleMutex>
|
||||
SPDLOG_INLINE wincolor_sink<ConsoleMutex>::~wincolor_sink()
|
||||
wincolor_sink<ConsoleMutex>::~wincolor_sink()
|
||||
{
|
||||
this->flush();
|
||||
}
|
||||
|
||||
// change the color for the given level
|
||||
template<typename ConsoleMutex>
|
||||
void SPDLOG_INLINE 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 SPDLOG_INLINE 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)
|
||||
{
|
||||
@ -79,34 +79,34 @@ void SPDLOG_INLINE wincolor_sink<ConsoleMutex>::log(const details::log_msg &msg)
|
||||
}
|
||||
|
||||
template<typename ConsoleMutex>
|
||||
void SPDLOG_INLINE wincolor_sink<ConsoleMutex>::flush()
|
||||
void wincolor_sink<ConsoleMutex>::flush()
|
||||
{
|
||||
// windows console always flushed?
|
||||
}
|
||||
|
||||
template<typename ConsoleMutex>
|
||||
void SPDLOG_INLINE 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 SPDLOG_INLINE 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 SPDLOG_INLINE 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 SPDLOG_INLINE 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)
|
||||
{
|
||||
@ -123,7 +123,7 @@ void SPDLOG_INLINE wincolor_sink<ConsoleMutex>::set_color_mode_impl(color_mode m
|
||||
|
||||
// set foreground color and return the orig console attributes (for resetting later)
|
||||
template<typename ConsoleMutex>
|
||||
std::uint16_t SPDLOG_INLINE 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))
|
||||
@ -141,7 +141,7 @@ std::uint16_t SPDLOG_INLINE wincolor_sink<ConsoleMutex>::set_foreground_color_(s
|
||||
|
||||
// print a range of formatted message to console
|
||||
template<typename ConsoleMutex>
|
||||
void SPDLOG_INLINE 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)
|
||||
{
|
||||
@ -152,7 +152,7 @@ void SPDLOG_INLINE wincolor_sink<ConsoleMutex>::print_range_(const memory_buf_t
|
||||
}
|
||||
|
||||
template<typename ConsoleMutex>
|
||||
void SPDLOG_INLINE 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;
|
||||
@ -162,13 +162,13 @@ void SPDLOG_INLINE wincolor_sink<ConsoleMutex>::write_to_file_(const memory_buf_
|
||||
|
||||
// wincolor_stdout_sink
|
||||
template<typename ConsoleMutex>
|
||||
SPDLOG_INLINE 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>
|
||||
SPDLOG_INLINE 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
|
||||
|
@ -12,97 +12,97 @@
|
||||
|
||||
namespace spdlog {
|
||||
|
||||
SPDLOG_INLINE void initialize_logger(std::shared_ptr<logger> logger)
|
||||
void initialize_logger(std::shared_ptr<logger> logger)
|
||||
{
|
||||
details::registry::instance().initialize_logger(std::move(logger));
|
||||
}
|
||||
|
||||
SPDLOG_INLINE std::shared_ptr<logger> get(const std::string &name)
|
||||
std::shared_ptr<logger> get(const std::string &name)
|
||||
{
|
||||
return details::registry::instance().get(name);
|
||||
}
|
||||
|
||||
SPDLOG_INLINE 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));
|
||||
}
|
||||
|
||||
SPDLOG_INLINE 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)));
|
||||
}
|
||||
|
||||
SPDLOG_INLINE level get_level()
|
||||
level get_level()
|
||||
{
|
||||
return default_logger_raw()->log_level();
|
||||
}
|
||||
|
||||
SPDLOG_INLINE bool should_log(level level)
|
||||
bool should_log(level level)
|
||||
{
|
||||
return default_logger_raw()->should_log(level);
|
||||
}
|
||||
|
||||
SPDLOG_INLINE void set_level(level level)
|
||||
void set_level(level level)
|
||||
{
|
||||
details::registry::instance().set_level(level);
|
||||
}
|
||||
|
||||
SPDLOG_INLINE void flush_on(level level)
|
||||
void flush_on(level level)
|
||||
{
|
||||
details::registry::instance().flush_on(level);
|
||||
}
|
||||
|
||||
SPDLOG_INLINE 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);
|
||||
}
|
||||
|
||||
SPDLOG_INLINE void register_logger(std::shared_ptr<logger> logger)
|
||||
void register_logger(std::shared_ptr<logger> logger)
|
||||
{
|
||||
details::registry::instance().register_logger(std::move(logger));
|
||||
}
|
||||
|
||||
SPDLOG_INLINE 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);
|
||||
}
|
||||
|
||||
SPDLOG_INLINE void drop(const std::string &name)
|
||||
void drop(const std::string &name)
|
||||
{
|
||||
details::registry::instance().drop(name);
|
||||
}
|
||||
|
||||
SPDLOG_INLINE void drop_all()
|
||||
void drop_all()
|
||||
{
|
||||
details::registry::instance().drop_all();
|
||||
}
|
||||
|
||||
SPDLOG_INLINE void shutdown()
|
||||
void shutdown()
|
||||
{
|
||||
details::registry::instance().shutdown();
|
||||
}
|
||||
|
||||
SPDLOG_INLINE void set_automatic_registration(bool automatic_registration)
|
||||
void set_automatic_registration(bool automatic_registration)
|
||||
{
|
||||
details::registry::instance().set_automatic_registration(automatic_registration);
|
||||
}
|
||||
|
||||
SPDLOG_INLINE std::shared_ptr<spdlog::logger> default_logger()
|
||||
std::shared_ptr<spdlog::logger> default_logger()
|
||||
{
|
||||
return details::registry::instance().default_logger();
|
||||
}
|
||||
|
||||
SPDLOG_INLINE spdlog::logger *default_logger_raw()
|
||||
spdlog::logger *default_logger_raw()
|
||||
{
|
||||
return details::registry::instance().get_default_raw();
|
||||
}
|
||||
|
||||
SPDLOG_INLINE 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));
|
||||
}
|
||||
|
||||
SPDLOG_INLINE 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));
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user