mirror of
https://github.com/gabime/spdlog.git
synced 2024-12-25 01:51:38 +08:00
update clang format again
This commit is contained in:
parent
968048ced6
commit
6dffd7c6e8
@ -1,6 +1,6 @@
|
||||
---
|
||||
Language: Cpp
|
||||
# BasedOnStyle: Google
|
||||
BasedOnStyle: Google
|
||||
AccessModifierOffset: -4
|
||||
Standard: c++17
|
||||
IndentWidth: 4
|
||||
|
@ -35,16 +35,15 @@ void bench_mt(int howmany, std::shared_ptr<spdlog::logger> log, int thread_count
|
||||
|
||||
#ifdef _MSC_VER
|
||||
#pragma warning(push)
|
||||
#pragma warning(disable : 4996) // disable fopen warning under msvc
|
||||
#endif // _MSC_VER
|
||||
#pragma warning(disable : 4996) // disable fopen warning under msvc
|
||||
#endif // _MSC_VER
|
||||
|
||||
int count_lines(const char *filename) {
|
||||
int counter = 0;
|
||||
auto *infile = fopen(filename, "r");
|
||||
int ch;
|
||||
while (EOF != (ch = getc(infile))) {
|
||||
if ('\n' == ch)
|
||||
counter++;
|
||||
if ('\n' == ch) counter++;
|
||||
}
|
||||
fclose(infile);
|
||||
|
||||
@ -67,7 +66,6 @@ void verify_file(const char *filename, int expected_count) {
|
||||
#endif
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
|
||||
int howmany = 1000000;
|
||||
int queue_size = std::min(howmany + 2, 8192);
|
||||
int threads = 10;
|
||||
@ -80,10 +78,8 @@ int main(int argc, char *argv[]) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (argc > 1)
|
||||
howmany = atoi(argv[1]);
|
||||
if (argc > 2)
|
||||
threads = atoi(argv[2]);
|
||||
if (argc > 1) howmany = atoi(argv[1]);
|
||||
if (argc > 2) threads = atoi(argv[2]);
|
||||
if (argc > 3) {
|
||||
queue_size = atoi(argv[3]);
|
||||
if (queue_size > 500000) {
|
||||
@ -92,8 +88,7 @@ int main(int argc, char *argv[]) {
|
||||
}
|
||||
}
|
||||
|
||||
if (argc > 4)
|
||||
iters = atoi(argv[4]);
|
||||
if (argc > 4) iters = atoi(argv[4]);
|
||||
|
||||
auto slot_size = sizeof(spdlog::details::async_msg);
|
||||
spdlog::info("-------------------------------------------------");
|
||||
|
@ -22,7 +22,7 @@
|
||||
|
||||
#include "utils.h"
|
||||
#include <atomic>
|
||||
#include <cstdlib> // EXIT_FAILURE
|
||||
#include <cstdlib> // EXIT_FAILURE
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <thread>
|
||||
@ -91,7 +91,6 @@ int main(int argc, char *argv[]) {
|
||||
int iters = 250000;
|
||||
size_t threads = 4;
|
||||
try {
|
||||
|
||||
if (argc > 1) {
|
||||
iters = std::stoi(argv[1]);
|
||||
}
|
||||
|
@ -54,7 +54,6 @@ void bench_formatters() {
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
|
||||
spdlog::set_pattern("[%^%l%$] %v");
|
||||
if (argc != 2) {
|
||||
spdlog::error("Usage: {} <pattern> (or \"all\" to bench all)", argv[0]);
|
||||
|
@ -49,8 +49,8 @@ void bench_global_logger(benchmark::State &state, std::shared_ptr<spdlog::logger
|
||||
|
||||
void bench_disabled_macro(benchmark::State &state, std::shared_ptr<spdlog::logger> logger) {
|
||||
int i = 0;
|
||||
benchmark::DoNotOptimize(i); // prevent unused warnings
|
||||
benchmark::DoNotOptimize(logger); // prevent unused warnings
|
||||
benchmark::DoNotOptimize(i); // prevent unused warnings
|
||||
benchmark::DoNotOptimize(logger); // prevent unused warnings
|
||||
for (auto _ : state) {
|
||||
SPDLOG_LOGGER_DEBUG(logger, "Hello logger: msg number {}...............", i++);
|
||||
}
|
||||
@ -60,8 +60,8 @@ void bench_disabled_macro_global_logger(benchmark::State &state,
|
||||
std::shared_ptr<spdlog::logger> logger) {
|
||||
spdlog::set_default_logger(std::move(logger));
|
||||
int i = 0;
|
||||
benchmark::DoNotOptimize(i); // prevent unused warnings
|
||||
benchmark::DoNotOptimize(logger); // prevent unused warnings
|
||||
benchmark::DoNotOptimize(i); // prevent unused warnings
|
||||
benchmark::DoNotOptimize(logger); // prevent unused warnings
|
||||
for (auto _ : state) {
|
||||
SPDLOG_DEBUG("Hello logger: msg number {}...............", i++);
|
||||
}
|
||||
@ -79,7 +79,7 @@ void bench_dev_null() {
|
||||
->UseRealTime();
|
||||
spdlog::drop("/dev/null_mt");
|
||||
}
|
||||
#endif // __linux__
|
||||
#endif // __linux__
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
using spdlog::sinks::null_sink_mt;
|
||||
@ -112,7 +112,7 @@ int main(int argc, char *argv[]) {
|
||||
|
||||
#ifdef __linux
|
||||
bench_dev_null();
|
||||
#endif // __linux__
|
||||
#endif // __linux__
|
||||
|
||||
if (full_bench) {
|
||||
// basic_st
|
||||
|
@ -29,4 +29,4 @@ inline std::string format(const double &value) {
|
||||
return ss.str();
|
||||
}
|
||||
|
||||
} // namespace utils
|
||||
} // namespace utils
|
||||
|
@ -32,7 +32,7 @@ void replace_default_logger_example();
|
||||
// #define SPDLOG_SOURCE_LOCATION
|
||||
|
||||
#include "spdlog/spdlog.h"
|
||||
#include "spdlog/cfg/env.h" // support for loading levels from the environment variable
|
||||
#include "spdlog/cfg/env.h" // support for loading levels from the environment variable
|
||||
|
||||
int main(int, char *[]) {
|
||||
// Log levels can be loaded from argv/env using "SPDLOG_LEVEL"
|
||||
@ -47,15 +47,15 @@ int main(int, char *[]) {
|
||||
spdlog::info("{:>8} aligned, {:<8} aligned", "right", "left");
|
||||
|
||||
// Runtime log levels
|
||||
spdlog::set_level(spdlog::level::info); // Set global log level to info
|
||||
spdlog::set_level(spdlog::level::info); // Set global log level to info
|
||||
spdlog::debug("This message should not be displayed!");
|
||||
spdlog::set_level(spdlog::level::trace); // Set specific logger's log level
|
||||
spdlog::set_level(spdlog::level::trace); // Set specific logger's log level
|
||||
spdlog::debug("This message should be displayed..");
|
||||
|
||||
// Customize msg format for all loggers
|
||||
spdlog::set_pattern("[%H:%M:%S %z] [%^%L%$] [thread %t] %v");
|
||||
spdlog::info("This an info message with custom format");
|
||||
spdlog::set_pattern("%+"); // back to default format
|
||||
spdlog::set_pattern("%+"); // back to default format
|
||||
spdlog::set_level(spdlog::level::info);
|
||||
|
||||
try {
|
||||
@ -259,7 +259,7 @@ struct my_type {
|
||||
: i(i){};
|
||||
};
|
||||
|
||||
#ifndef SPDLOG_USE_STD_FORMAT // when using fmtlib
|
||||
#ifndef SPDLOG_USE_STD_FORMAT // when using fmtlib
|
||||
template <>
|
||||
struct fmt::formatter<my_type> : fmt::formatter<std::string> {
|
||||
auto format(my_type my, format_context &ctx) -> decltype(ctx.out()) {
|
||||
@ -267,7 +267,7 @@ struct fmt::formatter<my_type> : fmt::formatter<std::string> {
|
||||
}
|
||||
};
|
||||
|
||||
#else // when using std::format
|
||||
#else // when using std::format
|
||||
template <>
|
||||
struct std::formatter<my_type> : std::formatter<std::string> {
|
||||
auto format(my_type my, format_context &ctx) const -> decltype(ctx.out()) {
|
||||
@ -311,8 +311,9 @@ void android_example() {
|
||||
#include "spdlog/pattern_formatter.h"
|
||||
class my_formatter_flag : public spdlog::custom_flag_formatter {
|
||||
public:
|
||||
void
|
||||
format(const spdlog::details::log_msg &, const std::tm &, spdlog::memory_buf_t &dest) override {
|
||||
void format(const spdlog::details::log_msg &,
|
||||
const std::tm &,
|
||||
spdlog::memory_buf_t &dest) override {
|
||||
std::string some_txt = "custom-flag";
|
||||
dest.append(some_txt.data(), some_txt.data() + some_txt.size());
|
||||
}
|
||||
|
@ -82,8 +82,9 @@ inline void init_thread_pool(size_t q_size,
|
||||
details::registry::instance().set_tp(std::move(tp));
|
||||
}
|
||||
|
||||
inline void
|
||||
init_thread_pool(size_t q_size, size_t thread_count, std::function<void()> on_thread_start) {
|
||||
inline void init_thread_pool(size_t q_size,
|
||||
size_t thread_count,
|
||||
std::function<void()> on_thread_start) {
|
||||
init_thread_pool(q_size, thread_count, on_thread_start, [] {});
|
||||
}
|
||||
|
||||
@ -96,4 +97,4 @@ inline void init_thread_pool(size_t q_size, size_t thread_count) {
|
||||
inline std::shared_ptr<spdlog::details::thread_pool> thread_pool() {
|
||||
return details::registry::instance().get_tp();
|
||||
}
|
||||
} // namespace spdlog
|
||||
} // namespace spdlog
|
||||
|
@ -20,10 +20,10 @@ namespace spdlog {
|
||||
|
||||
// Async overflow policy - block by default.
|
||||
enum class async_overflow_policy {
|
||||
block, // Block until message can be enqueued
|
||||
overrun_oldest, // Discard oldest message in the queue if full when trying to
|
||||
// add new item.
|
||||
discard_new // Discard new message if the queue is full when trying to add new item.
|
||||
block, // Block until message can be enqueued
|
||||
overrun_oldest, // Discard oldest message in the queue if full when trying to
|
||||
// add new item.
|
||||
discard_new // Discard new message if the queue is full when trying to add new item.
|
||||
};
|
||||
|
||||
namespace details {
|
||||
@ -67,4 +67,4 @@ private:
|
||||
std::weak_ptr<details::thread_pool> thread_pool_;
|
||||
async_overflow_policy overflow_policy_;
|
||||
};
|
||||
} // namespace spdlog
|
||||
} // namespace spdlog
|
||||
|
@ -36,5 +36,5 @@ inline void load_argv_levels(int argc, char **argv) {
|
||||
load_argv_levels(argc, const_cast<const char **>(argv));
|
||||
}
|
||||
|
||||
} // namespace cfg
|
||||
} // namespace spdlog
|
||||
} // namespace cfg
|
||||
} // namespace spdlog
|
||||
|
@ -32,5 +32,5 @@ inline void load_env_levels() {
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace cfg
|
||||
} // namespace spdlog
|
||||
} // namespace cfg
|
||||
} // namespace spdlog
|
||||
|
@ -19,6 +19,6 @@ namespace helpers {
|
||||
// turn off all logging except for logger1 and logger2: "off,logger1=debug,logger2=info"
|
||||
//
|
||||
SPDLOG_API void load_levels(const std::string &txt);
|
||||
} // namespace helpers
|
||||
} // namespace cfg
|
||||
} // namespace spdlog
|
||||
} // namespace helpers
|
||||
} // namespace cfg
|
||||
} // namespace spdlog
|
||||
|
@ -41,20 +41,20 @@
|
||||
#if defined(_WIN32)
|
||||
#ifdef spdlog_EXPORTS
|
||||
#define SPDLOG_API __declspec(dllexport)
|
||||
#else // !spdlog_EXPORTS
|
||||
#else // !spdlog_EXPORTS
|
||||
#define SPDLOG_API __declspec(dllimport)
|
||||
#endif
|
||||
#else // !defined(_WIN32)
|
||||
#else // !defined(_WIN32)
|
||||
#define SPDLOG_API __attribute__((visibility("default")))
|
||||
#endif
|
||||
#else // !defined(SPDLOG_SHARED_LIB)
|
||||
#else // !defined(SPDLOG_SHARED_LIB)
|
||||
#define SPDLOG_API
|
||||
#endif
|
||||
|
||||
#include <spdlog/fmt/fmt.h>
|
||||
|
||||
#if !defined(SPDLOG_USE_STD_FORMAT) && \
|
||||
FMT_VERSION >= 80000 // backward compatibility with fmt versions older than 8
|
||||
FMT_VERSION >= 80000 // backward compatibility with fmt versions older than 8
|
||||
#define SPDLOG_FMT_RUNTIME(format_string) fmt::runtime(format_string)
|
||||
#if defined(SPDLOG_WCHAR_FILENAMES)
|
||||
#include <spdlog/fmt/xchar.h>
|
||||
@ -121,7 +121,7 @@ using format_string_t = std::string_view;
|
||||
#endif
|
||||
|
||||
#define SPDLOG_BUF_TO_STRING(x) x
|
||||
#else // use fmt lib instead of std::format
|
||||
#else // use fmt lib instead of std::format
|
||||
namespace fmt_lib = fmt;
|
||||
|
||||
using string_view_t = fmt::basic_string_view<char>;
|
||||
@ -131,7 +131,7 @@ using format_string_t = fmt::format_string<Args...>;
|
||||
using wstring_view_t = fmt::basic_string_view<wchar_t>;
|
||||
using wmemory_buf_t = fmt::basic_memory_buffer<wchar_t, 250>;
|
||||
#define SPDLOG_BUF_TO_STRING(x) fmt::to_string(x)
|
||||
#endif // SPDLOG_USE_STD_FORMAT
|
||||
#endif // SPDLOG_USE_STD_FORMAT
|
||||
|
||||
#define SPDLOG_LEVEL_TRACE 0
|
||||
#define SPDLOG_LEVEL_DEBUG 1
|
||||
@ -204,8 +204,8 @@ enum class color_mode { always, automatic, never };
|
||||
// local time by default
|
||||
//
|
||||
enum class pattern_time_type {
|
||||
local, // log localtime
|
||||
utc // log utc
|
||||
local, // log localtime
|
||||
utc // log utc
|
||||
};
|
||||
|
||||
//
|
||||
@ -234,8 +234,8 @@ struct source_loc {
|
||||
funcname{funcname_in} {}
|
||||
|
||||
#ifdef SPDLOG_HAVE_STD_SOURCE_LOCATION
|
||||
static constexpr source_loc
|
||||
current(const std::source_location source_location = std::source_location::current()) {
|
||||
static constexpr source_loc current(
|
||||
const std::source_location source_location = std::source_location::current()) {
|
||||
return source_loc{source_location.file_name(), source_location.line(),
|
||||
source_location.function_name()};
|
||||
}
|
||||
@ -245,7 +245,7 @@ struct source_loc {
|
||||
return source_loc{source_location.file_name(), source_location.line(),
|
||||
source_location.function_name()};
|
||||
}
|
||||
#else // no source location support
|
||||
#else // no source location support
|
||||
static constexpr source_loc current() { return source_loc{}; }
|
||||
#endif
|
||||
|
||||
@ -310,26 +310,26 @@ namespace details {
|
||||
|
||||
// convert format_string<...> to string_view depending on format lib versions
|
||||
#if defined(SPDLOG_USE_STD_FORMAT)
|
||||
#if __cpp_lib_format >= 202207L // std::format and __cpp_lib_format >= 202207L
|
||||
#if __cpp_lib_format >= 202207L // std::format and __cpp_lib_format >= 202207L
|
||||
template <typename T, typename... Args>
|
||||
[[nodiscard]] constexpr std::basic_string_view<T>
|
||||
to_string_view(std::basic_format_string<T, Args...> fmt) noexcept {
|
||||
[[nodiscard]] constexpr std::basic_string_view<T> to_string_view(
|
||||
std::basic_format_string<T, Args...> fmt) noexcept {
|
||||
return fmt.get();
|
||||
}
|
||||
#else // std::format and __cpp_lib_format < 202207L
|
||||
#else // std::format and __cpp_lib_format < 202207L
|
||||
template <typename T, typename... Args>
|
||||
[[nodiscard]] constexpr std::basic_string_view<T>
|
||||
to_string_view(std::basic_format_string<T, Args...> fmt) noexcept {
|
||||
[[nodiscard]] constexpr std::basic_string_view<T> to_string_view(
|
||||
std::basic_format_string<T, Args...> fmt) noexcept {
|
||||
return fmt;
|
||||
}
|
||||
#endif
|
||||
#else // {fmt} version
|
||||
#else // {fmt} version
|
||||
template <typename T, typename... Args>
|
||||
[[nodiscard]] constexpr fmt::basic_string_view<T>
|
||||
to_string_view(fmt::basic_format_string<T, Args...> fmt) noexcept {
|
||||
[[nodiscard]] constexpr fmt::basic_string_view<T> to_string_view(
|
||||
fmt::basic_format_string<T, Args...> fmt) noexcept {
|
||||
return fmt;
|
||||
}
|
||||
#endif
|
||||
|
||||
} // namespace details
|
||||
} // namespace spdlog
|
||||
} // namespace details
|
||||
} // namespace spdlog
|
||||
|
@ -24,7 +24,7 @@ public:
|
||||
circular_q() = default;
|
||||
|
||||
explicit circular_q(size_t max_items)
|
||||
: max_items_(max_items + 1) // one item is reserved as marker for full q
|
||||
: max_items_(max_items + 1) // one item is reserved as marker for full q
|
||||
,
|
||||
v_(max_items_) {}
|
||||
|
||||
@ -46,7 +46,7 @@ public:
|
||||
v_[tail_] = std::move(item);
|
||||
tail_ = (tail_ + 1) % max_items_;
|
||||
|
||||
if (tail_ == head_) // overrun last item if full
|
||||
if (tail_ == head_) // overrun last item if full
|
||||
{
|
||||
head_ = (head_ + 1) % max_items_;
|
||||
++overrun_counter_;
|
||||
@ -115,5 +115,5 @@ private:
|
||||
other.overrun_counter_ = 0;
|
||||
}
|
||||
};
|
||||
} // namespace details
|
||||
} // namespace spdlog
|
||||
} // namespace details
|
||||
} // namespace spdlog
|
||||
|
@ -24,5 +24,5 @@ struct console_nullmutex {
|
||||
return s_mutex;
|
||||
}
|
||||
};
|
||||
} // namespace details
|
||||
} // namespace spdlog
|
||||
} // namespace details
|
||||
} // namespace spdlog
|
||||
|
@ -53,5 +53,5 @@ private:
|
||||
filename_t filename_;
|
||||
file_event_handlers event_handlers_;
|
||||
};
|
||||
} // namespace details
|
||||
} // namespace spdlog
|
||||
} // namespace details
|
||||
} // namespace spdlog
|
||||
|
@ -53,14 +53,10 @@ constexpr unsigned int count_digits_fallback(T n) {
|
||||
// Integer division is slow so do it for a group of four digits instead
|
||||
// of for every digit. The idea comes from the talk by Alexandrescu
|
||||
// "Three Optimization Tips for C++". See speed-test for a comparison.
|
||||
if (n < 10)
|
||||
return count;
|
||||
if (n < 100)
|
||||
return count + 1;
|
||||
if (n < 1000)
|
||||
return count + 2;
|
||||
if (n < 10000)
|
||||
return count + 3;
|
||||
if (n < 10) return count;
|
||||
if (n < 100) return count + 1;
|
||||
if (n < 1000) return count + 2;
|
||||
if (n < 10000) return count + 3;
|
||||
n /= 10000u;
|
||||
count += 4;
|
||||
}
|
||||
@ -86,11 +82,11 @@ inline unsigned int count_digits(T n) {
|
||||
}
|
||||
|
||||
inline void pad2(int n, memory_buf_t &dest) {
|
||||
if (n >= 0 && n < 100) // 0-99
|
||||
if (n >= 0 && n < 100) // 0-99
|
||||
{
|
||||
dest.push_back(static_cast<char>('0' + n / 10));
|
||||
dest.push_back(static_cast<char>('0' + n % 10));
|
||||
} else // unlikely, but just in case, let fmt deal with it
|
||||
} else // unlikely, but just in case, let fmt deal with it
|
||||
{
|
||||
fmt_lib::format_to(std::back_inserter(dest), "{:02}", n);
|
||||
}
|
||||
@ -140,6 +136,6 @@ inline ToDuration time_fraction(log_clock::time_point tp) {
|
||||
return duration_cast<ToDuration>(duration) - duration_cast<ToDuration>(secs);
|
||||
}
|
||||
|
||||
} // namespace fmt_helper
|
||||
} // namespace details
|
||||
} // namespace spdlog
|
||||
} // namespace fmt_helper
|
||||
} // namespace details
|
||||
} // namespace spdlog
|
||||
|
@ -32,5 +32,5 @@ struct SPDLOG_API log_msg {
|
||||
source_loc source;
|
||||
string_view_t payload;
|
||||
};
|
||||
} // namespace details
|
||||
} // namespace spdlog
|
||||
} // namespace details
|
||||
} // namespace spdlog
|
||||
|
@ -24,5 +24,5 @@ public:
|
||||
log_msg_buffer &operator=(log_msg_buffer &&other) noexcept;
|
||||
};
|
||||
|
||||
} // namespace details
|
||||
} // namespace spdlog
|
||||
} // namespace details
|
||||
} // namespace spdlog
|
||||
|
@ -173,5 +173,5 @@ private:
|
||||
spdlog::details::circular_q<T> q_;
|
||||
std::atomic<size_t> discard_counter_{0};
|
||||
};
|
||||
} // namespace details
|
||||
} // namespace spdlog
|
||||
} // namespace details
|
||||
} // namespace spdlog
|
||||
|
@ -30,9 +30,9 @@ struct null_atomic {
|
||||
|
||||
T exchange(T new_value, std::memory_order = std::memory_order_seq_cst) {
|
||||
std::swap(new_value, value);
|
||||
return new_value; // return value before the call
|
||||
return new_value; // return value before the call
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace details
|
||||
} // namespace spdlog
|
||||
} // namespace details
|
||||
} // namespace spdlog
|
||||
|
@ -3,7 +3,7 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <ctime> // std::time_t
|
||||
#include <ctime> // std::time_t
|
||||
#include <spdlog/common.h>
|
||||
|
||||
namespace spdlog {
|
||||
@ -114,6 +114,6 @@ SPDLOG_API std::string getenv(const char *field);
|
||||
// Return true on success.
|
||||
SPDLOG_API bool fsync(FILE *fp);
|
||||
|
||||
} // namespace os
|
||||
} // namespace details
|
||||
} // namespace spdlog
|
||||
} // namespace os
|
||||
} // namespace details
|
||||
} // namespace spdlog
|
||||
|
@ -35,7 +35,7 @@ public:
|
||||
for (;;) {
|
||||
std::unique_lock<std::mutex> lock(this->mutex_);
|
||||
if (this->cv_.wait_for(lock, interval, [this] { return !this->active_; })) {
|
||||
return; // active_ == false, so exit this thread
|
||||
return; // active_ == false, so exit this thread
|
||||
}
|
||||
callback_fun();
|
||||
}
|
||||
@ -53,5 +53,5 @@ private:
|
||||
std::condition_variable cv_;
|
||||
};
|
||||
|
||||
} // namespace details
|
||||
} // namespace spdlog
|
||||
} // namespace details
|
||||
} // namespace spdlog
|
||||
|
@ -109,5 +109,5 @@ private:
|
||||
bool automatic_registration_ = true;
|
||||
};
|
||||
|
||||
} // namespace details
|
||||
} // namespace spdlog
|
||||
} // namespace details
|
||||
} // namespace spdlog
|
||||
|
@ -19,4 +19,4 @@ struct synchronous_factory {
|
||||
return new_logger;
|
||||
}
|
||||
};
|
||||
} // namespace spdlog
|
||||
} // namespace spdlog
|
||||
|
@ -66,9 +66,9 @@ public:
|
||||
struct addrinfo hints {};
|
||||
ZeroMemory(&hints, sizeof(hints));
|
||||
|
||||
hints.ai_family = AF_UNSPEC; // To work with IPv4, IPv6, and so on
|
||||
hints.ai_socktype = SOCK_STREAM; // TCP
|
||||
hints.ai_flags = AI_NUMERICSERV; // port passed as as numeric value
|
||||
hints.ai_family = AF_UNSPEC; // To work with IPv4, IPv6, and so on
|
||||
hints.ai_socktype = SOCK_STREAM; // TCP
|
||||
hints.ai_flags = AI_NUMERICSERV; // port passed as as numeric value
|
||||
hints.ai_protocol = 0;
|
||||
|
||||
auto port_str = std::to_string(port);
|
||||
@ -123,7 +123,7 @@ public:
|
||||
throw_winsock_error_("send failed", last_error);
|
||||
}
|
||||
|
||||
if (write_result == 0) // (probably should not happen but in any case..)
|
||||
if (write_result == 0) // (probably should not happen but in any case..)
|
||||
{
|
||||
break;
|
||||
}
|
||||
@ -131,5 +131,5 @@ public:
|
||||
}
|
||||
}
|
||||
};
|
||||
} // namespace details
|
||||
} // namespace spdlog
|
||||
} // namespace details
|
||||
} // namespace spdlog
|
||||
|
@ -44,9 +44,9 @@ public:
|
||||
close();
|
||||
struct addrinfo hints {};
|
||||
memset(&hints, 0, sizeof(struct addrinfo));
|
||||
hints.ai_family = AF_UNSPEC; // To work with IPv4, IPv6, and so on
|
||||
hints.ai_socktype = SOCK_STREAM; // TCP
|
||||
hints.ai_flags = AI_NUMERICSERV; // port passed as as numeric value
|
||||
hints.ai_family = AF_UNSPEC; // To work with IPv4, IPv6, and so on
|
||||
hints.ai_socktype = SOCK_STREAM; // TCP
|
||||
hints.ai_flags = AI_NUMERICSERV; // port passed as as numeric value
|
||||
hints.ai_protocol = 0;
|
||||
|
||||
auto port_str = std::to_string(port);
|
||||
@ -115,7 +115,7 @@ public:
|
||||
throw_spdlog_ex("write(2) failed", errno);
|
||||
}
|
||||
|
||||
if (write_result == 0) // (probably should not happen but in any case..)
|
||||
if (write_result == 0) // (probably should not happen but in any case..)
|
||||
{
|
||||
break;
|
||||
}
|
||||
@ -123,5 +123,5 @@ public:
|
||||
}
|
||||
}
|
||||
};
|
||||
} // namespace details
|
||||
} // namespace spdlog
|
||||
} // namespace details
|
||||
} // namespace spdlog
|
||||
|
@ -48,7 +48,7 @@ struct async_msg : log_msg_buffer {
|
||||
worker_ptr = std::move(other.worker_ptr);
|
||||
return *this;
|
||||
}
|
||||
#else // (_MSC_VER) && _MSC_VER <= 1800
|
||||
#else // (_MSC_VER) && _MSC_VER <= 1800
|
||||
async_msg(async_msg &&) = default;
|
||||
async_msg &operator=(async_msg &&) = default;
|
||||
#endif
|
||||
@ -110,5 +110,5 @@ private:
|
||||
bool process_next_msg_();
|
||||
};
|
||||
|
||||
} // namespace details
|
||||
} // namespace spdlog
|
||||
} // namespace details
|
||||
} // namespace spdlog
|
||||
|
@ -94,5 +94,5 @@ public:
|
||||
}
|
||||
}
|
||||
};
|
||||
} // namespace details
|
||||
} // namespace spdlog
|
||||
} // namespace details
|
||||
} // namespace spdlog
|
||||
|
@ -77,5 +77,5 @@ public:
|
||||
}
|
||||
}
|
||||
};
|
||||
} // namespace details
|
||||
} // namespace spdlog
|
||||
} // namespace details
|
||||
} // namespace spdlog
|
||||
|
@ -1,7 +1,7 @@
|
||||
#pragma once
|
||||
|
||||
#ifndef NOMINMAX
|
||||
#define NOMINMAX // prevent windows redefining min/max
|
||||
#define NOMINMAX // prevent windows redefining min/max
|
||||
#endif
|
||||
|
||||
#ifndef WIN32_LEAN_AND_MEAN
|
||||
|
@ -56,7 +56,7 @@ private:
|
||||
It begin_, end_;
|
||||
size_t size_per_line_;
|
||||
};
|
||||
} // namespace details
|
||||
} // namespace details
|
||||
|
||||
// create a dump_info that wraps the given container
|
||||
template <typename Container>
|
||||
@ -71,8 +71,8 @@ inline details::dump_info<typename Container::const_iterator> to_hex(const Conta
|
||||
#if __cpp_lib_span >= 202002L
|
||||
|
||||
template <typename Value, size_t Extent>
|
||||
inline details::dump_info<typename std::span<Value, Extent>::iterator>
|
||||
to_hex(const std::span<Value, Extent> &container, size_t size_per_line = 32) {
|
||||
inline details::dump_info<typename std::span<Value, Extent>::iterator> to_hex(
|
||||
const std::span<Value, Extent> &container, size_t size_per_line = 32) {
|
||||
using Container = std::span<Value, Extent>;
|
||||
static_assert(sizeof(typename Container::value_type) == 1,
|
||||
"sizeof(Container::value_type) != 1");
|
||||
@ -84,12 +84,13 @@ to_hex(const std::span<Value, Extent> &container, size_t size_per_line = 32) {
|
||||
|
||||
// create dump_info from ranges
|
||||
template <typename It>
|
||||
inline details::dump_info<It>
|
||||
to_hex(const It range_begin, const It range_end, size_t size_per_line = 32) {
|
||||
inline details::dump_info<It> to_hex(const It range_begin,
|
||||
const It range_end,
|
||||
size_t size_per_line = 32) {
|
||||
return details::dump_info<It>(range_begin, range_end, size_per_line);
|
||||
}
|
||||
|
||||
} // namespace spdlog
|
||||
} // namespace spdlog
|
||||
|
||||
namespace
|
||||
#ifdef SPDLOG_USE_STD_FORMAT
|
||||
@ -105,7 +106,7 @@ struct formatter<spdlog::details::dump_info<T>, char> {
|
||||
bool put_newlines = true;
|
||||
bool put_delimiters = true;
|
||||
bool use_uppercase = false;
|
||||
bool put_positions = true; // position on start of each line
|
||||
bool put_positions = true; // position on start of each line
|
||||
bool show_ascii = false;
|
||||
|
||||
// parse the format string flags
|
||||
@ -114,24 +115,24 @@ struct formatter<spdlog::details::dump_info<T>, char> {
|
||||
auto it = ctx.begin();
|
||||
while (it != ctx.end() && *it != '}') {
|
||||
switch (*it) {
|
||||
case 'X':
|
||||
use_uppercase = true;
|
||||
break;
|
||||
case 's':
|
||||
put_delimiters = false;
|
||||
break;
|
||||
case 'p':
|
||||
put_positions = false;
|
||||
break;
|
||||
case 'n':
|
||||
put_newlines = false;
|
||||
show_ascii = false;
|
||||
break;
|
||||
case 'a':
|
||||
if (put_newlines) {
|
||||
show_ascii = true;
|
||||
}
|
||||
break;
|
||||
case 'X':
|
||||
use_uppercase = true;
|
||||
break;
|
||||
case 's':
|
||||
put_delimiters = false;
|
||||
break;
|
||||
case 'p':
|
||||
put_positions = false;
|
||||
break;
|
||||
case 'n':
|
||||
put_newlines = false;
|
||||
show_ascii = false;
|
||||
break;
|
||||
case 'a':
|
||||
if (put_newlines) {
|
||||
show_ascii = true;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
++it;
|
||||
@ -185,7 +186,7 @@ struct formatter<spdlog::details::dump_info<T>, char> {
|
||||
*inserter++ = hex_chars[(ch >> 4) & 0x0f];
|
||||
*inserter++ = hex_chars[ch & 0x0f];
|
||||
}
|
||||
if (show_ascii) // add ascii to last line
|
||||
if (show_ascii) // add ascii to last line
|
||||
{
|
||||
if (the_range.get_end() - the_range.get_begin() > size_per_line) {
|
||||
auto blank_num = size_per_line - (the_range.get_end() - start_of_line);
|
||||
@ -220,4 +221,4 @@ struct formatter<spdlog::details::dump_info<T>, char> {
|
||||
}
|
||||
}
|
||||
};
|
||||
} // namespace std
|
||||
} // namespace std
|
||||
|
@ -10,12 +10,12 @@
|
||||
// By default, spdlog include its own copy.
|
||||
//
|
||||
|
||||
#if defined(SPDLOG_USE_STD_FORMAT) // SPDLOG_USE_STD_FORMAT is defined - use std::format
|
||||
#if defined(SPDLOG_USE_STD_FORMAT) // SPDLOG_USE_STD_FORMAT is defined - use std::format
|
||||
#include <format>
|
||||
#elif !defined(SPDLOG_FMT_EXTERNAL)
|
||||
#include <spdlog/fmt/bundled/core.h>
|
||||
#include <spdlog/fmt/bundled/format.h>
|
||||
#else // SPDLOG_FMT_EXTERNAL is defined - use external fmtlib
|
||||
#else // SPDLOG_FMT_EXTERNAL is defined - use external fmtlib
|
||||
#include <fmt/core.h>
|
||||
#include <fmt/format.h>
|
||||
#endif
|
||||
|
@ -14,4 +14,4 @@ public:
|
||||
virtual void format(const details::log_msg &msg, memory_buf_t &dest) = 0;
|
||||
virtual std::unique_ptr<formatter> clone() const = 0;
|
||||
};
|
||||
} // namespace spdlog
|
||||
} // namespace spdlog
|
||||
|
@ -12,4 +12,4 @@ namespace sinks {
|
||||
class sink;
|
||||
}
|
||||
|
||||
} // namespace spdlog
|
||||
} // namespace spdlog
|
||||
|
@ -266,7 +266,7 @@ protected:
|
||||
#ifdef SPDLOG_USE_STD_FORMAT
|
||||
auto formatted = std::vformat(fmt, std::make_format_args(args...));
|
||||
sink_it_(details::log_msg(loc, name_, lvl, formatted));
|
||||
#else // use {fmt} lib
|
||||
#else // use {fmt} lib
|
||||
memory_buf_t buf;
|
||||
fmt::vformat_to(std::back_inserter(buf), fmt, fmt::make_format_args(args...));
|
||||
sink_it_(details::log_msg(loc, name_, lvl, string_view_t(buf.data(), buf.size())));
|
||||
@ -297,4 +297,4 @@ protected:
|
||||
void err_handler_(const std::string &msg);
|
||||
};
|
||||
|
||||
} // namespace spdlog
|
||||
} // namespace spdlog
|
||||
|
@ -43,14 +43,15 @@ public:
|
||||
: padinfo_(padinfo) {}
|
||||
flag_formatter() = default;
|
||||
virtual ~flag_formatter() = default;
|
||||
virtual void
|
||||
format(const details::log_msg &msg, const std::tm &tm_time, memory_buf_t &dest) = 0;
|
||||
virtual void format(const details::log_msg &msg,
|
||||
const std::tm &tm_time,
|
||||
memory_buf_t &dest) = 0;
|
||||
|
||||
protected:
|
||||
padding_info padinfo_;
|
||||
};
|
||||
|
||||
} // namespace details
|
||||
} // namespace details
|
||||
|
||||
class SPDLOG_API custom_flag_formatter : public details::flag_formatter {
|
||||
public:
|
||||
@ -110,4 +111,4 @@ private:
|
||||
|
||||
void compile_pattern_(const std::string &pattern);
|
||||
};
|
||||
} // namespace spdlog
|
||||
} // namespace spdlog
|
||||
|
@ -52,7 +52,7 @@ protected:
|
||||
// See system/core/liblog/logger_write.c for explanation of return value
|
||||
int ret = android_log(priority, tag_.c_str(), msg_output);
|
||||
if (ret == -EPERM) {
|
||||
return; // !__android_log_is_loggable
|
||||
return; // !__android_log_is_loggable
|
||||
}
|
||||
int retry_count = 0;
|
||||
while ((ret == -11 /*EAGAIN*/) && (retry_count < SPDLOG_ANDROID_RETRIES)) {
|
||||
@ -74,33 +74,33 @@ private:
|
||||
// __android_log_buf_write, if user explicitly provides a non-default log buffer. Otherwise,
|
||||
// when using the default log buffer, always log via __android_log_write.
|
||||
template <int ID = BufferID>
|
||||
typename std::enable_if<ID == static_cast<int>(log_id::LOG_ID_MAIN), int>::type
|
||||
android_log(int prio, const char *tag, const char *text) {
|
||||
typename std::enable_if<ID == static_cast<int>(log_id::LOG_ID_MAIN), int>::type android_log(
|
||||
int prio, const char *tag, const char *text) {
|
||||
return __android_log_write(prio, tag, text);
|
||||
}
|
||||
|
||||
template <int ID = BufferID>
|
||||
typename std::enable_if<ID != static_cast<int>(log_id::LOG_ID_MAIN), int>::type
|
||||
android_log(int prio, const char *tag, const char *text) {
|
||||
typename std::enable_if<ID != static_cast<int>(log_id::LOG_ID_MAIN), int>::type android_log(
|
||||
int prio, const char *tag, const char *text) {
|
||||
return __android_log_buf_write(ID, prio, tag, text);
|
||||
}
|
||||
|
||||
static android_LogPriority convert_to_android_(spdlog::level level) {
|
||||
switch (level) {
|
||||
case spdlog::level::trace:
|
||||
return ANDROID_LOG_VERBOSE;
|
||||
case spdlog::level::debug:
|
||||
return ANDROID_LOG_DEBUG;
|
||||
case spdlog::level::info:
|
||||
return ANDROID_LOG_INFO;
|
||||
case spdlog::level::warn:
|
||||
return ANDROID_LOG_WARN;
|
||||
case spdlog::level::err:
|
||||
return ANDROID_LOG_ERROR;
|
||||
case spdlog::level::critical:
|
||||
return ANDROID_LOG_FATAL;
|
||||
default:
|
||||
return ANDROID_LOG_DEFAULT;
|
||||
case spdlog::level::trace:
|
||||
return ANDROID_LOG_VERBOSE;
|
||||
case spdlog::level::debug:
|
||||
return ANDROID_LOG_DEBUG;
|
||||
case spdlog::level::info:
|
||||
return ANDROID_LOG_INFO;
|
||||
case spdlog::level::warn:
|
||||
return ANDROID_LOG_WARN;
|
||||
case spdlog::level::err:
|
||||
return ANDROID_LOG_ERROR;
|
||||
case spdlog::level::critical:
|
||||
return ANDROID_LOG_FATAL;
|
||||
default:
|
||||
return ANDROID_LOG_DEFAULT;
|
||||
}
|
||||
}
|
||||
|
||||
@ -116,7 +116,7 @@ using android_sink_buf_mt = android_sink<std::mutex, BufferId>;
|
||||
template <int BufferId = log_id::LOG_ID_MAIN>
|
||||
using android_sink_buf_st = android_sink<details::null_mutex, BufferId>;
|
||||
|
||||
} // namespace sinks
|
||||
} // namespace sinks
|
||||
|
||||
// Create and register android syslog logger
|
||||
|
||||
@ -132,6 +132,6 @@ inline std::shared_ptr<logger> android_logger_st(const std::string &logger_name,
|
||||
return Factory::template create<sinks::android_sink_st>(logger_name, tag);
|
||||
}
|
||||
|
||||
} // namespace spdlog
|
||||
} // namespace spdlog
|
||||
|
||||
#endif // __ANDROID__
|
||||
#endif // __ANDROID__
|
||||
|
@ -107,5 +107,5 @@ using ansicolor_stdout_sink_st = ansicolor_stdout_sink<details::console_nullmute
|
||||
using ansicolor_stderr_sink_mt = ansicolor_stderr_sink<details::console_mutex>;
|
||||
using ansicolor_stderr_sink_st = ansicolor_stderr_sink<details::console_nullmutex>;
|
||||
|
||||
} // namespace sinks
|
||||
} // namespace spdlog
|
||||
} // namespace sinks
|
||||
} // namespace spdlog
|
||||
|
@ -43,5 +43,5 @@ protected:
|
||||
virtual void set_pattern_(const std::string &pattern);
|
||||
virtual void set_formatter_(std::unique_ptr<spdlog::formatter> sink_formatter);
|
||||
};
|
||||
} // namespace sinks
|
||||
} // namespace spdlog
|
||||
} // namespace sinks
|
||||
} // namespace spdlog
|
||||
|
@ -35,7 +35,7 @@ private:
|
||||
using basic_file_sink_mt = basic_file_sink<std::mutex>;
|
||||
using basic_file_sink_st = basic_file_sink<details::null_mutex>;
|
||||
|
||||
} // namespace sinks
|
||||
} // namespace sinks
|
||||
|
||||
//
|
||||
// factory functions
|
||||
@ -58,4 +58,4 @@ inline std::shared_ptr<logger> basic_logger_st(const std::string &logger_name,
|
||||
event_handlers);
|
||||
}
|
||||
|
||||
} // namespace spdlog
|
||||
} // namespace spdlog
|
||||
|
@ -36,7 +36,7 @@ private:
|
||||
using callback_sink_mt = callback_sink<std::mutex>;
|
||||
using callback_sink_st = callback_sink<details::null_mutex>;
|
||||
|
||||
} // namespace sinks
|
||||
} // namespace sinks
|
||||
|
||||
//
|
||||
// factory functions
|
||||
@ -53,4 +53,4 @@ inline std::shared_ptr<logger> callback_logger_st(const std::string &logger_name
|
||||
return Factory::template create<sinks::callback_sink_st>(logger_name, callback);
|
||||
}
|
||||
|
||||
} // namespace spdlog
|
||||
} // namespace spdlog
|
||||
|
@ -194,7 +194,7 @@ using daily_file_format_sink_mt = daily_file_sink<std::mutex, daily_filename_for
|
||||
using daily_file_format_sink_st =
|
||||
daily_file_sink<details::null_mutex, daily_filename_format_calculator>;
|
||||
|
||||
} // namespace sinks
|
||||
} // namespace sinks
|
||||
|
||||
//
|
||||
// factory functions
|
||||
@ -212,14 +212,14 @@ inline std::shared_ptr<logger> daily_logger_mt(const std::string &logger_name,
|
||||
}
|
||||
|
||||
template <typename Factory = spdlog::synchronous_factory>
|
||||
inline std::shared_ptr<logger>
|
||||
daily_logger_format_mt(const std::string &logger_name,
|
||||
const filename_t &filename,
|
||||
int hour = 0,
|
||||
int minute = 0,
|
||||
bool truncate = false,
|
||||
uint16_t max_files = 0,
|
||||
const file_event_handlers &event_handlers = {}) {
|
||||
inline std::shared_ptr<logger> daily_logger_format_mt(
|
||||
const std::string &logger_name,
|
||||
const filename_t &filename,
|
||||
int hour = 0,
|
||||
int minute = 0,
|
||||
bool truncate = false,
|
||||
uint16_t max_files = 0,
|
||||
const file_event_handlers &event_handlers = {}) {
|
||||
return Factory::template create<sinks::daily_file_format_sink_mt>(
|
||||
logger_name, filename, hour, minute, truncate, max_files, event_handlers);
|
||||
}
|
||||
@ -237,15 +237,15 @@ inline std::shared_ptr<logger> daily_logger_st(const std::string &logger_name,
|
||||
}
|
||||
|
||||
template <typename Factory = spdlog::synchronous_factory>
|
||||
inline std::shared_ptr<logger>
|
||||
daily_logger_format_st(const std::string &logger_name,
|
||||
const filename_t &filename,
|
||||
int hour = 0,
|
||||
int minute = 0,
|
||||
bool truncate = false,
|
||||
uint16_t max_files = 0,
|
||||
const file_event_handlers &event_handlers = {}) {
|
||||
inline std::shared_ptr<logger> daily_logger_format_st(
|
||||
const std::string &logger_name,
|
||||
const filename_t &filename,
|
||||
int hour = 0,
|
||||
int minute = 0,
|
||||
bool truncate = false,
|
||||
uint16_t max_files = 0,
|
||||
const file_event_handlers &event_handlers = {}) {
|
||||
return Factory::template create<sinks::daily_file_format_sink_st>(
|
||||
logger_name, filename, hour, minute, truncate, max_files, event_handlers);
|
||||
}
|
||||
} // namespace spdlog
|
||||
} // namespace spdlog
|
||||
|
@ -77,5 +77,5 @@ protected:
|
||||
using dist_sink_mt = dist_sink<std::mutex>;
|
||||
using dist_sink_st = dist_sink<details::null_mutex>;
|
||||
|
||||
} // namespace sinks
|
||||
} // namespace spdlog
|
||||
} // namespace sinks
|
||||
} // namespace spdlog
|
||||
|
@ -88,5 +88,5 @@ protected:
|
||||
using dup_filter_sink_mt = dup_filter_sink<std::mutex>;
|
||||
using dup_filter_sink_st = dup_filter_sink<details::null_mutex>;
|
||||
|
||||
} // namespace sinks
|
||||
} // namespace spdlog
|
||||
} // namespace sinks
|
||||
} // namespace spdlog
|
||||
|
@ -164,7 +164,7 @@ private:
|
||||
using hourly_file_sink_mt = hourly_file_sink<std::mutex>;
|
||||
using hourly_file_sink_st = hourly_file_sink<details::null_mutex>;
|
||||
|
||||
} // namespace sinks
|
||||
} // namespace sinks
|
||||
|
||||
//
|
||||
// factory functions
|
||||
@ -188,4 +188,4 @@ inline std::shared_ptr<logger> hourly_logger_st(const std::string &logger_name,
|
||||
return Factory::template create<sinks::hourly_file_sink_st>(logger_name, filename, truncate,
|
||||
max_files, event_handlers);
|
||||
}
|
||||
} // namespace spdlog
|
||||
} // namespace spdlog
|
||||
|
@ -90,7 +90,7 @@ private:
|
||||
using kafka_sink_mt = kafka_sink<std::mutex>;
|
||||
using kafka_sink_st = kafka_sink<spdlog::details::null_mutex>;
|
||||
|
||||
} // namespace sinks
|
||||
} // namespace sinks
|
||||
|
||||
template <typename Factory = spdlog::synchronous_factory>
|
||||
inline std::shared_ptr<logger> kafka_logger_mt(const std::string &logger_name,
|
||||
@ -105,15 +105,15 @@ inline std::shared_ptr<logger> kafka_logger_st(const std::string &logger_name,
|
||||
}
|
||||
|
||||
template <typename Factory = spdlog::async_factory>
|
||||
inline std::shared_ptr<spdlog::logger>
|
||||
kafka_logger_async_mt(std::string logger_name, spdlog::sinks::kafka_sink_config config) {
|
||||
inline std::shared_ptr<spdlog::logger> kafka_logger_async_mt(
|
||||
std::string logger_name, spdlog::sinks::kafka_sink_config config) {
|
||||
return Factory::template create<sinks::kafka_sink_mt>(logger_name, config);
|
||||
}
|
||||
|
||||
template <typename Factory = spdlog::async_factory>
|
||||
inline std::shared_ptr<spdlog::logger>
|
||||
kafka_logger_async_st(std::string logger_name, spdlog::sinks::kafka_sink_config config) {
|
||||
inline std::shared_ptr<spdlog::logger> kafka_logger_async_st(
|
||||
std::string logger_name, spdlog::sinks::kafka_sink_config config) {
|
||||
return Factory::template create<sinks::kafka_sink_st>(logger_name, config);
|
||||
}
|
||||
|
||||
} // namespace spdlog
|
||||
} // namespace spdlog
|
||||
|
@ -83,26 +83,26 @@ private:
|
||||
using mongo_sink_mt = mongo_sink<std::mutex>;
|
||||
using mongo_sink_st = mongo_sink<spdlog::details::null_mutex>;
|
||||
|
||||
} // namespace sinks
|
||||
} // namespace sinks
|
||||
|
||||
template <typename Factory = spdlog::synchronous_factory>
|
||||
inline std::shared_ptr<logger>
|
||||
mongo_logger_mt(const std::string &logger_name,
|
||||
const std::string &db_name,
|
||||
const std::string &collection_name,
|
||||
const std::string &uri = "mongodb://localhost:27017") {
|
||||
inline std::shared_ptr<logger> mongo_logger_mt(
|
||||
const std::string &logger_name,
|
||||
const std::string &db_name,
|
||||
const std::string &collection_name,
|
||||
const std::string &uri = "mongodb://localhost:27017") {
|
||||
return Factory::template create<sinks::mongo_sink_mt>(logger_name, db_name, collection_name,
|
||||
uri);
|
||||
}
|
||||
|
||||
template <typename Factory = spdlog::synchronous_factory>
|
||||
inline std::shared_ptr<logger>
|
||||
mongo_logger_st(const std::string &logger_name,
|
||||
const std::string &db_name,
|
||||
const std::string &collection_name,
|
||||
const std::string &uri = "mongodb://localhost:27017") {
|
||||
inline std::shared_ptr<logger> mongo_logger_st(
|
||||
const std::string &logger_name,
|
||||
const std::string &db_name,
|
||||
const std::string &collection_name,
|
||||
const std::string &uri = "mongodb://localhost:27017") {
|
||||
return Factory::template create<sinks::mongo_sink_st>(logger_name, db_name, collection_name,
|
||||
uri);
|
||||
}
|
||||
|
||||
} // namespace spdlog
|
||||
} // namespace spdlog
|
||||
|
@ -34,7 +34,7 @@ protected:
|
||||
}
|
||||
memory_buf_t formatted;
|
||||
base_sink<Mutex>::formatter_->format(msg, formatted);
|
||||
formatted.push_back('\0'); // add a null terminator for OutputDebugString
|
||||
formatted.push_back('\0'); // add a null terminator for OutputDebugString
|
||||
OutputDebugStringA(formatted.data());
|
||||
}
|
||||
|
||||
@ -49,7 +49,7 @@ using msvc_sink_st = msvc_sink<details::null_mutex>;
|
||||
using windebug_sink_mt = msvc_sink_mt;
|
||||
using windebug_sink_st = msvc_sink_st;
|
||||
|
||||
} // namespace sinks
|
||||
} // namespace spdlog
|
||||
} // namespace sinks
|
||||
} // namespace spdlog
|
||||
|
||||
#endif
|
||||
|
@ -22,7 +22,7 @@ protected:
|
||||
using null_sink_mt = null_sink<details::null_mutex>;
|
||||
using null_sink_st = null_sink<details::null_mutex>;
|
||||
|
||||
} // namespace sinks
|
||||
} // namespace sinks
|
||||
|
||||
template <typename Factory = spdlog::synchronous_factory>
|
||||
inline std::shared_ptr<logger> null_logger_mt(const std::string &logger_name) {
|
||||
@ -38,4 +38,4 @@ inline std::shared_ptr<logger> null_logger_st(const std::string &logger_name) {
|
||||
return null_logger;
|
||||
}
|
||||
|
||||
} // namespace spdlog
|
||||
} // namespace spdlog
|
||||
|
@ -39,5 +39,5 @@ protected:
|
||||
using ostream_sink_mt = ostream_sink<std::mutex>;
|
||||
using ostream_sink_st = ostream_sink<details::null_mutex>;
|
||||
|
||||
} // namespace sinks
|
||||
} // namespace spdlog
|
||||
} // namespace sinks
|
||||
} // namespace spdlog
|
||||
|
@ -167,13 +167,13 @@ protected:
|
||||
payload = QString::fromLatin1(str.data(), static_cast<int>(str.size()));
|
||||
}
|
||||
|
||||
invoke_params params{max_lines_, // max lines
|
||||
qt_text_edit_, // text edit to append to
|
||||
std::move(payload), // text to append
|
||||
default_color_, // default color
|
||||
colors_.at(msg.log_level), // color to apply
|
||||
color_range_start, // color range start
|
||||
color_range_end}; // color range end
|
||||
invoke_params params{max_lines_, // max lines
|
||||
qt_text_edit_, // text edit to append to
|
||||
std::move(payload), // text to append
|
||||
default_color_, // default color
|
||||
colors_.at(msg.log_level), // color to apply
|
||||
color_range_start, // color range start
|
||||
color_range_end}; // color range end
|
||||
|
||||
QMetaObject::invokeMethod(
|
||||
qt_text_edit_, [params]() { invoke_method_(params); }, Qt::AutoConnection);
|
||||
@ -193,7 +193,7 @@ protected:
|
||||
while (document->blockCount() > params.max_lines) {
|
||||
cursor.select(QTextCursor::BlockUnderCursor);
|
||||
cursor.removeSelectedText();
|
||||
cursor.deleteChar(); // delete the newline after the block
|
||||
cursor.deleteChar(); // delete the newline after the block
|
||||
}
|
||||
|
||||
cursor.movePosition(QTextCursor::End);
|
||||
@ -232,7 +232,7 @@ using qt_sink_mt = qt_sink<std::mutex>;
|
||||
using qt_sink_st = qt_sink<details::null_mutex>;
|
||||
using qt_color_sink_mt = qt_color_sink<std::mutex>;
|
||||
using qt_color_sink_st = qt_color_sink<details::null_mutex>;
|
||||
} // namespace sinks
|
||||
} // namespace sinks
|
||||
|
||||
//
|
||||
// Factory functions
|
||||
@ -269,14 +269,16 @@ inline std::shared_ptr<logger> qt_logger_st(const std::string &logger_name,
|
||||
}
|
||||
// log to QObject
|
||||
template <typename Factory = spdlog::synchronous_factory>
|
||||
inline std::shared_ptr<logger>
|
||||
qt_logger_mt(const std::string &logger_name, QObject *qt_object, const std::string &meta_method) {
|
||||
inline std::shared_ptr<logger> qt_logger_mt(const std::string &logger_name,
|
||||
QObject *qt_object,
|
||||
const std::string &meta_method) {
|
||||
return Factory::template create<sinks::qt_sink_mt>(logger_name, qt_object, meta_method);
|
||||
}
|
||||
|
||||
template <typename Factory = spdlog::synchronous_factory>
|
||||
inline std::shared_ptr<logger>
|
||||
qt_logger_st(const std::string &logger_name, QObject *qt_object, const std::string &meta_method) {
|
||||
inline std::shared_ptr<logger> qt_logger_st(const std::string &logger_name,
|
||||
QObject *qt_object,
|
||||
const std::string &meta_method) {
|
||||
return Factory::template create<sinks::qt_sink_st>(logger_name, qt_object, meta_method);
|
||||
}
|
||||
|
||||
@ -299,4 +301,4 @@ inline std::shared_ptr<logger> qt_color_logger_st(const std::string &logger_name
|
||||
false, is_utf8);
|
||||
}
|
||||
|
||||
} // namespace spdlog
|
||||
} // namespace spdlog
|
||||
|
@ -59,5 +59,5 @@ private:
|
||||
using ringbuffer_sink_mt = ringbuffer_sink<std::mutex>;
|
||||
using ringbuffer_sink_st = ringbuffer_sink<details::null_mutex>;
|
||||
|
||||
} // namespace sinks
|
||||
} // namespace spdlog
|
||||
} // namespace sinks
|
||||
} // namespace spdlog
|
||||
|
@ -55,7 +55,7 @@ private:
|
||||
using rotating_file_sink_mt = rotating_file_sink<std::mutex>;
|
||||
using rotating_file_sink_st = rotating_file_sink<details::null_mutex>;
|
||||
|
||||
} // namespace sinks
|
||||
} // namespace sinks
|
||||
|
||||
//
|
||||
// factory functions
|
||||
@ -82,4 +82,4 @@ inline std::shared_ptr<logger> rotating_logger_st(const std::string &logger_name
|
||||
return Factory::template create<sinks::rotating_file_sink_st>(
|
||||
logger_name, filename, max_file_size, max_files, rotate_on_open, event_handlers);
|
||||
}
|
||||
} // namespace spdlog
|
||||
} // namespace spdlog
|
||||
|
@ -25,5 +25,5 @@ protected:
|
||||
atomic_level_t level_{level::trace};
|
||||
};
|
||||
|
||||
} // namespace sinks
|
||||
} // namespace spdlog
|
||||
} // namespace sinks
|
||||
} // namespace spdlog
|
||||
|
@ -25,7 +25,7 @@ using stdout_color_sink_st = ansicolor_stdout_sink_st;
|
||||
using stderr_color_sink_mt = ansicolor_stderr_sink_mt;
|
||||
using stderr_color_sink_st = ansicolor_stderr_sink_st;
|
||||
#endif
|
||||
} // namespace sinks
|
||||
} // namespace sinks
|
||||
|
||||
// template instantations
|
||||
|
||||
@ -45,4 +45,4 @@ template <typename Factory = spdlog::synchronous_factory>
|
||||
std::shared_ptr<logger> stderr_color_st(const std::string &logger_name,
|
||||
color_mode mode = color_mode::automatic);
|
||||
|
||||
} // namespace spdlog
|
||||
} // namespace spdlog
|
||||
|
@ -41,7 +41,7 @@ protected:
|
||||
std::unique_ptr<spdlog::formatter> formatter_;
|
||||
#ifdef _WIN32
|
||||
HANDLE handle_;
|
||||
#endif // WIN32
|
||||
#endif // WIN32
|
||||
};
|
||||
|
||||
template <typename ConsoleMutex>
|
||||
@ -62,7 +62,7 @@ using stdout_sink_st = stdout_sink<details::console_nullmutex>;
|
||||
using stderr_sink_mt = stderr_sink<details::console_mutex>;
|
||||
using stderr_sink_st = stderr_sink<details::console_nullmutex>;
|
||||
|
||||
} // namespace sinks
|
||||
} // namespace sinks
|
||||
|
||||
// factory methods
|
||||
template <typename Factory = spdlog::synchronous_factory>
|
||||
@ -77,4 +77,4 @@ std::shared_ptr<logger> stderr_logger_mt(const std::string &logger_name);
|
||||
template <typename Factory = spdlog::synchronous_factory>
|
||||
std::shared_ptr<logger> stderr_logger_st(const std::string &logger_name);
|
||||
|
||||
} // namespace spdlog
|
||||
} // namespace spdlog
|
||||
|
@ -18,7 +18,6 @@ namespace sinks {
|
||||
*/
|
||||
template <typename Mutex>
|
||||
class syslog_sink : public base_sink<Mutex> {
|
||||
|
||||
public:
|
||||
syslog_sink(std::string ident, int syslog_option, int syslog_facility, bool enable_formatting)
|
||||
: enable_formatting_{enable_formatting},
|
||||
@ -79,7 +78,7 @@ private:
|
||||
|
||||
using syslog_sink_mt = syslog_sink<std::mutex>;
|
||||
using syslog_sink_st = syslog_sink<details::null_mutex>;
|
||||
} // namespace sinks
|
||||
} // namespace sinks
|
||||
|
||||
// Create and register a syslog logger
|
||||
template <typename Factory = spdlog::synchronous_factory>
|
||||
@ -101,4 +100,4 @@ inline std::shared_ptr<logger> syslog_logger_st(const std::string &logger_name,
|
||||
return Factory::template create<sinks::syslog_sink_st>(logger_name, syslog_ident, syslog_option,
|
||||
syslog_facility, enable_formatting);
|
||||
}
|
||||
} // namespace spdlog
|
||||
} // namespace spdlog
|
||||
|
@ -100,7 +100,7 @@ protected:
|
||||
|
||||
using systemd_sink_mt = systemd_sink<std::mutex>;
|
||||
using systemd_sink_st = systemd_sink<details::null_mutex>;
|
||||
} // namespace sinks
|
||||
} // namespace sinks
|
||||
|
||||
// Create and register a syslog logger
|
||||
template <typename Factory = spdlog::synchronous_factory>
|
||||
@ -116,4 +116,4 @@ inline std::shared_ptr<logger> systemd_logger_st(const std::string &logger_name,
|
||||
bool enable_formatting = false) {
|
||||
return Factory::template create<sinks::systemd_sink_st>(logger_name, ident, enable_formatting);
|
||||
}
|
||||
} // namespace spdlog
|
||||
} // namespace spdlog
|
||||
|
@ -31,7 +31,7 @@ namespace sinks {
|
||||
struct tcp_sink_config {
|
||||
std::string server_host;
|
||||
int server_port;
|
||||
bool lazy_connect = false; // if true connect on first log call instead of on construction
|
||||
bool lazy_connect = false; // if true connect on first log call instead of on construction
|
||||
|
||||
tcp_sink_config(std::string host, int port)
|
||||
: server_host{std::move(host)},
|
||||
@ -71,5 +71,5 @@ protected:
|
||||
using tcp_sink_mt = tcp_sink<std::mutex>;
|
||||
using tcp_sink_st = tcp_sink<spdlog::details::null_mutex>;
|
||||
|
||||
} // namespace sinks
|
||||
} // namespace spdlog
|
||||
} // namespace sinks
|
||||
} // namespace spdlog
|
||||
|
@ -55,7 +55,7 @@ protected:
|
||||
using udp_sink_mt = udp_sink<std::mutex>;
|
||||
using udp_sink_st = udp_sink<spdlog::details::null_mutex>;
|
||||
|
||||
} // namespace sinks
|
||||
} // namespace sinks
|
||||
|
||||
//
|
||||
// factory functions
|
||||
@ -66,4 +66,4 @@ inline std::shared_ptr<logger> udp_logger_mt(const std::string &logger_name,
|
||||
return Factory::template create<sinks::udp_sink_mt>(logger_name, skin_config);
|
||||
}
|
||||
|
||||
} // namespace spdlog
|
||||
} // namespace spdlog
|
||||
|
@ -131,7 +131,7 @@ public:
|
||||
~process_token_t() { ::CloseHandle(token_handle_); }
|
||||
|
||||
} current_process_token(
|
||||
::GetCurrentProcess()); // GetCurrentProcess returns pseudohandle, no leak here!
|
||||
::GetCurrentProcess()); // GetCurrentProcess returns pseudohandle, no leak here!
|
||||
|
||||
// Get the required size, this is expected to fail with ERROR_INSUFFICIENT_BUFFER and return
|
||||
// the token size
|
||||
@ -156,30 +156,30 @@ public:
|
||||
struct eventlog {
|
||||
static WORD get_event_type(details::log_msg const &msg) {
|
||||
switch (msg.log_level) {
|
||||
case level::trace:
|
||||
case level::debug:
|
||||
return EVENTLOG_SUCCESS;
|
||||
case level::trace:
|
||||
case level::debug:
|
||||
return EVENTLOG_SUCCESS;
|
||||
|
||||
case level::info:
|
||||
return EVENTLOG_INFORMATION_TYPE;
|
||||
case level::info:
|
||||
return EVENTLOG_INFORMATION_TYPE;
|
||||
|
||||
case spdlog::level::warn:
|
||||
return EVENTLOG_WARNING_TYPE;
|
||||
case spdlog::level::warn:
|
||||
return EVENTLOG_WARNING_TYPE;
|
||||
|
||||
case level::err:
|
||||
case level::critical:
|
||||
case level::off:
|
||||
return EVENTLOG_ERROR_TYPE;
|
||||
case level::err:
|
||||
case level::critical:
|
||||
case level::off:
|
||||
return EVENTLOG_ERROR_TYPE;
|
||||
|
||||
default:
|
||||
return EVENTLOG_INFORMATION_TYPE;
|
||||
default:
|
||||
return EVENTLOG_INFORMATION_TYPE;
|
||||
}
|
||||
}
|
||||
|
||||
static WORD get_event_category(details::log_msg const &msg) { return (WORD)msg.log_level; }
|
||||
};
|
||||
|
||||
} // namespace internal
|
||||
} // namespace internal
|
||||
|
||||
/*
|
||||
* Windows Event Log sink
|
||||
@ -238,15 +238,14 @@ public:
|
||||
}
|
||||
|
||||
~win_eventlog_sink() {
|
||||
if (hEventLog_)
|
||||
DeregisterEventSource(hEventLog_);
|
||||
if (hEventLog_) DeregisterEventSource(hEventLog_);
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace win_eventlog
|
||||
} // namespace win_eventlog
|
||||
|
||||
using win_eventlog_sink_mt = win_eventlog::win_eventlog_sink<std::mutex>;
|
||||
using win_eventlog_sink_st = win_eventlog::win_eventlog_sink<details::null_mutex>;
|
||||
|
||||
} // namespace sinks
|
||||
} // namespace spdlog
|
||||
} // namespace sinks
|
||||
} // namespace spdlog
|
||||
|
@ -74,5 +74,5 @@ using wincolor_stdout_sink_st = wincolor_stdout_sink<details::console_nullmutex>
|
||||
|
||||
using wincolor_stderr_sink_mt = wincolor_stderr_sink<details::console_mutex>;
|
||||
using wincolor_stderr_sink_st = wincolor_stderr_sink<details::console_nullmutex>;
|
||||
} // namespace sinks
|
||||
} // namespace spdlog
|
||||
} // namespace sinks
|
||||
} // namespace spdlog
|
||||
|
@ -251,7 +251,7 @@ inline void error(string_view_t msg) { log(level::err, msg); }
|
||||
inline void critical(string_view_t msg) { log(level::critical, msg); }
|
||||
#endif
|
||||
|
||||
} // namespace spdlog
|
||||
} // namespace spdlog
|
||||
|
||||
//
|
||||
// enable/disable log calls at compile time according to global level.
|
||||
@ -328,4 +328,4 @@ inline void critical(string_view_t msg) { log(level::critical, msg); }
|
||||
#define SPDLOG_CRITICAL(...) (void)0
|
||||
#endif
|
||||
|
||||
#endif // SPDLOG_H
|
||||
#endif // SPDLOG_H
|
||||
|
@ -41,7 +41,7 @@ public:
|
||||
|
||||
void reset() { start_tp_ = clock::now(); }
|
||||
};
|
||||
} // namespace spdlog
|
||||
} // namespace spdlog
|
||||
|
||||
// Support for fmt formatting (e.g. "{:012.9}" or just "{}")
|
||||
namespace
|
||||
@ -59,4 +59,4 @@ struct formatter<spdlog::stopwatch> : formatter<double> {
|
||||
return formatter<double>::format(sw.elapsed().count(), ctx);
|
||||
}
|
||||
};
|
||||
} // namespace std
|
||||
} // namespace std
|
||||
|
@ -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
|
||||
|
@ -2,7 +2,7 @@
|
||||
|
||||
#if defined(__GNUC__) && __GNUC__ == 12
|
||||
#pragma GCC diagnostic push
|
||||
#pragma GCC diagnostic ignored "-Wmaybe-uninitialized" // Workaround for GCC 12
|
||||
#pragma GCC diagnostic ignored "-Wmaybe-uninitialized" // Workaround for GCC 12
|
||||
#endif
|
||||
#include <catch2/catch_all.hpp>
|
||||
#if defined(__GNUC__) && __GNUC__ == 12
|
||||
|
@ -1,6 +1,6 @@
|
||||
#if defined(__GNUC__) && __GNUC__ == 12
|
||||
#pragma GCC diagnostic push
|
||||
#pragma GCC diagnostic ignored "-Wmaybe-uninitialized" // Workaround for GCC 12
|
||||
#pragma GCC diagnostic ignored "-Wmaybe-uninitialized" // Workaround for GCC 12
|
||||
#endif
|
||||
|
||||
#include <catch2/catch_all.hpp>
|
||||
|
@ -94,7 +94,6 @@ TEST_CASE("flush", "[async]") {
|
||||
}
|
||||
|
||||
TEST_CASE("async periodic flush", "[async]") {
|
||||
|
||||
auto logger = spdlog::create_async<spdlog::sinks::test_sink_mt>("as");
|
||||
auto test_sink = std::static_pointer_cast<spdlog::sinks::test_sink_mt>(logger->sinks()[0]);
|
||||
|
||||
|
@ -23,7 +23,7 @@ TEST_CASE("test_rolling", "[circular_q]") {
|
||||
|
||||
for (size_t i = 0; i < q_size + 2; i++) {
|
||||
auto val = i;
|
||||
q.push_back(std::move(val)); // arg to push_back must be r value
|
||||
q.push_back(std::move(val)); // arg to push_back must be r value
|
||||
}
|
||||
|
||||
REQUIRE(q.size() == q_size);
|
||||
@ -49,7 +49,7 @@ TEST_CASE("test_rolling", "[circular_q]") {
|
||||
TEST_CASE("test_empty", "[circular_q]") {
|
||||
q_type q1(0);
|
||||
REQUIRE(q1.empty());
|
||||
REQUIRE(q1.full()); // q with capacity 0 is considered full
|
||||
REQUIRE(q1.full()); // q with capacity 0 is considered full
|
||||
q1.push_back(1);
|
||||
REQUIRE(q1.empty());
|
||||
|
||||
|
@ -19,7 +19,7 @@ TEST_CASE("create_dir", "[create_dir]") {
|
||||
REQUIRE(try_create_dir(SPDLOG_FILENAME_T("test_logs/dir1/dir1"),
|
||||
SPDLOG_FILENAME_T("test_logs/dir1/dir1")));
|
||||
REQUIRE(try_create_dir(SPDLOG_FILENAME_T("test_logs/dir1/dir1"),
|
||||
SPDLOG_FILENAME_T("test_logs/dir1/dir1"))); // test existing
|
||||
SPDLOG_FILENAME_T("test_logs/dir1/dir1"))); // test existing
|
||||
REQUIRE(try_create_dir(SPDLOG_FILENAME_T("test_logs/dir1///dir2//"),
|
||||
SPDLOG_FILENAME_T("test_logs/dir1/dir2")));
|
||||
REQUIRE(try_create_dir(SPDLOG_FILENAME_T("./test_logs/dir1/dir3"),
|
||||
|
@ -37,7 +37,6 @@ TEST_CASE("daily_logger with dateonly calculator", "[daily_logger]") {
|
||||
|
||||
auto logger = spdlog::create<sink_type>("logger", basename, 0, 0);
|
||||
for (int i = 0; i < 10; ++i) {
|
||||
|
||||
logger->info("Test message {}", i);
|
||||
}
|
||||
logger->flush();
|
||||
|
@ -78,6 +78,6 @@ TEST_CASE("dup_filter_test5", "[dup_filter_sink]") {
|
||||
dup_sink.log(spdlog::details::log_msg{"test", spdlog::level::info, "message2"});
|
||||
|
||||
REQUIRE(test_sink->msg_counter() ==
|
||||
3); // skip 2 messages but log the "skipped.." message before message2
|
||||
3); // skip 2 messages but log the "skipped.." message before message2
|
||||
REQUIRE(test_sink->lines()[1] == "Skipped 2 duplicate messages..");
|
||||
}
|
||||
|
@ -19,7 +19,7 @@ protected:
|
||||
};
|
||||
struct custom_ex {};
|
||||
|
||||
#if !defined(SPDLOG_USE_STD_FORMAT) // std formt doesn't fully support runtime format strings
|
||||
#if !defined(SPDLOG_USE_STD_FORMAT) // std formt doesn't fully support runtime format strings
|
||||
TEST_CASE("default_error_handler", "[errors]") {
|
||||
prepare_logdir();
|
||||
spdlog::filename_t filename = SPDLOG_FILENAME_T(SIMPLE_LOG);
|
||||
@ -62,7 +62,7 @@ TEST_CASE("flush_error_handler", "[errors]") {
|
||||
REQUIRE_THROWS_AS(logger->flush(), custom_ex);
|
||||
}
|
||||
|
||||
#if !defined(SPDLOG_USE_STD_FORMAT) // std formt doesn't fully support runtime format strings
|
||||
#if !defined(SPDLOG_USE_STD_FORMAT) // std formt doesn't fully support runtime format strings
|
||||
TEST_CASE("async_error_handler", "[errors]") {
|
||||
prepare_logdir();
|
||||
std::string err_msg("log failed with some msg");
|
||||
@ -82,7 +82,7 @@ TEST_CASE("async_error_handler", "[errors]") {
|
||||
logger->info("Good message #1");
|
||||
logger->info(SPDLOG_FMT_RUNTIME("Bad format msg {} {}"), "xxx");
|
||||
logger->info("Good message #2");
|
||||
spdlog::drop("logger"); // force logger to drain the queue and shutdown
|
||||
spdlog::drop("logger"); // force logger to drain the queue and shutdown
|
||||
}
|
||||
spdlog::init_thread_pool(128, 1);
|
||||
require_message_count(SIMPLE_ASYNC_LOG, 2);
|
||||
@ -100,12 +100,11 @@ TEST_CASE("async_error_handler2", "[errors]") {
|
||||
auto logger = spdlog::create_async<failing_sink>("failed_logger");
|
||||
logger->set_error_handler([=](const std::string &) {
|
||||
std::ofstream ofs("test_logs/custom_err2.txt");
|
||||
if (!ofs)
|
||||
throw std::runtime_error("Failed open test_logs/custom_err2.txt");
|
||||
if (!ofs) throw std::runtime_error("Failed open test_logs/custom_err2.txt");
|
||||
ofs << err_msg;
|
||||
});
|
||||
logger->info("Hello failure");
|
||||
spdlog::drop("failed_logger"); // force logger to drain the queue and shutdown
|
||||
spdlog::drop("failed_logger"); // force logger to drain the queue and shutdown
|
||||
}
|
||||
|
||||
spdlog::init_thread_pool(128, 1);
|
||||
|
@ -72,4 +72,4 @@ TEST_CASE("eventlog", "[eventlog]") {
|
||||
"my critical message", EVENTLOG_ERROR_TYPE);
|
||||
}
|
||||
|
||||
#endif //_WIN32
|
||||
#endif //_WIN32
|
||||
|
@ -85,7 +85,6 @@ TEST_CASE("rotating_file_logger2", "[rotating_logger]") {
|
||||
require_message_count(ROTATING_LOG, 10);
|
||||
|
||||
for (int i = 0; i < 1000; i++) {
|
||||
|
||||
logger->info("Test message {}", i);
|
||||
}
|
||||
|
||||
|
@ -12,7 +12,6 @@
|
||||
#define TEST_FILENAME "test_logs/simple_log"
|
||||
|
||||
TEST_CASE("debug and trace w/o format string", "[macros]") {
|
||||
|
||||
prepare_logdir();
|
||||
spdlog::filename_t filename = SPDLOG_FILENAME_T(TEST_FILENAME);
|
||||
|
||||
|
@ -3,7 +3,6 @@
|
||||
|
||||
template <class T>
|
||||
std::string log_info(const T &what, spdlog::level logger_level = spdlog::level::info) {
|
||||
|
||||
std::ostringstream oss;
|
||||
auto oss_sink = std::make_shared<spdlog::sinks::ostream_sink_mt>(oss);
|
||||
|
||||
|
@ -22,7 +22,6 @@ TEST_CASE("dequeue-empty-nowait", "[mpmc_blocking_q]") {
|
||||
}
|
||||
|
||||
TEST_CASE("dequeue-empty-wait", "[mpmc_blocking_q]") {
|
||||
|
||||
size_t q_size = 100;
|
||||
milliseconds wait_ms(250);
|
||||
milliseconds tolerance_wait(250);
|
||||
@ -59,7 +58,6 @@ TEST_CASE("dequeue-full-wait", "[mpmc_blocking_q]") {
|
||||
}
|
||||
|
||||
TEST_CASE("enqueue_nowait", "[mpmc_blocking_q]") {
|
||||
|
||||
size_t q_size = 1;
|
||||
spdlog::details::mpmc_blocking_queue<int> q(q_size);
|
||||
milliseconds tolerance_wait(10);
|
||||
@ -96,8 +94,8 @@ TEST_CASE("full_queue", "[mpmc_blocking_q]") {
|
||||
size_t q_size = 100;
|
||||
spdlog::details::mpmc_blocking_queue<int> q(q_size);
|
||||
for (int i = 0; i < static_cast<int>(q_size); i++) {
|
||||
q.enqueue(i + 0); // i+0 to force rvalue and avoid tidy warnings on the same time if we
|
||||
// std::move(i) instead
|
||||
q.enqueue(i + 0); // i+0 to force rvalue and avoid tidy warnings on the same time if we
|
||||
// std::move(i) instead
|
||||
}
|
||||
|
||||
q.enqueue_nowait(123456);
|
||||
|
@ -53,7 +53,7 @@ TEST_CASE("test_empty", "[ringbuffer_sink]") {
|
||||
spdlog::logger l("logger", sink);
|
||||
|
||||
sink->drain([&](std::string_view) {
|
||||
REQUIRE_FALSE(true); // should not be called since the sink is empty
|
||||
REQUIRE_FALSE(true); // should not be called since the sink is empty
|
||||
});
|
||||
}
|
||||
|
||||
@ -67,6 +67,6 @@ TEST_CASE("test_empty_size", "[ringbuffer_sink]") {
|
||||
}
|
||||
|
||||
sink->drain([&](std::string_view) {
|
||||
REQUIRE_FALSE(true); // should not be called since the sink size is 0
|
||||
REQUIRE_FALSE(true); // should not be called since the sink size is 0
|
||||
});
|
||||
}
|
@ -65,5 +65,5 @@ protected:
|
||||
using test_sink_mt = test_sink<std::mutex>;
|
||||
using test_sink_st = test_sink<details::null_mutex>;
|
||||
|
||||
} // namespace sinks
|
||||
} // namespace spdlog
|
||||
} // namespace sinks
|
||||
} // namespace spdlog
|
||||
|
@ -8,7 +8,7 @@ TEST_CASE("time_point1", "[time_point log_msg]") {
|
||||
|
||||
spdlog::source_loc source{};
|
||||
std::chrono::system_clock::time_point tp{std::chrono::system_clock::now()};
|
||||
test_sink->set_pattern("%T.%F"); // interested in the time_point
|
||||
test_sink->set_pattern("%T.%F"); // interested in the time_point
|
||||
|
||||
// all the following should have the same time
|
||||
test_sink->set_delay(std::chrono::milliseconds(10));
|
||||
@ -22,7 +22,7 @@ TEST_CASE("time_point1", "[time_point log_msg]") {
|
||||
logger.log(tp, source, spdlog::level::info, "formatted message");
|
||||
logger.log(tp, source, spdlog::level::info, "formatted message");
|
||||
logger.log(source, spdlog::level::info,
|
||||
"formatted message"); // last line has different time_point
|
||||
"formatted message"); // last line has different time_point
|
||||
|
||||
// now the real test... that the times are the same.
|
||||
std::vector<std::string> lines = test_sink->lines();
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user