mirror of
https://github.com/gabime/spdlog.git
synced 2025-11-16 09:28:56 +08:00
update clang format again
This commit is contained in:
@@ -83,7 +83,7 @@ void load_levels(const std::string &input) {
|
||||
if (level == level::off && level_name != "off") {
|
||||
continue;
|
||||
}
|
||||
if (logger_name.empty()) // no logger name indicate global level
|
||||
if (logger_name.empty()) // no logger name indicate global level
|
||||
{
|
||||
global_level_found = true;
|
||||
global_level = level;
|
||||
@@ -96,6 +96,6 @@ void load_levels(const std::string &input) {
|
||||
global_level_found ? &global_level : nullptr);
|
||||
}
|
||||
|
||||
} // namespace helpers
|
||||
} // namespace cfg
|
||||
} // namespace spdlog
|
||||
} // namespace helpers
|
||||
} // namespace cfg
|
||||
} // namespace spdlog
|
||||
|
||||
@@ -44,4 +44,4 @@ void throw_spdlog_ex(const std::string &msg, int last_errno) {
|
||||
|
||||
void throw_spdlog_ex(std::string msg) { SPDLOG_THROW(spdlog_ex(std::move(msg))); }
|
||||
|
||||
} // namespace spdlog
|
||||
} // namespace spdlog
|
||||
|
||||
@@ -139,5 +139,5 @@ std::tuple<filename_t, filename_t> file_helper::split_by_extension(const filenam
|
||||
return std::make_tuple(fname.substr(0, ext_index), fname.substr(ext_index));
|
||||
}
|
||||
|
||||
} // namespace details
|
||||
} // namespace spdlog
|
||||
} // namespace details
|
||||
} // namespace spdlog
|
||||
|
||||
@@ -33,5 +33,5 @@ log_msg::log_msg(spdlog::source_loc loc,
|
||||
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) {}
|
||||
|
||||
} // namespace details
|
||||
} // namespace spdlog
|
||||
} // namespace details
|
||||
} // namespace spdlog
|
||||
|
||||
@@ -46,5 +46,5 @@ void log_msg_buffer::update_string_views() {
|
||||
payload = string_view_t{buffer.data() + logger_name.size(), payload.size()};
|
||||
}
|
||||
|
||||
} // namespace details
|
||||
} // namespace spdlog
|
||||
} // namespace details
|
||||
} // namespace spdlog
|
||||
|
||||
@@ -17,9 +17,9 @@
|
||||
|
||||
#ifdef _WIN32
|
||||
#include <spdlog/details/windows_include.h>
|
||||
#include <fileapi.h> // for FlushFileBuffers
|
||||
#include <io.h> // for _get_osfhandle, _isatty, _fileno
|
||||
#include <process.h> // for _get_pid
|
||||
#include <fileapi.h> // for FlushFileBuffers
|
||||
#include <io.h> // for _get_osfhandle, _isatty, _fileno
|
||||
#include <process.h> // for _get_pid
|
||||
|
||||
#ifdef __MINGW32__
|
||||
#include <share.h>
|
||||
@@ -30,37 +30,37 @@
|
||||
#include <limits>
|
||||
#endif
|
||||
|
||||
#include <direct.h> // for _mkdir/_wmkdir
|
||||
#include <direct.h> // for _mkdir/_wmkdir
|
||||
|
||||
#else // unix
|
||||
#else // unix
|
||||
|
||||
#include <fcntl.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#ifdef __linux__
|
||||
#include <sys/syscall.h> //Use gettid() syscall under linux to get thread id
|
||||
#include <sys/syscall.h> //Use gettid() syscall under linux to get thread id
|
||||
|
||||
#elif defined(_AIX)
|
||||
#include <pthread.h> // for pthread_getthrds_np
|
||||
#include <pthread.h> // for pthread_getthrds_np
|
||||
|
||||
#elif defined(__DragonFly__) || defined(__FreeBSD__)
|
||||
#include <pthread_np.h> // for pthread_getthreadid_np
|
||||
#include <pthread_np.h> // for pthread_getthreadid_np
|
||||
|
||||
#elif defined(__NetBSD__)
|
||||
#include <lwp.h> // for _lwp_self
|
||||
#include <lwp.h> // for _lwp_self
|
||||
|
||||
#elif defined(__sun)
|
||||
#include <thread.h> // for thr_self
|
||||
#include <thread.h> // for thr_self
|
||||
#endif
|
||||
|
||||
#endif // unix
|
||||
#endif // unix
|
||||
|
||||
#if defined __APPLE__
|
||||
#include <AvailabilityMacros.h>
|
||||
#endif
|
||||
|
||||
#ifndef __has_feature // Clang - feature checking macros.
|
||||
#define __has_feature(x) 0 // Compatibility with non-clang compilers.
|
||||
#ifndef __has_feature // Clang - feature checking macros.
|
||||
#define __has_feature(x) 0 // Compatibility with non-clang compilers.
|
||||
#endif
|
||||
|
||||
namespace spdlog {
|
||||
@@ -68,7 +68,6 @@ namespace details {
|
||||
namespace os {
|
||||
|
||||
spdlog::log_clock::time_point now() noexcept {
|
||||
|
||||
#if defined __linux__ && defined SPDLOG_CLOCK_COARSE
|
||||
timespec ts;
|
||||
::clock_gettime(CLOCK_REALTIME_COARSE, &ts);
|
||||
@@ -81,7 +80,6 @@ spdlog::log_clock::time_point now() noexcept {
|
||||
#endif
|
||||
}
|
||||
std::tm localtime(const std::time_t &time_tt) noexcept {
|
||||
|
||||
#ifdef _WIN32
|
||||
std::tm tm;
|
||||
::localtime_s(&tm, &time_tt);
|
||||
@@ -98,7 +96,6 @@ std::tm localtime() noexcept {
|
||||
}
|
||||
|
||||
std::tm gmtime(const std::time_t &time_tt) noexcept {
|
||||
|
||||
#ifdef _WIN32
|
||||
std::tm tm;
|
||||
::gmtime_s(&tm, &time_tt);
|
||||
@@ -131,7 +128,7 @@ bool fopen_s(FILE **fp, const filename_t &filename, const filename_t &mode) {
|
||||
}
|
||||
}
|
||||
#endif
|
||||
#else // unix
|
||||
#else // unix
|
||||
#if defined(SPDLOG_PREVENT_CHILD_FD)
|
||||
const int mode_flag = mode == SPDLOG_FILENAME_T("ab") ? O_APPEND : O_TRUNC;
|
||||
const int fd =
|
||||
@@ -180,7 +177,7 @@ bool path_exists(const filename_t &filename) noexcept {
|
||||
auto attribs = ::GetFileAttributesA(filename.c_str());
|
||||
#endif
|
||||
return attribs != INVALID_FILE_ATTRIBUTES;
|
||||
#else // common linux/unix all have the stat system call
|
||||
#else // common linux/unix all have the stat system call
|
||||
struct stat buffer;
|
||||
return (::stat(filename.c_str(), &buffer) == 0);
|
||||
#endif
|
||||
@@ -199,20 +196,20 @@ size_t filesize(FILE *f) {
|
||||
}
|
||||
#if defined(_WIN32) && !defined(__CYGWIN__)
|
||||
int fd = ::_fileno(f);
|
||||
#if defined(_WIN64) // 64 bits
|
||||
#if defined(_WIN64) // 64 bits
|
||||
__int64 ret = ::_filelengthi64(fd);
|
||||
if (ret >= 0) {
|
||||
return static_cast<size_t>(ret);
|
||||
}
|
||||
|
||||
#else // windows 32 bits
|
||||
#else // windows 32 bits
|
||||
long ret = ::_filelength(fd);
|
||||
if (ret >= 0) {
|
||||
return static_cast<size_t>(ret);
|
||||
}
|
||||
#endif
|
||||
|
||||
#else // unix
|
||||
#else // unix
|
||||
// OpenBSD and AIX doesn't compile with :: before the fileno(..)
|
||||
#if defined(__OpenBSD__) || defined(_AIX)
|
||||
int fd = fileno(f);
|
||||
@@ -226,7 +223,7 @@ size_t filesize(FILE *f) {
|
||||
if (::fstat64(fd, &st) == 0) {
|
||||
return static_cast<size_t>(st.st_size);
|
||||
}
|
||||
#else // other unix or linux 32 bits or cygwin
|
||||
#else // other unix or linux 32 bits or cygwin
|
||||
struct stat st;
|
||||
if (::fstat(fd, &st) == 0) {
|
||||
return static_cast<size_t>(st.st_size);
|
||||
@@ -234,7 +231,7 @@ size_t filesize(FILE *f) {
|
||||
#endif
|
||||
#endif
|
||||
throw_spdlog_ex("Failed getting file size from fd", errno);
|
||||
return 0; // will not be reached.
|
||||
return 0; // will not be reached.
|
||||
}
|
||||
|
||||
#ifdef _MSC_VER
|
||||
@@ -243,7 +240,6 @@ size_t filesize(FILE *f) {
|
||||
|
||||
// Return utc offset in minutes or throw spdlog_ex on failure
|
||||
int utc_minutes_offset(const std::tm &tm) {
|
||||
|
||||
#ifdef _WIN32
|
||||
#if _WIN32_WINNT < _WIN32_WINNT_WS08
|
||||
TIME_ZONE_INFORMATION tzinfo;
|
||||
@@ -252,8 +248,7 @@ int utc_minutes_offset(const std::tm &tm) {
|
||||
DYNAMIC_TIME_ZONE_INFORMATION tzinfo;
|
||||
auto rv = ::GetDynamicTimeZoneInformation(&tzinfo);
|
||||
#endif
|
||||
if (rv == TIME_ZONE_ID_INVALID)
|
||||
throw_spdlog_ex("Failed getting timezone info. ", errno);
|
||||
if (rv == TIME_ZONE_ID_INVALID) throw_spdlog_ex("Failed getting timezone info. ", errno);
|
||||
|
||||
int offset = -tzinfo.Bias;
|
||||
if (tm.tm_isdst) {
|
||||
@@ -345,7 +340,7 @@ size_t _thread_id() noexcept {
|
||||
pthread_threadid_np(nullptr, &tid);
|
||||
#endif
|
||||
return static_cast<size_t>(tid);
|
||||
#else // Default to standard C++11 (other Unix)
|
||||
#else // Default to standard C++11 (other Unix)
|
||||
return static_cast<size_t>(std::hash<std::thread::id>()(std::this_thread::get_id()));
|
||||
#endif
|
||||
}
|
||||
@@ -379,7 +374,6 @@ std::string filename_to_str(const filename_t &filename) { return filename; }
|
||||
#endif
|
||||
|
||||
int pid() noexcept {
|
||||
|
||||
#ifdef _WIN32
|
||||
return static_cast<int>(::GetCurrentProcessId());
|
||||
#else
|
||||
@@ -421,7 +415,6 @@ bool is_color_terminal() noexcept {
|
||||
// Determine if the terminal attached
|
||||
// Source: https://github.com/agauniyal/rang/
|
||||
bool in_terminal(FILE *file) noexcept {
|
||||
|
||||
#ifdef _WIN32
|
||||
return ::_isatty(_fileno(file)) != 0;
|
||||
#else
|
||||
@@ -490,7 +483,7 @@ void utf8_to_wstrbuf(string_view_t str, wmemory_buf_t &target) {
|
||||
throw_spdlog_ex(
|
||||
fmt_lib::format("MultiByteToWideChar failed. Last error: {}", ::GetLastError()));
|
||||
}
|
||||
#endif // defined(SPDLOG_WCHAR_FILENAMES) && defined(_WIN32)
|
||||
#endif // defined(SPDLOG_WCHAR_FILENAMES) && defined(_WIN32)
|
||||
|
||||
// return true on success
|
||||
static bool mkdir_(const filename_t &path) {
|
||||
@@ -527,7 +520,7 @@ bool create_dir(const filename_t &path) {
|
||||
auto subdir = path.substr(0, token_pos);
|
||||
|
||||
if (!subdir.empty() && !path_exists(subdir) && !mkdir_(subdir)) {
|
||||
return false; // return error if failed creating dir
|
||||
return false; // return error if failed creating dir
|
||||
}
|
||||
search_offset = token_pos + 1;
|
||||
} while (search_offset < path.size());
|
||||
@@ -546,17 +539,16 @@ filename_t dir_name(const filename_t &path) {
|
||||
}
|
||||
|
||||
std::string getenv(const char *field) {
|
||||
|
||||
#if defined(_MSC_VER)
|
||||
#if defined(__cplusplus_winrt)
|
||||
return std::string{}; // not supported under uwp
|
||||
return std::string{}; // not supported under uwp
|
||||
#else
|
||||
size_t len = 0;
|
||||
char buf[128];
|
||||
bool ok = ::getenv_s(&len, buf, sizeof(buf), field) == 0;
|
||||
return ok ? buf : std::string{};
|
||||
#endif
|
||||
#else // revert to getenv
|
||||
#else // revert to getenv
|
||||
char *buf = ::getenv(field);
|
||||
return buf ? buf : std::string{};
|
||||
#endif
|
||||
@@ -572,6 +564,6 @@ bool fsync(FILE *fp) {
|
||||
#endif
|
||||
}
|
||||
|
||||
} // namespace os
|
||||
} // namespace details
|
||||
} // namespace spdlog
|
||||
} // namespace os
|
||||
} // namespace details
|
||||
} // namespace spdlog
|
||||
|
||||
@@ -18,5 +18,5 @@ periodic_worker::~periodic_worker() {
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace details
|
||||
} // namespace spdlog
|
||||
} // namespace details
|
||||
} // namespace spdlog
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
#else
|
||||
#include <spdlog/sinks/ansicolor_sink.h>
|
||||
#endif
|
||||
#endif // SPDLOG_DISABLE_DEFAULT_LOGGER
|
||||
#endif // SPDLOG_DISABLE_DEFAULT_LOGGER
|
||||
|
||||
#include <chrono>
|
||||
#include <functional>
|
||||
@@ -28,7 +28,6 @@ namespace details {
|
||||
|
||||
registry::registry()
|
||||
: formatter_(new pattern_formatter()) {
|
||||
|
||||
#ifndef SPDLOG_DISABLE_DEFAULT_LOGGER
|
||||
// create default logger (ansicolor_stdout_sink_mt or wincolor_stdout_sink_mt in windows).
|
||||
#ifdef _WIN32
|
||||
@@ -41,7 +40,7 @@ registry::registry()
|
||||
default_logger_ = std::make_shared<spdlog::logger>(default_logger_name, std::move(color_sink));
|
||||
loggers_[default_logger_name] = default_logger_;
|
||||
|
||||
#endif // SPDLOG_DISABLE_DEFAULT_LOGGER
|
||||
#endif // SPDLOG_DISABLE_DEFAULT_LOGGER
|
||||
}
|
||||
|
||||
registry::~registry() = default;
|
||||
@@ -236,5 +235,5 @@ void registry::register_logger_(std::shared_ptr<logger> new_logger) {
|
||||
loggers_[logger_name] = std::move(new_logger);
|
||||
}
|
||||
|
||||
} // namespace details
|
||||
} // namespace spdlog
|
||||
} // namespace details
|
||||
} // namespace spdlog
|
||||
|
||||
@@ -14,8 +14,9 @@ thread_pool::thread_pool(size_t q_max_items,
|
||||
std::function<void()> on_thread_stop)
|
||||
: q_(q_max_items) {
|
||||
if (threads_n == 0 || threads_n > 1000) {
|
||||
throw_spdlog_ex("spdlog::thread_pool(): invalid threads_n param (valid "
|
||||
"range is 1-1000)");
|
||||
throw_spdlog_ex(
|
||||
"spdlog::thread_pool(): invalid threads_n param (valid "
|
||||
"range is 1-1000)");
|
||||
}
|
||||
for (size_t i = 0; i < threads_n; i++) {
|
||||
threads_.emplace_back([this, on_thread_start, on_thread_stop] {
|
||||
@@ -94,26 +95,26 @@ bool thread_pool::process_next_msg_() {
|
||||
q_.dequeue(incoming_async_msg);
|
||||
|
||||
switch (incoming_async_msg.msg_type) {
|
||||
case async_msg_type::log: {
|
||||
incoming_async_msg.worker_ptr->backend_sink_it_(incoming_async_msg);
|
||||
return true;
|
||||
}
|
||||
case async_msg_type::flush: {
|
||||
incoming_async_msg.worker_ptr->backend_flush_();
|
||||
return true;
|
||||
}
|
||||
case async_msg_type::log: {
|
||||
incoming_async_msg.worker_ptr->backend_sink_it_(incoming_async_msg);
|
||||
return true;
|
||||
}
|
||||
case async_msg_type::flush: {
|
||||
incoming_async_msg.worker_ptr->backend_flush_();
|
||||
return true;
|
||||
}
|
||||
|
||||
case async_msg_type::terminate: {
|
||||
return false;
|
||||
}
|
||||
case async_msg_type::terminate: {
|
||||
return false;
|
||||
}
|
||||
|
||||
default: {
|
||||
assert(false);
|
||||
}
|
||||
default: {
|
||||
assert(false);
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
} // namespace details
|
||||
} // namespace spdlog
|
||||
} // namespace details
|
||||
} // namespace spdlog
|
||||
|
||||
@@ -23,8 +23,10 @@ template FMT_API auto decimal_point_impl(locale_ref) -> char;
|
||||
|
||||
template FMT_API void buffer<char>::append(const char *, const char *);
|
||||
|
||||
template FMT_API void
|
||||
vformat_to(buffer<char> &, string_view, typename vformat_args<>::type, locale_ref);
|
||||
template FMT_API void vformat_to(buffer<char> &,
|
||||
string_view,
|
||||
typename vformat_args<>::type,
|
||||
locale_ref);
|
||||
|
||||
// Explicit instantiations for wchar_t.
|
||||
|
||||
@@ -33,7 +35,7 @@ template FMT_API auto decimal_point_impl(locale_ref) -> wchar_t;
|
||||
|
||||
template FMT_API void buffer<wchar_t>::append(const wchar_t *, const wchar_t *);
|
||||
|
||||
} // namespace detail
|
||||
} // namespace detail
|
||||
FMT_END_NAMESPACE
|
||||
|
||||
#endif // !SPDLOG_FMT_EXTERNAL
|
||||
#endif // !SPDLOG_FMT_EXTERNAL
|
||||
|
||||
@@ -38,7 +38,7 @@ void logger::set_formatter(std::unique_ptr<formatter> f) {
|
||||
if (std::next(it) == sinks_.end()) {
|
||||
// last element - we can be move it.
|
||||
(*it)->set_formatter(std::move(f));
|
||||
break; // to prevent clang-tidy warning
|
||||
break; // to prevent clang-tidy warning
|
||||
} else {
|
||||
(*it)->set_formatter(f->clone());
|
||||
}
|
||||
@@ -102,7 +102,7 @@ void logger::err_handler_(const std::string &msg) {
|
||||
auto tm_time = details::os::localtime(system_clock::to_time_t(now));
|
||||
char date_buf[64];
|
||||
std::strftime(date_buf, sizeof(date_buf), "%Y-%m-%d %H:%M:%S", &tm_time);
|
||||
#if defined(USING_R) && defined(R_R_H) // if in R environment
|
||||
#if defined(USING_R) && defined(R_R_H) // if in R environment
|
||||
REprintf("[*** LOG ERROR #%04zu ***] [%s] [%s] %s\n", err_counter, date_buf, name().c_str(),
|
||||
msg.c_str());
|
||||
#else
|
||||
@@ -111,4 +111,4 @@ void logger::err_handler_(const std::string &msg) {
|
||||
#endif
|
||||
}
|
||||
}
|
||||
} // namespace spdlog
|
||||
} // namespace spdlog
|
||||
|
||||
@@ -41,7 +41,7 @@ public:
|
||||
auto half_pad = remaining_pad_ / 2;
|
||||
auto reminder = remaining_pad_ & 1;
|
||||
pad_it(half_pad);
|
||||
remaining_pad_ = half_pad + reminder; // for the right side
|
||||
remaining_pad_ = half_pad + reminder; // for the right side
|
||||
}
|
||||
}
|
||||
|
||||
@@ -515,9 +515,9 @@ public:
|
||||
dest.push_back('+');
|
||||
}
|
||||
|
||||
fmt_helper::pad2(total_minutes / 60, dest); // hours
|
||||
fmt_helper::pad2(total_minutes / 60, dest); // hours
|
||||
dest.push_back(':');
|
||||
fmt_helper::pad2(total_minutes % 60, dest); // minutes
|
||||
fmt_helper::pad2(total_minutes % 60, dest); // minutes
|
||||
}
|
||||
|
||||
private:
|
||||
@@ -679,8 +679,8 @@ public:
|
||||
|
||||
#ifdef _MSC_VER
|
||||
#pragma warning(push)
|
||||
#pragma warning(disable : 4127) // consider using 'if constexpr' instead
|
||||
#endif // _MSC_VER
|
||||
#pragma warning(disable : 4127) // consider using 'if constexpr' instead
|
||||
#endif // _MSC_VER
|
||||
static const char *basename(const char *filename) {
|
||||
// if the size is 2 (1 character + null terminator) we can use the more efficient strrchr
|
||||
// the branch will be elided by optimizations
|
||||
@@ -698,7 +698,7 @@ public:
|
||||
}
|
||||
#ifdef _MSC_VER
|
||||
#pragma warning(pop)
|
||||
#endif // _MSC_VER
|
||||
#endif // _MSC_VER
|
||||
|
||||
void format(const details::log_msg &msg, const std::tm &, memory_buf_t &dest) override {
|
||||
if (msg.source.empty()) {
|
||||
@@ -857,7 +857,7 @@ private:
|
||||
memory_buf_t cached_datetime_;
|
||||
};
|
||||
|
||||
} // namespace details
|
||||
} // namespace details
|
||||
|
||||
pattern_formatter::pattern_formatter(std::string pattern,
|
||||
pattern_time_type time_type,
|
||||
@@ -944,227 +944,231 @@ void pattern_formatter::handle_flag_(char flag, details::padding_info padding) {
|
||||
|
||||
// process built-in flags
|
||||
switch (flag) {
|
||||
case ('+'): // default formatter
|
||||
formatters_.push_back(std::make_unique<details::full_formatter>(padding));
|
||||
need_localtime_ = true;
|
||||
break;
|
||||
case ('+'): // default formatter
|
||||
formatters_.push_back(std::make_unique<details::full_formatter>(padding));
|
||||
need_localtime_ = true;
|
||||
break;
|
||||
|
||||
case 'n': // logger name
|
||||
formatters_.push_back(std::make_unique<details::name_formatter<Padder>>(padding));
|
||||
break;
|
||||
case 'n': // logger name
|
||||
formatters_.push_back(std::make_unique<details::name_formatter<Padder>>(padding));
|
||||
break;
|
||||
|
||||
case 'l': // level
|
||||
formatters_.push_back(std::make_unique<details::level_formatter<Padder>>(padding));
|
||||
break;
|
||||
case 'l': // level
|
||||
formatters_.push_back(std::make_unique<details::level_formatter<Padder>>(padding));
|
||||
break;
|
||||
|
||||
case 'L': // short level
|
||||
formatters_.push_back(std::make_unique<details::short_level_formatter<Padder>>(padding));
|
||||
break;
|
||||
case 'L': // short level
|
||||
formatters_.push_back(
|
||||
std::make_unique<details::short_level_formatter<Padder>>(padding));
|
||||
break;
|
||||
|
||||
case ('t'): // thread id
|
||||
formatters_.push_back(std::make_unique<details::t_formatter<Padder>>(padding));
|
||||
break;
|
||||
case ('t'): // thread id
|
||||
formatters_.push_back(std::make_unique<details::t_formatter<Padder>>(padding));
|
||||
break;
|
||||
|
||||
case ('v'): // the message text
|
||||
formatters_.push_back(std::make_unique<details::v_formatter<Padder>>(padding));
|
||||
break;
|
||||
case ('v'): // the message text
|
||||
formatters_.push_back(std::make_unique<details::v_formatter<Padder>>(padding));
|
||||
break;
|
||||
|
||||
case ('a'): // weekday
|
||||
formatters_.push_back(std::make_unique<details::a_formatter<Padder>>(padding));
|
||||
need_localtime_ = true;
|
||||
break;
|
||||
case ('a'): // weekday
|
||||
formatters_.push_back(std::make_unique<details::a_formatter<Padder>>(padding));
|
||||
need_localtime_ = true;
|
||||
break;
|
||||
|
||||
case ('A'): // short weekday
|
||||
formatters_.push_back(std::make_unique<details::A_formatter<Padder>>(padding));
|
||||
need_localtime_ = true;
|
||||
break;
|
||||
case ('A'): // short weekday
|
||||
formatters_.push_back(std::make_unique<details::A_formatter<Padder>>(padding));
|
||||
need_localtime_ = true;
|
||||
break;
|
||||
|
||||
case ('b'):
|
||||
case ('h'): // month
|
||||
formatters_.push_back(std::make_unique<details::b_formatter<Padder>>(padding));
|
||||
need_localtime_ = true;
|
||||
break;
|
||||
case ('b'):
|
||||
case ('h'): // month
|
||||
formatters_.push_back(std::make_unique<details::b_formatter<Padder>>(padding));
|
||||
need_localtime_ = true;
|
||||
break;
|
||||
|
||||
case ('B'): // short month
|
||||
formatters_.push_back(std::make_unique<details::B_formatter<Padder>>(padding));
|
||||
need_localtime_ = true;
|
||||
break;
|
||||
case ('B'): // short month
|
||||
formatters_.push_back(std::make_unique<details::B_formatter<Padder>>(padding));
|
||||
need_localtime_ = true;
|
||||
break;
|
||||
|
||||
case ('c'): // datetime
|
||||
formatters_.push_back(std::make_unique<details::c_formatter<Padder>>(padding));
|
||||
need_localtime_ = true;
|
||||
break;
|
||||
case ('c'): // datetime
|
||||
formatters_.push_back(std::make_unique<details::c_formatter<Padder>>(padding));
|
||||
need_localtime_ = true;
|
||||
break;
|
||||
|
||||
case ('C'): // year 2 digits
|
||||
formatters_.push_back(std::make_unique<details::C_formatter<Padder>>(padding));
|
||||
need_localtime_ = true;
|
||||
break;
|
||||
case ('C'): // year 2 digits
|
||||
formatters_.push_back(std::make_unique<details::C_formatter<Padder>>(padding));
|
||||
need_localtime_ = true;
|
||||
break;
|
||||
|
||||
case ('Y'): // year 4 digits
|
||||
formatters_.push_back(std::make_unique<details::Y_formatter<Padder>>(padding));
|
||||
need_localtime_ = true;
|
||||
break;
|
||||
case ('Y'): // year 4 digits
|
||||
formatters_.push_back(std::make_unique<details::Y_formatter<Padder>>(padding));
|
||||
need_localtime_ = true;
|
||||
break;
|
||||
|
||||
case ('D'):
|
||||
case ('x'): // datetime MM/DD/YY
|
||||
formatters_.push_back(std::make_unique<details::D_formatter<Padder>>(padding));
|
||||
need_localtime_ = true;
|
||||
break;
|
||||
case ('D'):
|
||||
case ('x'): // datetime MM/DD/YY
|
||||
formatters_.push_back(std::make_unique<details::D_formatter<Padder>>(padding));
|
||||
need_localtime_ = true;
|
||||
break;
|
||||
|
||||
case ('m'): // month 1-12
|
||||
formatters_.push_back(std::make_unique<details::m_formatter<Padder>>(padding));
|
||||
need_localtime_ = true;
|
||||
break;
|
||||
case ('m'): // month 1-12
|
||||
formatters_.push_back(std::make_unique<details::m_formatter<Padder>>(padding));
|
||||
need_localtime_ = true;
|
||||
break;
|
||||
|
||||
case ('d'): // day of month 1-31
|
||||
formatters_.push_back(std::make_unique<details::d_formatter<Padder>>(padding));
|
||||
need_localtime_ = true;
|
||||
break;
|
||||
case ('d'): // day of month 1-31
|
||||
formatters_.push_back(std::make_unique<details::d_formatter<Padder>>(padding));
|
||||
need_localtime_ = true;
|
||||
break;
|
||||
|
||||
case ('H'): // hours 24
|
||||
formatters_.push_back(std::make_unique<details::H_formatter<Padder>>(padding));
|
||||
need_localtime_ = true;
|
||||
break;
|
||||
case ('H'): // hours 24
|
||||
formatters_.push_back(std::make_unique<details::H_formatter<Padder>>(padding));
|
||||
need_localtime_ = true;
|
||||
break;
|
||||
|
||||
case ('I'): // hours 12
|
||||
formatters_.push_back(std::make_unique<details::I_formatter<Padder>>(padding));
|
||||
need_localtime_ = true;
|
||||
break;
|
||||
case ('I'): // hours 12
|
||||
formatters_.push_back(std::make_unique<details::I_formatter<Padder>>(padding));
|
||||
need_localtime_ = true;
|
||||
break;
|
||||
|
||||
case ('M'): // minutes
|
||||
formatters_.push_back(std::make_unique<details::M_formatter<Padder>>(padding));
|
||||
need_localtime_ = true;
|
||||
break;
|
||||
case ('M'): // minutes
|
||||
formatters_.push_back(std::make_unique<details::M_formatter<Padder>>(padding));
|
||||
need_localtime_ = true;
|
||||
break;
|
||||
|
||||
case ('S'): // seconds
|
||||
formatters_.push_back(std::make_unique<details::S_formatter<Padder>>(padding));
|
||||
need_localtime_ = true;
|
||||
break;
|
||||
case ('S'): // seconds
|
||||
formatters_.push_back(std::make_unique<details::S_formatter<Padder>>(padding));
|
||||
need_localtime_ = true;
|
||||
break;
|
||||
|
||||
case ('e'): // milliseconds
|
||||
formatters_.push_back(std::make_unique<details::e_formatter<Padder>>(padding));
|
||||
break;
|
||||
case ('e'): // milliseconds
|
||||
formatters_.push_back(std::make_unique<details::e_formatter<Padder>>(padding));
|
||||
break;
|
||||
|
||||
case ('f'): // microseconds
|
||||
formatters_.push_back(std::make_unique<details::f_formatter<Padder>>(padding));
|
||||
break;
|
||||
case ('f'): // microseconds
|
||||
formatters_.push_back(std::make_unique<details::f_formatter<Padder>>(padding));
|
||||
break;
|
||||
|
||||
case ('F'): // nanoseconds
|
||||
formatters_.push_back(std::make_unique<details::F_formatter<Padder>>(padding));
|
||||
break;
|
||||
case ('F'): // nanoseconds
|
||||
formatters_.push_back(std::make_unique<details::F_formatter<Padder>>(padding));
|
||||
break;
|
||||
|
||||
case ('E'): // seconds since epoch
|
||||
formatters_.push_back(std::make_unique<details::E_formatter<Padder>>(padding));
|
||||
break;
|
||||
case ('E'): // seconds since epoch
|
||||
formatters_.push_back(std::make_unique<details::E_formatter<Padder>>(padding));
|
||||
break;
|
||||
|
||||
case ('p'): // am/pm
|
||||
formatters_.push_back(std::make_unique<details::p_formatter<Padder>>(padding));
|
||||
need_localtime_ = true;
|
||||
break;
|
||||
case ('p'): // am/pm
|
||||
formatters_.push_back(std::make_unique<details::p_formatter<Padder>>(padding));
|
||||
need_localtime_ = true;
|
||||
break;
|
||||
|
||||
case ('r'): // 12 hour clock 02:55:02 pm
|
||||
formatters_.push_back(std::make_unique<details::r_formatter<Padder>>(padding));
|
||||
need_localtime_ = true;
|
||||
break;
|
||||
case ('r'): // 12 hour clock 02:55:02 pm
|
||||
formatters_.push_back(std::make_unique<details::r_formatter<Padder>>(padding));
|
||||
need_localtime_ = true;
|
||||
break;
|
||||
|
||||
case ('R'): // 24-hour HH:MM time
|
||||
formatters_.push_back(std::make_unique<details::R_formatter<Padder>>(padding));
|
||||
need_localtime_ = true;
|
||||
break;
|
||||
case ('R'): // 24-hour HH:MM time
|
||||
formatters_.push_back(std::make_unique<details::R_formatter<Padder>>(padding));
|
||||
need_localtime_ = true;
|
||||
break;
|
||||
|
||||
case ('T'):
|
||||
case ('X'): // ISO 8601 time format (HH:MM:SS)
|
||||
formatters_.push_back(std::make_unique<details::T_formatter<Padder>>(padding));
|
||||
need_localtime_ = true;
|
||||
break;
|
||||
case ('T'):
|
||||
case ('X'): // ISO 8601 time format (HH:MM:SS)
|
||||
formatters_.push_back(std::make_unique<details::T_formatter<Padder>>(padding));
|
||||
need_localtime_ = true;
|
||||
break;
|
||||
|
||||
case ('z'): // timezone
|
||||
formatters_.push_back(std::make_unique<details::z_formatter<Padder>>(padding));
|
||||
need_localtime_ = true;
|
||||
break;
|
||||
case ('z'): // timezone
|
||||
formatters_.push_back(std::make_unique<details::z_formatter<Padder>>(padding));
|
||||
need_localtime_ = true;
|
||||
break;
|
||||
|
||||
case ('P'): // pid
|
||||
formatters_.push_back(std::make_unique<details::pid_formatter<Padder>>(padding));
|
||||
break;
|
||||
case ('P'): // pid
|
||||
formatters_.push_back(std::make_unique<details::pid_formatter<Padder>>(padding));
|
||||
break;
|
||||
|
||||
case ('^'): // color range start
|
||||
formatters_.push_back(std::make_unique<details::color_start_formatter>(padding));
|
||||
break;
|
||||
case ('^'): // color range start
|
||||
formatters_.push_back(std::make_unique<details::color_start_formatter>(padding));
|
||||
break;
|
||||
|
||||
case ('$'): // color range end
|
||||
formatters_.push_back(std::make_unique<details::color_stop_formatter>(padding));
|
||||
break;
|
||||
case ('$'): // color range end
|
||||
formatters_.push_back(std::make_unique<details::color_stop_formatter>(padding));
|
||||
break;
|
||||
|
||||
case ('@'): // source location (filename:filenumber)
|
||||
formatters_.push_back(
|
||||
std::make_unique<details::source_location_formatter<Padder>>(padding));
|
||||
break;
|
||||
case ('@'): // source location (filename:filenumber)
|
||||
formatters_.push_back(
|
||||
std::make_unique<details::source_location_formatter<Padder>>(padding));
|
||||
break;
|
||||
|
||||
case ('s'): // short source filename - without directory name
|
||||
formatters_.push_back(std::make_unique<details::short_filename_formatter<Padder>>(padding));
|
||||
break;
|
||||
case ('s'): // short source filename - without directory name
|
||||
formatters_.push_back(
|
||||
std::make_unique<details::short_filename_formatter<Padder>>(padding));
|
||||
break;
|
||||
|
||||
case ('g'): // full source filename
|
||||
formatters_.push_back(
|
||||
std::make_unique<details::source_filename_formatter<Padder>>(padding));
|
||||
break;
|
||||
case ('g'): // full source filename
|
||||
formatters_.push_back(
|
||||
std::make_unique<details::source_filename_formatter<Padder>>(padding));
|
||||
break;
|
||||
|
||||
case ('#'): // source line number
|
||||
formatters_.push_back(std::make_unique<details::source_linenum_formatter<Padder>>(padding));
|
||||
break;
|
||||
case ('#'): // source line number
|
||||
formatters_.push_back(
|
||||
std::make_unique<details::source_linenum_formatter<Padder>>(padding));
|
||||
break;
|
||||
|
||||
case ('!'): // source funcname
|
||||
formatters_.push_back(
|
||||
std::make_unique<details::source_funcname_formatter<Padder>>(padding));
|
||||
break;
|
||||
|
||||
case ('%'): // % char
|
||||
formatters_.push_back(std::make_unique<details::ch_formatter>('%'));
|
||||
break;
|
||||
|
||||
case ('u'): // elapsed time since last log message in nanos
|
||||
formatters_.push_back(
|
||||
std::make_unique<details::elapsed_formatter<Padder, std::chrono::nanoseconds>>(
|
||||
padding));
|
||||
break;
|
||||
|
||||
case ('i'): // elapsed time since last log message in micros
|
||||
formatters_.push_back(
|
||||
std::make_unique<details::elapsed_formatter<Padder, std::chrono::microseconds>>(
|
||||
padding));
|
||||
break;
|
||||
|
||||
case ('o'): // elapsed time since last log message in millis
|
||||
formatters_.push_back(
|
||||
std::make_unique<details::elapsed_formatter<Padder, std::chrono::milliseconds>>(
|
||||
padding));
|
||||
break;
|
||||
|
||||
case ('O'): // elapsed time since last log message in seconds
|
||||
formatters_.push_back(
|
||||
std::make_unique<details::elapsed_formatter<Padder, std::chrono::seconds>>(padding));
|
||||
break;
|
||||
|
||||
default: // Unknown flag appears as is
|
||||
auto unknown_flag = std::make_unique<details::aggregate_formatter>();
|
||||
|
||||
if (!padding.truncate_) {
|
||||
unknown_flag->add_ch('%');
|
||||
unknown_flag->add_ch(flag);
|
||||
formatters_.push_back((std::move(unknown_flag)));
|
||||
}
|
||||
// fix issue #1617 (prev char was '!' and should have been treated as funcname flag instead
|
||||
// of truncating flag) spdlog::set_pattern("[%10!] %v") => "[ main] some message"
|
||||
// spdlog::set_pattern("[%3!!] %v") => "[mai] some message"
|
||||
else {
|
||||
padding.truncate_ = false;
|
||||
case ('!'): // source funcname
|
||||
formatters_.push_back(
|
||||
std::make_unique<details::source_funcname_formatter<Padder>>(padding));
|
||||
unknown_flag->add_ch(flag);
|
||||
formatters_.push_back((std::move(unknown_flag)));
|
||||
}
|
||||
break;
|
||||
|
||||
break;
|
||||
case ('%'): // % char
|
||||
formatters_.push_back(std::make_unique<details::ch_formatter>('%'));
|
||||
break;
|
||||
|
||||
case ('u'): // elapsed time since last log message in nanos
|
||||
formatters_.push_back(
|
||||
std::make_unique<details::elapsed_formatter<Padder, std::chrono::nanoseconds>>(
|
||||
padding));
|
||||
break;
|
||||
|
||||
case ('i'): // elapsed time since last log message in micros
|
||||
formatters_.push_back(
|
||||
std::make_unique<details::elapsed_formatter<Padder, std::chrono::microseconds>>(
|
||||
padding));
|
||||
break;
|
||||
|
||||
case ('o'): // elapsed time since last log message in millis
|
||||
formatters_.push_back(
|
||||
std::make_unique<details::elapsed_formatter<Padder, std::chrono::milliseconds>>(
|
||||
padding));
|
||||
break;
|
||||
|
||||
case ('O'): // elapsed time since last log message in seconds
|
||||
formatters_.push_back(
|
||||
std::make_unique<details::elapsed_formatter<Padder, std::chrono::seconds>>(
|
||||
padding));
|
||||
break;
|
||||
|
||||
default: // Unknown flag appears as is
|
||||
auto unknown_flag = std::make_unique<details::aggregate_formatter>();
|
||||
|
||||
if (!padding.truncate_) {
|
||||
unknown_flag->add_ch('%');
|
||||
unknown_flag->add_ch(flag);
|
||||
formatters_.push_back((std::move(unknown_flag)));
|
||||
}
|
||||
// fix issue #1617 (prev char was '!' and should have been treated as funcname flag
|
||||
// instead of truncating flag) spdlog::set_pattern("[%10!] %v") => "[ main] some
|
||||
// message" spdlog::set_pattern("[%3!!] %v") => "[mai] some message"
|
||||
else {
|
||||
padding.truncate_ = false;
|
||||
formatters_.push_back(
|
||||
std::make_unique<details::source_funcname_formatter<Padder>>(padding));
|
||||
unknown_flag->add_ch(flag);
|
||||
formatters_.push_back((std::move(unknown_flag)));
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1182,21 +1186,21 @@ details::padding_info pattern_formatter::handle_padspec_(std::string::const_iter
|
||||
|
||||
padding_info::pad_side side;
|
||||
switch (*it) {
|
||||
case '-':
|
||||
side = padding_info::pad_side::right;
|
||||
++it;
|
||||
break;
|
||||
case '=':
|
||||
side = padding_info::pad_side::center;
|
||||
++it;
|
||||
break;
|
||||
default:
|
||||
side = details::padding_info::pad_side::left;
|
||||
break;
|
||||
case '-':
|
||||
side = padding_info::pad_side::right;
|
||||
++it;
|
||||
break;
|
||||
case '=':
|
||||
side = padding_info::pad_side::center;
|
||||
++it;
|
||||
break;
|
||||
default:
|
||||
side = details::padding_info::pad_side::left;
|
||||
break;
|
||||
}
|
||||
|
||||
if (it == end || !std::isdigit(static_cast<unsigned char>(*it))) {
|
||||
return padding_info{}; // no padding if no digit found here
|
||||
return padding_info{}; // no padding if no digit found here
|
||||
}
|
||||
|
||||
auto width = static_cast<size_t>(*it) - '0';
|
||||
@@ -1222,7 +1226,7 @@ void pattern_formatter::compile_pattern_(const std::string &pattern) {
|
||||
formatters_.clear();
|
||||
for (auto it = pattern.begin(); it != end; ++it) {
|
||||
if (*it == '%') {
|
||||
if (user_chars) // append user chars found so far
|
||||
if (user_chars) // append user chars found so far
|
||||
{
|
||||
formatters_.push_back(std::move(user_chars));
|
||||
}
|
||||
@@ -1238,7 +1242,7 @@ void pattern_formatter::compile_pattern_(const std::string &pattern) {
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
} else // chars not following the % sign should be displayed as is
|
||||
} else // chars not following the % sign should be displayed as is
|
||||
{
|
||||
if (!user_chars) {
|
||||
user_chars = std::make_unique<details::aggregate_formatter>();
|
||||
@@ -1246,9 +1250,9 @@ void pattern_formatter::compile_pattern_(const std::string &pattern) {
|
||||
user_chars->add_ch(*it);
|
||||
}
|
||||
}
|
||||
if (user_chars) // append raw chars found so far
|
||||
if (user_chars) // append raw chars found so far
|
||||
{
|
||||
formatters_.push_back(std::move(user_chars));
|
||||
}
|
||||
}
|
||||
} // namespace spdlog
|
||||
} // namespace spdlog
|
||||
|
||||
@@ -50,7 +50,7 @@ void ansicolor_sink<ConsoleMutex>::log(const details::log_msg &msg) {
|
||||
print_ccode_(reset);
|
||||
// after color range
|
||||
print_range_(formatted, msg.color_range_end, formatted.size());
|
||||
} else // no color
|
||||
} else // no color
|
||||
{
|
||||
print_range_(formatted, 0, formatted.size());
|
||||
}
|
||||
@@ -84,18 +84,18 @@ bool ansicolor_sink<ConsoleMutex>::should_color() {
|
||||
template <typename ConsoleMutex>
|
||||
void ansicolor_sink<ConsoleMutex>::set_color_mode(color_mode mode) {
|
||||
switch (mode) {
|
||||
case color_mode::always:
|
||||
should_do_colors_ = true;
|
||||
return;
|
||||
case color_mode::automatic:
|
||||
should_do_colors_ =
|
||||
details::os::in_terminal(target_file_) && details::os::is_color_terminal();
|
||||
return;
|
||||
case color_mode::never:
|
||||
should_do_colors_ = false;
|
||||
return;
|
||||
default:
|
||||
should_do_colors_ = false;
|
||||
case color_mode::always:
|
||||
should_do_colors_ = true;
|
||||
return;
|
||||
case color_mode::automatic:
|
||||
should_do_colors_ =
|
||||
details::os::in_terminal(target_file_) && details::os::is_color_terminal();
|
||||
return;
|
||||
case color_mode::never:
|
||||
should_do_colors_ = false;
|
||||
return;
|
||||
default:
|
||||
should_do_colors_ = false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -126,8 +126,8 @@ template <typename ConsoleMutex>
|
||||
ansicolor_stderr_sink<ConsoleMutex>::ansicolor_stderr_sink(color_mode mode)
|
||||
: ansicolor_sink<ConsoleMutex>(stderr, mode) {}
|
||||
|
||||
} // namespace sinks
|
||||
} // namespace spdlog
|
||||
} // namespace sinks
|
||||
} // namespace spdlog
|
||||
|
||||
// template instantiations
|
||||
template SPDLOG_API class spdlog::sinks::ansicolor_stdout_sink<spdlog::details::console_mutex>;
|
||||
|
||||
@@ -34,8 +34,8 @@ void basic_file_sink<Mutex>::flush_() {
|
||||
file_helper_.flush();
|
||||
}
|
||||
|
||||
} // namespace sinks
|
||||
} // namespace spdlog
|
||||
} // namespace sinks
|
||||
} // namespace spdlog
|
||||
|
||||
// template instantiations
|
||||
template class SPDLOG_API spdlog::sinks::basic_file_sink<std::mutex>;
|
||||
|
||||
@@ -34,7 +34,7 @@ rotating_file_sink<Mutex>::rotating_file_sink(filename_t base_filename,
|
||||
throw_spdlog_ex("rotating sink constructor: max_files arg cannot exceed 200000");
|
||||
}
|
||||
file_helper_.open(calc_filename(base_filename_, 0));
|
||||
current_size_ = file_helper_.size(); // expensive. called only once
|
||||
current_size_ = file_helper_.size(); // expensive. called only once
|
||||
if (rotate_on_open && current_size_ > 0) {
|
||||
rotate_();
|
||||
current_size_ = 0;
|
||||
@@ -106,11 +106,12 @@ void rotating_file_sink<Mutex>::rotate_() {
|
||||
if (!rename_file_(src, target)) {
|
||||
// if failed try again after a small delay.
|
||||
// this is a workaround to a windows issue, where very high rotation
|
||||
// rates can cause the rename to fail with permission denied (because of antivirus?).
|
||||
// rates can cause the rename to fail with permission denied (because of
|
||||
// antivirus?).
|
||||
details::os::sleep_for_millis(100);
|
||||
if (!rename_file_(src, target)) {
|
||||
file_helper_.reopen(
|
||||
true); // truncate the log file anyway to prevent it to grow beyond its limit!
|
||||
file_helper_.reopen(true); // truncate the log file anyway to prevent it
|
||||
// to grow beyond its limit!
|
||||
current_size_ = 0;
|
||||
throw_spdlog_ex("rotating_file_sink: failed renaming " + filename_to_str(src) +
|
||||
" to " + filename_to_str(target),
|
||||
@@ -131,8 +132,8 @@ bool rotating_file_sink<Mutex>::rename_file_(const filename_t &src_filename,
|
||||
return details::os::rename(src_filename, target_filename) == 0;
|
||||
}
|
||||
|
||||
} // namespace sinks
|
||||
} // namespace spdlog
|
||||
} // namespace sinks
|
||||
} // namespace spdlog
|
||||
|
||||
// template instantiations
|
||||
template class SPDLOG_API spdlog::sinks::rotating_file_sink<std::mutex>;
|
||||
|
||||
@@ -28,7 +28,7 @@ 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
|
||||
} // namespace spdlog
|
||||
|
||||
// template instantiations
|
||||
template SPDLOG_API std::shared_ptr<spdlog::logger>
|
||||
@@ -47,14 +47,14 @@ template SPDLOG_API std::shared_ptr<spdlog::logger>
|
||||
spdlog::stderr_color_st<spdlog::synchronous_factory>(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);
|
||||
template SPDLOG_API std::shared_ptr<spdlog::logger> spdlog::stdout_color_mt<spdlog::async_factory>(
|
||||
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);
|
||||
template SPDLOG_API std::shared_ptr<spdlog::logger> spdlog::stdout_color_st<spdlog::async_factory>(
|
||||
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);
|
||||
template SPDLOG_API std::shared_ptr<spdlog::logger> spdlog::stderr_color_mt<spdlog::async_factory>(
|
||||
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);
|
||||
template SPDLOG_API std::shared_ptr<spdlog::logger> spdlog::stderr_color_st<spdlog::async_factory>(
|
||||
const std::string &logger_name, color_mode mode);
|
||||
|
||||
@@ -10,13 +10,13 @@
|
||||
// so instead we use ::FileWrite
|
||||
#include <spdlog/details/windows_include.h>
|
||||
|
||||
#ifndef _USING_V110_SDK71_ // fileapi.h doesn't exist in winxp
|
||||
#include <fileapi.h> // WriteFile (..)
|
||||
#ifndef _USING_V110_SDK71_ // fileapi.h doesn't exist in winxp
|
||||
#include <fileapi.h> // WriteFile (..)
|
||||
#endif
|
||||
|
||||
#include <io.h> // _get_osfhandle(..)
|
||||
#include <stdio.h> // _fileno(..)
|
||||
#endif // WIN32
|
||||
#include <io.h> // _get_osfhandle(..)
|
||||
#include <stdio.h> // _fileno(..)
|
||||
#endif // WIN32
|
||||
|
||||
namespace spdlog {
|
||||
|
||||
@@ -38,7 +38,7 @@ stdout_sink_base<ConsoleMutex>::stdout_sink_base(FILE *file)
|
||||
if (handle_ == INVALID_HANDLE_VALUE && file != stdout && file != stderr) {
|
||||
throw_spdlog_ex("spdlog::stdout_sink_base: _get_osfhandle() failed", errno);
|
||||
}
|
||||
#endif // WIN32
|
||||
#endif // WIN32
|
||||
}
|
||||
|
||||
template <typename ConsoleMutex>
|
||||
@@ -62,8 +62,8 @@ void stdout_sink_base<ConsoleMutex>::log(const details::log_msg &msg) {
|
||||
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
|
||||
#endif // WIN32
|
||||
::fflush(file_); // flush every line to terminal
|
||||
}
|
||||
|
||||
template <typename ConsoleMutex>
|
||||
@@ -95,7 +95,7 @@ template <typename ConsoleMutex>
|
||||
stderr_sink<ConsoleMutex>::stderr_sink()
|
||||
: stdout_sink_base<ConsoleMutex>(stderr) {}
|
||||
|
||||
} // namespace sinks
|
||||
} // namespace sinks
|
||||
|
||||
// factory methods
|
||||
template <typename Factory>
|
||||
@@ -117,7 +117,7 @@ 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
|
||||
} // namespace spdlog
|
||||
|
||||
// template instantiations for stdout/stderr loggers
|
||||
#include <spdlog/details/console_globals.h>
|
||||
@@ -141,11 +141,11 @@ spdlog::stderr_logger_mt<spdlog::synchronous_factory>(const std::string &logger_
|
||||
template SPDLOG_API std::shared_ptr<spdlog::logger>
|
||||
spdlog::stderr_logger_st<spdlog::synchronous_factory>(const std::string &logger_name);
|
||||
|
||||
template SPDLOG_API std::shared_ptr<spdlog::logger>
|
||||
spdlog::stdout_logger_mt<spdlog::async_factory>(const std::string &logger_name);
|
||||
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);
|
||||
template SPDLOG_API std::shared_ptr<spdlog::logger> spdlog::stdout_logger_mt<spdlog::async_factory>(
|
||||
const std::string &logger_name);
|
||||
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);
|
||||
|
||||
@@ -19,15 +19,15 @@ wincolor_sink<ConsoleMutex>::wincolor_sink(void *out_handle, color_mode mode)
|
||||
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::info)) = FOREGROUND_GREEN; // green
|
||||
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::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
|
||||
FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_INTENSITY; // intense yellow
|
||||
colors_.at(level_to_number(level::err)) = FOREGROUND_RED | FOREGROUND_INTENSITY; // intense red
|
||||
colors_.at(level_to_number(level::critical)) =
|
||||
BACKGROUND_RED | FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE |
|
||||
FOREGROUND_INTENSITY; // intense white on red background
|
||||
FOREGROUND_INTENSITY; // intense white on red background
|
||||
colors_.at(level_to_number(level::off)) = 0;
|
||||
}
|
||||
|
||||
@@ -64,7 +64,7 @@ void wincolor_sink<ConsoleMutex>::log(const details::log_msg &msg) {
|
||||
// reset to orig colors
|
||||
::SetConsoleTextAttribute(static_cast<HANDLE>(out_handle_), orig_attribs);
|
||||
print_range_(formatted, msg.color_range_end, formatted.size());
|
||||
} else // print without colors if color range is invalid (or color is disabled)
|
||||
} else // print without colors if color range is invalid (or color is disabled)
|
||||
{
|
||||
write_to_file_(formatted);
|
||||
}
|
||||
@@ -119,7 +119,7 @@ std::uint16_t wincolor_sink<ConsoleMutex>::set_foreground_color_(std::uint16_t a
|
||||
auto ignored =
|
||||
::SetConsoleTextAttribute(static_cast<HANDLE>(out_handle_), static_cast<WORD>(new_attribs));
|
||||
(void)(ignored);
|
||||
return static_cast<std::uint16_t>(orig_buffer_info.wAttributes); // return orig attribs
|
||||
return static_cast<std::uint16_t>(orig_buffer_info.wAttributes); // return orig attribs
|
||||
}
|
||||
|
||||
// print a range of formatted message to console
|
||||
@@ -153,8 +153,8 @@ wincolor_stdout_sink<ConsoleMutex>::wincolor_stdout_sink(color_mode mode)
|
||||
template <typename ConsoleMutex>
|
||||
wincolor_stderr_sink<ConsoleMutex>::wincolor_stderr_sink(color_mode mode)
|
||||
: wincolor_sink<ConsoleMutex>(::GetStdHandle(STD_ERROR_HANDLE), mode) {}
|
||||
} // namespace sinks
|
||||
} // namespace spdlog
|
||||
} // namespace sinks
|
||||
} // namespace spdlog
|
||||
|
||||
// template instantiations
|
||||
template class SPDLOG_API spdlog::sinks::wincolor_sink<spdlog::details::console_mutex>;
|
||||
@@ -164,4 +164,4 @@ template class SPDLOG_API spdlog::sinks::wincolor_stdout_sink<spdlog::details::c
|
||||
template class SPDLOG_API spdlog::sinks::wincolor_stderr_sink<spdlog::details::console_mutex>;
|
||||
template class SPDLOG_API spdlog::sinks::wincolor_stderr_sink<spdlog::details::console_nullmutex>;
|
||||
|
||||
#endif // _WIN32
|
||||
#endif // _WIN32
|
||||
|
||||
@@ -68,4 +68,4 @@ void apply_logger_env_levels(std::shared_ptr<logger> logger) {
|
||||
details::registry::instance().apply_logger_env_levels(std::move(logger));
|
||||
}
|
||||
|
||||
} // namespace spdlog
|
||||
} // namespace spdlog
|
||||
|
||||
Reference in New Issue
Block a user