mirror of
https://github.com/gabime/spdlog.git
synced 2024-11-15 08:25:43 +08:00
clang format
This commit is contained in:
parent
4789065700
commit
77b07b3a10
@ -6,7 +6,7 @@ Standard: c++17
|
||||
IndentWidth: 4
|
||||
TabWidth: 4
|
||||
UseTab: Never
|
||||
ColumnLimit: 100
|
||||
ColumnLimit: 120
|
||||
AlignAfterOpenBracket: Align
|
||||
BinPackParameters: false
|
||||
AlignEscapedNewlines: Left
|
||||
|
@ -44,8 +44,7 @@ void verify_file(const char *filename, int expected_count) {
|
||||
spdlog::info("Verifying {} to contain {} line..", filename, expected_count);
|
||||
auto count = count_lines(filename);
|
||||
if (count != expected_count) {
|
||||
spdlog::error("Test failed. {} has {} lines instead of {}", filename, count,
|
||||
expected_count);
|
||||
spdlog::error("Test failed. {} has {} lines instead of {}", filename, count, expected_count);
|
||||
exit(1);
|
||||
}
|
||||
spdlog::info("Line count OK ({})\n", count);
|
||||
@ -85,8 +84,7 @@ int main(int argc, char *argv[]) {
|
||||
spdlog::info("Messages : {:L}", howmany);
|
||||
spdlog::info("Threads : {:L}", threads);
|
||||
spdlog::info("Queue : {:L} slots", queue_size);
|
||||
spdlog::info("Queue memory : {:L} x {:L} = {:L} KB ", queue_size, slot_size,
|
||||
(queue_size * slot_size) / 1024);
|
||||
spdlog::info("Queue memory : {:L} x {:L} = {:L} KB ", queue_size, slot_size, (queue_size * slot_size) / 1024);
|
||||
spdlog::info("Total iters : {:L}", iters);
|
||||
spdlog::info("-------------------------------------------------");
|
||||
|
||||
@ -98,8 +96,8 @@ int main(int argc, char *argv[]) {
|
||||
for (int i = 0; i < iters; i++) {
|
||||
auto tp = std::make_shared<details::thread_pool>(queue_size, 1);
|
||||
auto file_sink = std::make_shared<spdlog::sinks::basic_file_sink_mt>(filename, true);
|
||||
auto logger = std::make_shared<async_logger>(
|
||||
"async_logger", std::move(file_sink), std::move(tp), async_overflow_policy::block);
|
||||
auto logger = std::make_shared<async_logger>("async_logger", std::move(file_sink), std::move(tp),
|
||||
async_overflow_policy::block);
|
||||
bench_mt(howmany, std::move(logger), threads);
|
||||
// verify_file(filename, howmany);
|
||||
}
|
||||
@ -113,9 +111,8 @@ int main(int argc, char *argv[]) {
|
||||
for (int i = 0; i < iters; i++) {
|
||||
auto tp = std::make_shared<details::thread_pool>(queue_size, 1);
|
||||
auto file_sink = std::make_shared<spdlog::sinks::basic_file_sink_mt>(filename, true);
|
||||
auto logger =
|
||||
std::make_shared<async_logger>("async_logger", std::move(file_sink), std::move(tp),
|
||||
async_overflow_policy::overrun_oldest);
|
||||
auto logger = std::make_shared<async_logger>("async_logger", std::move(file_sink), std::move(tp),
|
||||
async_overflow_policy::overrun_oldest);
|
||||
bench_mt(howmany, std::move(logger), threads);
|
||||
}
|
||||
spdlog::shutdown();
|
||||
@ -142,8 +139,7 @@ void bench_mt(int howmany, std::shared_ptr<spdlog::logger> logger, int thread_co
|
||||
int msgs_per_thread_mod = howmany % thread_count;
|
||||
for (int t = 0; t < thread_count; ++t) {
|
||||
if (t == 0 && msgs_per_thread_mod)
|
||||
threads.push_back(
|
||||
std::thread(thread_fun, logger, msgs_per_thread + msgs_per_thread_mod));
|
||||
threads.push_back(std::thread(thread_fun, logger, msgs_per_thread + msgs_per_thread_mod));
|
||||
else
|
||||
threads.push_back(std::thread(thread_fun, logger, msgs_per_thread));
|
||||
}
|
||||
|
@ -38,16 +38,15 @@ static const int max_threads = 1000;
|
||||
|
||||
void bench_threaded_logging(size_t threads, int iters) {
|
||||
spdlog::info("**************************************************************");
|
||||
spdlog::info(spdlog::fmt_lib::format(
|
||||
std::locale("en_US.UTF-8"), "Multi threaded: {:L} threads, {:L} messages", threads, iters));
|
||||
spdlog::info(spdlog::fmt_lib::format(std::locale("en_US.UTF-8"), "Multi threaded: {:L} threads, {:L} messages",
|
||||
threads, iters));
|
||||
spdlog::info("**************************************************************");
|
||||
|
||||
auto basic_mt = spdlog::basic_logger_mt("basic_mt", "logs/basic_mt.log", true);
|
||||
bench_mt(iters, std::move(basic_mt), threads);
|
||||
|
||||
spdlog::info("");
|
||||
auto rotating_mt = spdlog::rotating_logger_mt("rotating_mt", "logs/rotating_mt.log", file_size,
|
||||
rotating_files);
|
||||
auto rotating_mt = spdlog::rotating_logger_mt("rotating_mt", "logs/rotating_mt.log", file_size, rotating_files);
|
||||
bench_mt(iters, std::move(rotating_mt), threads);
|
||||
|
||||
spdlog::info("");
|
||||
@ -62,16 +61,14 @@ void bench_threaded_logging(size_t threads, int iters) {
|
||||
|
||||
void bench_single_threaded(int iters) {
|
||||
spdlog::info("**************************************************************");
|
||||
spdlog::info(
|
||||
spdlog::fmt_lib::format(std::locale("en_US.UTF-8"), "Single threaded: {} messages", iters));
|
||||
spdlog::info(spdlog::fmt_lib::format(std::locale("en_US.UTF-8"), "Single threaded: {} messages", iters));
|
||||
spdlog::info("**************************************************************");
|
||||
|
||||
auto basic_st = spdlog::basic_logger_st("basic_st", "logs/basic_st.log", true);
|
||||
bench(iters, std::move(basic_st));
|
||||
|
||||
spdlog::info("");
|
||||
auto rotating_st = spdlog::rotating_logger_st("rotating_st", "logs/rotating_st.log", file_size,
|
||||
rotating_files);
|
||||
auto rotating_st = spdlog::rotating_logger_st("rotating_st", "logs/rotating_st.log", file_size, rotating_files);
|
||||
bench(iters, std::move(rotating_st));
|
||||
|
||||
spdlog::info("");
|
||||
@ -98,8 +95,7 @@ int main(int argc, char *argv[]) {
|
||||
}
|
||||
|
||||
if (threads > max_threads) {
|
||||
throw std::runtime_error(
|
||||
spdlog::fmt_lib::format("Number of threads exceeds maximum({})", max_threads));
|
||||
throw std::runtime_error(spdlog::fmt_lib::format("Number of threads exceeds maximum({})", max_threads));
|
||||
}
|
||||
|
||||
bench_single_threaded(iters);
|
||||
@ -125,9 +121,8 @@ void bench(int howmany, std::shared_ptr<spdlog::logger> log) {
|
||||
auto delta = high_resolution_clock::now() - start;
|
||||
auto delta_d = duration_cast<duration<double>>(delta).count();
|
||||
|
||||
spdlog::info(spdlog::fmt_lib::format(std::locale("en_US.UTF-8"),
|
||||
"{:<30} Elapsed: {:0.2f} secs {:>16L}/sec", log->name(),
|
||||
delta_d, size_t(howmany / delta_d)));
|
||||
spdlog::info(spdlog::fmt_lib::format(std::locale("en_US.UTF-8"), "{:<30} Elapsed: {:0.2f} secs {:>16L}/sec",
|
||||
log->name(), delta_d, size_t(howmany / delta_d)));
|
||||
spdlog::drop(log->name());
|
||||
}
|
||||
|
||||
@ -153,9 +148,8 @@ void bench_mt(int howmany, std::shared_ptr<spdlog::logger> log, size_t thread_co
|
||||
|
||||
auto delta = high_resolution_clock::now() - start;
|
||||
auto delta_d = duration_cast<duration<double>>(delta).count();
|
||||
spdlog::info(spdlog::fmt_lib::format(std::locale("en_US.UTF-8"),
|
||||
"{:<30} Elapsed: {:0.2f} secs {:>16L}/sec", log->name(),
|
||||
delta_d, size_t(howmany / delta_d)));
|
||||
spdlog::info(spdlog::fmt_lib::format(std::locale("en_US.UTF-8"), "{:<30} Elapsed: {:0.2f} secs {:>16L}/sec",
|
||||
log->name(), delta_d, size_t(howmany / delta_d)));
|
||||
spdlog::drop(log->name());
|
||||
}
|
||||
|
||||
|
@ -11,8 +11,7 @@ void bench_formatter(benchmark::State &state, std::string pattern) {
|
||||
auto formatter = std::make_unique<spdlog::pattern_formatter>(pattern);
|
||||
spdlog::memory_buf_t dest;
|
||||
std::string logger_name = "logger-name";
|
||||
const char *text =
|
||||
"Hello. This is some message with length of 80 ";
|
||||
const char *text = "Hello. This is some message with length of 80 ";
|
||||
|
||||
spdlog::source_loc source_loc{"a/b/c/d/myfile.cpp", 123, "some_func()"};
|
||||
spdlog::details::log_msg msg(source_loc, logger_name, spdlog::level::info, text);
|
||||
@ -47,8 +46,7 @@ void bench_formatters() {
|
||||
"[%Y-%m-%d %H:%M:%S.%e] [%l] [%n] [%t] %v",
|
||||
};
|
||||
for (auto &pattern : patterns) {
|
||||
benchmark::RegisterBenchmark(pattern.c_str(), &bench_formatter, pattern)
|
||||
->Iterations(2500000);
|
||||
benchmark::RegisterBenchmark(pattern.c_str(), &bench_formatter, pattern)->Iterations(2500000);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -55,8 +55,7 @@ void bench_disabled_macro(benchmark::State &state, std::shared_ptr<spdlog::logge
|
||||
}
|
||||
}
|
||||
|
||||
void bench_disabled_macro_global_logger(benchmark::State &state,
|
||||
std::shared_ptr<spdlog::logger> logger) {
|
||||
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
|
||||
@ -69,13 +68,11 @@ void bench_disabled_macro_global_logger(benchmark::State &state,
|
||||
#ifdef __linux__
|
||||
void bench_dev_null() {
|
||||
auto dev_null_st = spdlog::basic_logger_st("/dev/null_st", "/dev/null");
|
||||
benchmark::RegisterBenchmark("/dev/null_st", bench_logger, std::move(dev_null_st))
|
||||
->UseRealTime();
|
||||
benchmark::RegisterBenchmark("/dev/null_st", bench_logger, std::move(dev_null_st))->UseRealTime();
|
||||
spdlog::drop("/dev/null_st");
|
||||
|
||||
auto dev_null_mt = spdlog::basic_logger_mt("/dev/null_mt", "/dev/null");
|
||||
benchmark::RegisterBenchmark("/dev/null_mt", bench_logger, std::move(dev_null_mt))
|
||||
->UseRealTime();
|
||||
benchmark::RegisterBenchmark("/dev/null_mt", bench_logger, std::move(dev_null_mt))->UseRealTime();
|
||||
spdlog::drop("/dev/null_mt");
|
||||
}
|
||||
#endif // __linux__
|
||||
@ -91,23 +88,18 @@ int main(int argc, char *argv[]) {
|
||||
auto full_bench = argc > 1 && std::string(argv[1]) == "full";
|
||||
|
||||
// disabled loggers
|
||||
auto disabled_logger =
|
||||
std::make_shared<spdlog::logger>("bench", std::make_shared<null_sink_mt>());
|
||||
auto disabled_logger = std::make_shared<spdlog::logger>("bench", std::make_shared<null_sink_mt>());
|
||||
disabled_logger->set_level(spdlog::level::off);
|
||||
benchmark::RegisterBenchmark("disabled-at-compile-time", bench_disabled_macro, disabled_logger);
|
||||
benchmark::RegisterBenchmark("disabled-at-compile-time (global logger)",
|
||||
bench_disabled_macro_global_logger, disabled_logger);
|
||||
benchmark::RegisterBenchmark("disabled-at-runtime", bench_logger, disabled_logger);
|
||||
benchmark::RegisterBenchmark("disabled-at-runtime (global logger)", bench_global_logger,
|
||||
benchmark::RegisterBenchmark("disabled-at-compile-time (global logger)", bench_disabled_macro_global_logger,
|
||||
disabled_logger);
|
||||
benchmark::RegisterBenchmark("disabled-at-runtime", bench_logger, disabled_logger);
|
||||
benchmark::RegisterBenchmark("disabled-at-runtime (global logger)", bench_global_logger, disabled_logger);
|
||||
|
||||
auto null_logger_st =
|
||||
std::make_shared<spdlog::logger>("bench", std::make_shared<null_sink_st>());
|
||||
benchmark::RegisterBenchmark("null_sink_st (500_bytes c_str)", bench_c_string,
|
||||
std::move(null_logger_st));
|
||||
auto null_logger_st = std::make_shared<spdlog::logger>("bench", std::make_shared<null_sink_st>());
|
||||
benchmark::RegisterBenchmark("null_sink_st (500_bytes c_str)", bench_c_string, std::move(null_logger_st));
|
||||
benchmark::RegisterBenchmark("null_sink_st", bench_logger, null_logger_st);
|
||||
benchmark::RegisterBenchmark("null_sink_st (global logger)", bench_global_logger,
|
||||
null_logger_st);
|
||||
benchmark::RegisterBenchmark("null_sink_st (global logger)", bench_global_logger, null_logger_st);
|
||||
|
||||
#ifdef __linux
|
||||
bench_dev_null();
|
||||
@ -120,10 +112,9 @@ int main(int argc, char *argv[]) {
|
||||
spdlog::drop("basic_st");
|
||||
|
||||
// rotating st
|
||||
auto rotating_st = spdlog::rotating_logger_st("rotating_st", "latency_logs/rotating_st.log",
|
||||
file_size, rotating_files);
|
||||
benchmark::RegisterBenchmark("rotating_st", bench_logger, std::move(rotating_st))
|
||||
->UseRealTime();
|
||||
auto rotating_st =
|
||||
spdlog::rotating_logger_st("rotating_st", "latency_logs/rotating_st.log", file_size, rotating_files);
|
||||
benchmark::RegisterBenchmark("rotating_st", bench_logger, std::move(rotating_st))->UseRealTime();
|
||||
spdlog::drop("rotating_st");
|
||||
|
||||
// daily st
|
||||
@ -134,22 +125,17 @@ int main(int argc, char *argv[]) {
|
||||
//
|
||||
// Multi threaded bench, 10 loggers using same logger concurrently
|
||||
//
|
||||
auto null_logger_mt =
|
||||
std::make_shared<spdlog::logger>("bench", std::make_shared<null_sink_mt>());
|
||||
benchmark::RegisterBenchmark("null_sink_mt", bench_logger, null_logger_mt)
|
||||
->Threads(n_threads)
|
||||
->UseRealTime();
|
||||
auto null_logger_mt = std::make_shared<spdlog::logger>("bench", std::make_shared<null_sink_mt>());
|
||||
benchmark::RegisterBenchmark("null_sink_mt", bench_logger, null_logger_mt)->Threads(n_threads)->UseRealTime();
|
||||
|
||||
// basic_mt
|
||||
auto basic_mt = spdlog::basic_logger_mt("basic_mt", "latency_logs/basic_mt.log", true);
|
||||
benchmark::RegisterBenchmark("basic_mt", bench_logger, std::move(basic_mt))
|
||||
->Threads(n_threads)
|
||||
->UseRealTime();
|
||||
benchmark::RegisterBenchmark("basic_mt", bench_logger, std::move(basic_mt))->Threads(n_threads)->UseRealTime();
|
||||
spdlog::drop("basic_mt");
|
||||
|
||||
// rotating mt
|
||||
auto rotating_mt = spdlog::rotating_logger_mt("rotating_mt", "latency_logs/rotating_mt.log",
|
||||
file_size, rotating_files);
|
||||
auto rotating_mt =
|
||||
spdlog::rotating_logger_mt("rotating_mt", "latency_logs/rotating_mt.log", file_size, rotating_files);
|
||||
benchmark::RegisterBenchmark("rotating_mt", bench_logger, std::move(rotating_mt))
|
||||
->Threads(n_threads)
|
||||
->UseRealTime();
|
||||
@ -157,9 +143,7 @@ int main(int argc, char *argv[]) {
|
||||
|
||||
// daily mt
|
||||
auto daily_mt = spdlog::daily_logger_mt("daily_mt", "latency_logs/daily_mt.log");
|
||||
benchmark::RegisterBenchmark("daily_mt", bench_logger, std::move(daily_mt))
|
||||
->Threads(n_threads)
|
||||
->UseRealTime();
|
||||
benchmark::RegisterBenchmark("daily_mt", bench_logger, std::move(daily_mt))->Threads(n_threads)->UseRealTime();
|
||||
spdlog::drop("daily_mt");
|
||||
}
|
||||
|
||||
@ -167,11 +151,8 @@ int main(int argc, char *argv[]) {
|
||||
auto queue_size = 1024 * 1024 * 3;
|
||||
auto tp = std::make_shared<spdlog::details::thread_pool>(queue_size, 1);
|
||||
auto async_logger = std::make_shared<spdlog::async_logger>(
|
||||
"async_logger", std::make_shared<null_sink_mt>(), std::move(tp),
|
||||
spdlog::async_overflow_policy::overrun_oldest);
|
||||
benchmark::RegisterBenchmark("async_logger", bench_logger, async_logger)
|
||||
->Threads(n_threads)
|
||||
->UseRealTime();
|
||||
"async_logger", std::make_shared<null_sink_mt>(), std::move(tp), spdlog::async_overflow_policy::overrun_oldest);
|
||||
benchmark::RegisterBenchmark("async_logger", bench_logger, async_logger)->Threads(n_threads)->UseRealTime();
|
||||
benchmark::Initialize(&argc, argv);
|
||||
benchmark::RunSpecifiedBenchmarks();
|
||||
}
|
||||
|
@ -37,9 +37,8 @@ void replace_default_logger_example();
|
||||
int main(int, char *[]) {
|
||||
// Log levels can be loaded from argv/env using "SPDLOG_LEVEL"
|
||||
load_levels_example();
|
||||
|
||||
spdlog::info("Welcome to spdlog version {}.{}.{} !", SPDLOG_VER_MAJOR, SPDLOG_VER_MINOR,
|
||||
SPDLOG_VER_PATCH);
|
||||
SPDLOG_INFO("This message should be displayed..");
|
||||
spdlog::info("Welcome to spdlog version {}.{}.{} !", SPDLOG_VER_MAJOR, SPDLOG_VER_MINOR, SPDLOG_VER_PATCH);
|
||||
spdlog::warn("Easy padding in numbers like {:08d}", 12);
|
||||
spdlog::critical("Support for int: {0:d}; hex: {0:x}; oct: {0:o}; bin: {0:b}", 42);
|
||||
spdlog::info("Support for floats {:03.2f}", 1.23456);
|
||||
@ -99,7 +98,7 @@ int main(int, char *[]) {
|
||||
#include "spdlog/sinks/stdout_color_sinks.h"
|
||||
// or #include "spdlog/sinks/stdout_sinks.h" if no colors needed.
|
||||
void stdout_logger_example() {
|
||||
// Create color multi threaded logger.
|
||||
// Create color multithreading logger.
|
||||
auto console = spdlog::stdout_color_mt("console");
|
||||
// or for stderr:
|
||||
// auto console = spdlog::stderr_color_mt("error-logger");
|
||||
@ -114,8 +113,7 @@ void basic_example() {
|
||||
#include "spdlog/sinks/rotating_file_sink.h"
|
||||
void rotating_example() {
|
||||
// Create a file rotating logger with 5mb size max and 3 rotated files.
|
||||
auto rotating_logger =
|
||||
spdlog::rotating_logger_mt("some_logger_name", "logs/rotating.txt", 1048576 * 5, 3);
|
||||
auto rotating_logger = spdlog::rotating_logger_mt("some_logger_name", "logs/rotating.txt", 1048576 * 5, 3);
|
||||
}
|
||||
|
||||
#include "spdlog/sinks/daily_file_sink.h"
|
||||
@ -127,10 +125,9 @@ void daily_example() {
|
||||
#include "spdlog/sinks/callback_sink.h"
|
||||
void callback_example() {
|
||||
// Create the logger
|
||||
auto logger = spdlog::callback_logger_mt("custom_callback_logger",
|
||||
[](const spdlog::details::log_msg & /*msg*/) {
|
||||
// do what you need to do with msg
|
||||
});
|
||||
auto logger = spdlog::callback_logger_mt("custom_callback_logger", [](const spdlog::details::log_msg & /*msg*/) {
|
||||
// do what you need to do with msg
|
||||
});
|
||||
}
|
||||
|
||||
void load_levels_example() {
|
||||
@ -148,8 +145,7 @@ void load_levels_example() {
|
||||
void async_example() {
|
||||
// Default thread pool settings can be modified *before* creating the async logger:
|
||||
// spdlog::init_thread_pool(32768, 1); // queue with max 32k items 1 backing thread.
|
||||
auto async_file =
|
||||
spdlog::basic_logger_mt<spdlog::async_factory>("async_file_logger", "logs/async_log.txt");
|
||||
auto async_file = spdlog::basic_logger_mt<spdlog::async_factory>("async_file_logger", "logs/async_log.txt");
|
||||
// alternatively:
|
||||
// auto async_file =
|
||||
// spdlog::create_async<spdlog::sinks::basic_file_sink_mt>("async_file_logger",
|
||||
@ -177,8 +173,7 @@ void binary_example() {
|
||||
buf.push_back(static_cast<char>(i & 0xff));
|
||||
}
|
||||
spdlog::info("Binary example: {}", spdlog::to_hex(buf));
|
||||
spdlog::info("Another binary example:{:n}",
|
||||
spdlog::to_hex(std::begin(buf), std::begin(buf) + 10));
|
||||
spdlog::info("Another binary example:{:n}", spdlog::to_hex(std::begin(buf), std::begin(buf) + 10));
|
||||
// more examples:
|
||||
// logger->info("uppercase: {:X}", spdlog::to_hex(buf));
|
||||
// logger->info("uppercase, no delimiters: {:Xs}", spdlog::to_hex(buf));
|
||||
@ -243,8 +238,7 @@ void multi_sink_example() {
|
||||
console_sink->set_level(spdlog::level::warn);
|
||||
console_sink->set_pattern("[multi_sink_example] [%^%l%$] %v");
|
||||
|
||||
auto file_sink =
|
||||
std::make_shared<spdlog::sinks::basic_file_sink_mt>("logs/multisink.txt", true);
|
||||
auto file_sink = std::make_shared<spdlog::sinks::basic_file_sink_mt>("logs/multisink.txt", true);
|
||||
file_sink->set_level(spdlog::level::trace);
|
||||
|
||||
spdlog::logger logger("multi_sink", {console_sink, file_sink});
|
||||
@ -282,9 +276,8 @@ void user_defined_example() { spdlog::info("user defined type: {}", my_type(14))
|
||||
// Custom error handler. Will be triggered on log failure.
|
||||
void err_handler_example() {
|
||||
// can be set globally or per logger(logger->set_error_handler(..))
|
||||
spdlog::set_error_handler([](const std::string &msg) {
|
||||
printf("*** Custom log error handler: %s ***\n", msg.c_str());
|
||||
});
|
||||
spdlog::set_error_handler(
|
||||
[](const std::string &msg) { printf("*** Custom log error handler: %s ***\n", msg.c_str()); });
|
||||
}
|
||||
|
||||
// syslog example (linux/osx/freebsd)
|
||||
@ -312,16 +305,12 @@ 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());
|
||||
}
|
||||
|
||||
std::unique_ptr<custom_flag_formatter> clone() const override {
|
||||
return std::make_unique<my_formatter_flag>();
|
||||
}
|
||||
std::unique_ptr<custom_flag_formatter> clone() const override { return std::make_unique<my_formatter_flag>(); }
|
||||
};
|
||||
|
||||
void custom_flags_example() {
|
||||
@ -334,9 +323,7 @@ void custom_flags_example() {
|
||||
void file_events_example() {
|
||||
// pass the spdlog::file_event_handlers to file sinks for open/close log file notifications
|
||||
spdlog::file_event_handlers handlers;
|
||||
handlers.before_open = [](spdlog::filename_t filename) {
|
||||
spdlog::info("Before opening {}", filename);
|
||||
};
|
||||
handlers.before_open = [](spdlog::filename_t filename) { spdlog::info("Before opening {}", filename); };
|
||||
handlers.after_open = [](spdlog::filename_t filename, std::FILE *fstream) {
|
||||
spdlog::info("After opening {}", filename);
|
||||
fputs("After opening\n", fstream);
|
||||
@ -345,11 +332,8 @@ void file_events_example() {
|
||||
spdlog::info("Before closing {}", filename);
|
||||
fputs("Before closing\n", fstream);
|
||||
};
|
||||
handlers.after_close = [](spdlog::filename_t filename) {
|
||||
spdlog::info("After closing {}", filename);
|
||||
};
|
||||
auto file_sink = std::make_shared<spdlog::sinks::basic_file_sink_mt>("logs/events-sample.txt",
|
||||
true, handlers);
|
||||
handlers.after_close = [](spdlog::filename_t filename) { spdlog::info("After closing {}", filename); };
|
||||
auto file_sink = std::make_shared<spdlog::sinks::basic_file_sink_mt>("logs/events-sample.txt", true, handlers);
|
||||
spdlog::logger my_logger("some_logger", file_sink);
|
||||
my_logger.info("Some log line");
|
||||
}
|
||||
@ -358,8 +342,7 @@ void replace_default_logger_example() {
|
||||
// store the old logger so we don't break other examples.
|
||||
auto old_logger = spdlog::default_logger();
|
||||
|
||||
auto new_logger =
|
||||
spdlog::basic_logger_mt("new_default_logger", "logs/new-default-log.txt", true);
|
||||
auto new_logger = spdlog::basic_logger_mt("new_default_logger", "logs/new-default-log.txt", true);
|
||||
spdlog::set_default_logger(new_logger);
|
||||
spdlog::set_level(spdlog::level::info);
|
||||
spdlog::debug("This message should not be displayed!");
|
||||
|
@ -48,8 +48,8 @@ struct async_factory_impl {
|
||||
}
|
||||
|
||||
auto sink = std::make_shared<Sink>(std::forward<SinkArgs>(args)...);
|
||||
auto new_logger = std::make_shared<async_logger>(std::move(logger_name), std::move(sink),
|
||||
std::move(tp), OverflowPolicy);
|
||||
auto new_logger =
|
||||
std::make_shared<async_logger>(std::move(logger_name), std::move(sink), std::move(tp), OverflowPolicy);
|
||||
registry_inst.initialize_logger(new_logger);
|
||||
return new_logger;
|
||||
}
|
||||
@ -59,17 +59,13 @@ using async_factory = async_factory_impl<async_overflow_policy::block>;
|
||||
using async_factory_nonblock = async_factory_impl<async_overflow_policy::overrun_oldest>;
|
||||
|
||||
template <typename Sink, typename... SinkArgs>
|
||||
inline std::shared_ptr<spdlog::logger> create_async(std::string logger_name,
|
||||
SinkArgs &&...sink_args) {
|
||||
return async_factory::create<Sink>(std::move(logger_name),
|
||||
std::forward<SinkArgs>(sink_args)...);
|
||||
inline std::shared_ptr<spdlog::logger> create_async(std::string logger_name, SinkArgs &&...sink_args) {
|
||||
return async_factory::create<Sink>(std::move(logger_name), std::forward<SinkArgs>(sink_args)...);
|
||||
}
|
||||
|
||||
template <typename Sink, typename... SinkArgs>
|
||||
inline std::shared_ptr<spdlog::logger> create_async_nb(std::string logger_name,
|
||||
SinkArgs &&...sink_args) {
|
||||
return async_factory_nonblock::create<Sink>(std::move(logger_name),
|
||||
std::forward<SinkArgs>(sink_args)...);
|
||||
inline std::shared_ptr<spdlog::logger> create_async_nb(std::string logger_name, SinkArgs &&...sink_args) {
|
||||
return async_factory_nonblock::create<Sink>(std::move(logger_name), std::forward<SinkArgs>(sink_args)...);
|
||||
}
|
||||
|
||||
// set global thread pool.
|
||||
@ -77,14 +73,11 @@ inline void init_thread_pool(size_t q_size,
|
||||
size_t thread_count,
|
||||
std::function<void()> on_thread_start,
|
||||
std::function<void()> on_thread_stop) {
|
||||
auto tp = std::make_shared<details::thread_pool>(q_size, thread_count, on_thread_start,
|
||||
on_thread_stop);
|
||||
auto tp = std::make_shared<details::thread_pool>(q_size, thread_count, on_thread_start, on_thread_stop);
|
||||
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, [] {});
|
||||
}
|
||||
|
||||
@ -94,7 +87,5 @@ inline void init_thread_pool(size_t q_size, size_t thread_count) {
|
||||
}
|
||||
|
||||
// get the global thread pool.
|
||||
inline std::shared_ptr<spdlog::details::thread_pool> thread_pool() {
|
||||
return details::registry::instance().get_tp();
|
||||
}
|
||||
inline std::shared_ptr<spdlog::details::thread_pool> thread_pool() { return details::registry::instance().get_tp(); }
|
||||
} // namespace spdlog
|
||||
|
@ -30,8 +30,7 @@ namespace details {
|
||||
class thread_pool;
|
||||
}
|
||||
|
||||
class SPDLOG_API async_logger final : public std::enable_shared_from_this<async_logger>,
|
||||
public logger {
|
||||
class SPDLOG_API async_logger final : public std::enable_shared_from_this<async_logger>, public logger {
|
||||
friend class details::thread_pool;
|
||||
|
||||
public:
|
||||
|
@ -32,9 +32,7 @@ inline void load_argv_levels(int argc, const char **argv) {
|
||||
}
|
||||
}
|
||||
|
||||
inline void load_argv_levels(int argc, char **argv) {
|
||||
load_argv_levels(argc, const_cast<const char **>(argv));
|
||||
}
|
||||
inline void load_argv_levels(int argc, char **argv) { load_argv_levels(argc, const_cast<const char **>(argv)); }
|
||||
|
||||
} // namespace cfg
|
||||
} // namespace spdlog
|
||||
|
@ -15,9 +15,8 @@
|
||||
#include <string>
|
||||
#include <type_traits>
|
||||
|
||||
#include "./spdlog_config.h"
|
||||
#include "./source_loc.h"
|
||||
|
||||
#include "./spdlog_config.h"
|
||||
|
||||
#if __has_include(<version>)
|
||||
#include <version>
|
||||
@ -43,8 +42,7 @@
|
||||
|
||||
#include "fmt/fmt.h"
|
||||
|
||||
#if !defined(SPDLOG_USE_STD_FORMAT) && \
|
||||
FMT_VERSION >= 80000 // backward compatibility with fmt versions older than 8
|
||||
#if !defined(SPDLOG_USE_STD_FORMAT) && 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 "fmt/xchar.h"
|
||||
@ -156,14 +154,12 @@ using atomic_level_t = details::null_atomic<level>;
|
||||
using atomic_level_t = std::atomic<level>;
|
||||
#endif
|
||||
|
||||
|
||||
[[nodiscard]] constexpr size_t level_to_number(level lvl) noexcept {
|
||||
return static_cast<size_t>(lvl);
|
||||
}
|
||||
[[nodiscard]] constexpr size_t level_to_number(level lvl) noexcept { return static_cast<size_t>(lvl); }
|
||||
|
||||
constexpr auto levels_count = level_to_number(level::n_levels);
|
||||
constexpr std::array<string_view_t, levels_count> level_string_views { "trace", "debug", "info", "warning", "error", "critical", "off" };
|
||||
constexpr std::array<string_view_t, levels_count> short_level_names { "T", "D", "I", "W", "E", "C", "O" };
|
||||
constexpr std::array<string_view_t, levels_count> level_string_views{"trace", "debug", "info", "warning",
|
||||
"error", "critical", "off"};
|
||||
constexpr std::array<string_view_t, levels_count> short_level_names{"T", "D", "I", "W", "E", "C", "O"};
|
||||
|
||||
[[nodiscard]] constexpr string_view_t to_string_view(spdlog::level lvl) noexcept {
|
||||
return level_string_views.at(level_to_number(lvl));
|
||||
@ -221,8 +217,7 @@ struct loc_with_fmt {
|
||||
|
||||
#ifndef SPDLOG_USE_STD_FORMAT
|
||||
|
||||
constexpr loc_with_fmt(fmt::runtime_format_string<char> fmt_str,
|
||||
source_loc loc = source_loc::current()) noexcept
|
||||
constexpr loc_with_fmt(fmt::runtime_format_string<char> fmt_str, source_loc loc = source_loc::current()) noexcept
|
||||
: loc(loc),
|
||||
fmt_string(fmt_str.str) {}
|
||||
|
||||
@ -250,40 +245,33 @@ namespace details {
|
||||
return spdlog::string_view_t{buf.data(), buf.size()};
|
||||
}
|
||||
|
||||
[[nodiscard]] constexpr spdlog::string_view_t to_string_view(spdlog::string_view_t str) noexcept {
|
||||
return str;
|
||||
}
|
||||
[[nodiscard]] constexpr spdlog::string_view_t to_string_view(spdlog::string_view_t str) noexcept { return str; }
|
||||
|
||||
#if defined(SPDLOG_WCHAR_FILENAMES)
|
||||
[[nodiscard]] constexpr spdlog::wstring_view_t to_string_view(const wmemory_buf_t &buf) noexcept {
|
||||
return spdlog::wstring_view_t{buf.data(), buf.size()};
|
||||
}
|
||||
|
||||
[[nodiscard]] constexpr spdlog::wstring_view_t to_string_view(spdlog::wstring_view_t str) noexcept {
|
||||
return str;
|
||||
}
|
||||
[[nodiscard]] constexpr spdlog::wstring_view_t to_string_view(spdlog::wstring_view_t str) noexcept { return str; }
|
||||
#endif
|
||||
|
||||
// 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
|
||||
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
|
||||
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
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
|
@ -65,8 +65,7 @@ constexpr unsigned int count_digits_fallback(T n) {
|
||||
|
||||
template <typename T>
|
||||
inline unsigned int count_digits(T n) {
|
||||
using count_type =
|
||||
typename std::conditional<(sizeof(T) > sizeof(uint32_t)), uint64_t, uint32_t>::type;
|
||||
using count_type = typename std::conditional<(sizeof(T) > sizeof(uint32_t)), uint64_t, uint32_t>::type;
|
||||
#ifdef SPDLOG_USE_STD_FORMAT
|
||||
return count_digits_fallback(static_cast<count_type>(n));
|
||||
#else
|
||||
|
@ -11,11 +11,7 @@ namespace spdlog {
|
||||
namespace details {
|
||||
struct SPDLOG_API log_msg {
|
||||
log_msg() = default;
|
||||
log_msg(log_clock::time_point log_time,
|
||||
source_loc loc,
|
||||
string_view_t logger_name,
|
||||
level lvl,
|
||||
string_view_t msg);
|
||||
log_msg(log_clock::time_point log_time, source_loc loc, string_view_t logger_name, level lvl, string_view_t msg);
|
||||
log_msg(source_loc loc, string_view_t logger_name, level lvl, string_view_t msg);
|
||||
log_msg(string_view_t logger_name, level lvl, string_view_t msg);
|
||||
log_msg(const log_msg &other) = default;
|
||||
|
@ -42,8 +42,7 @@ constexpr static const char *default_eol = SPDLOG_EOL;
|
||||
#endif
|
||||
|
||||
constexpr static const char folder_seps[] = SPDLOG_FOLDER_SEPS;
|
||||
constexpr static const filename_t::value_type folder_seps_filename[] =
|
||||
SPDLOG_FILENAME_T(SPDLOG_FOLDER_SEPS);
|
||||
constexpr static const filename_t::value_type folder_seps_filename[] = SPDLOG_FILENAME_T(SPDLOG_FOLDER_SEPS);
|
||||
|
||||
// fopen_s on non windows for writing
|
||||
SPDLOG_API bool fopen_s(FILE **fp, const filename_t &filename, const filename_t &mode);
|
||||
|
@ -24,8 +24,7 @@ namespace details {
|
||||
class SPDLOG_API periodic_worker {
|
||||
public:
|
||||
template <typename Rep, typename Period>
|
||||
periodic_worker(const std::function<void()> &callback_fun,
|
||||
std::chrono::duration<Rep, Period> interval) {
|
||||
periodic_worker(const std::function<void()> &callback_fun, std::chrono::duration<Rep, Period> interval) {
|
||||
active_ = (interval > std::chrono::duration<Rep, Period>::zero());
|
||||
if (!active_) {
|
||||
return;
|
||||
|
@ -35,9 +35,8 @@ class tcp_client {
|
||||
|
||||
static void throw_winsock_error_(const std::string &msg, int last_error) {
|
||||
char buf[512];
|
||||
::FormatMessageA(FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, NULL,
|
||||
last_error, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), buf,
|
||||
(sizeof(buf) / sizeof(char)), NULL);
|
||||
::FormatMessageA(FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, NULL, last_error,
|
||||
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), buf, (sizeof(buf) / sizeof(char)), NULL);
|
||||
|
||||
throw_spdlog_ex(fmt_lib::format("tcp_sink - {}: {}", msg, buf));
|
||||
}
|
||||
@ -106,8 +105,7 @@ public:
|
||||
|
||||
// set TCP_NODELAY
|
||||
int enable_flag = 1;
|
||||
::setsockopt(socket_, IPPROTO_TCP, TCP_NODELAY, reinterpret_cast<char *>(&enable_flag),
|
||||
sizeof(enable_flag));
|
||||
::setsockopt(socket_, IPPROTO_TCP, TCP_NODELAY, reinterpret_cast<char *>(&enable_flag), sizeof(enable_flag));
|
||||
}
|
||||
|
||||
// Send exactly n_bytes of the given data.
|
||||
@ -116,8 +114,7 @@ public:
|
||||
size_t bytes_sent = 0;
|
||||
while (bytes_sent < n_bytes) {
|
||||
const int send_flags = 0;
|
||||
auto write_result =
|
||||
::send(socket_, data + bytes_sent, (int)(n_bytes - bytes_sent), send_flags);
|
||||
auto write_result = ::send(socket_, data + bytes_sent, (int)(n_bytes - bytes_sent), send_flags);
|
||||
if (write_result == SOCKET_ERROR) {
|
||||
int last_error = ::WSAGetLastError();
|
||||
close();
|
||||
|
@ -85,13 +85,11 @@ public:
|
||||
|
||||
// set TCP_NODELAY
|
||||
int enable_flag = 1;
|
||||
::setsockopt(socket_, IPPROTO_TCP, TCP_NODELAY, reinterpret_cast<char *>(&enable_flag),
|
||||
sizeof(enable_flag));
|
||||
::setsockopt(socket_, IPPROTO_TCP, TCP_NODELAY, reinterpret_cast<char *>(&enable_flag), sizeof(enable_flag));
|
||||
|
||||
// prevent sigpipe on systems where MSG_NOSIGNAL is not available
|
||||
#if defined(SO_NOSIGPIPE) && !defined(MSG_NOSIGNAL)
|
||||
::setsockopt(socket_, SOL_SOCKET, SO_NOSIGPIPE, reinterpret_cast<char *>(&enable_flag),
|
||||
sizeof(enable_flag));
|
||||
::setsockopt(socket_, SOL_SOCKET, SO_NOSIGPIPE, reinterpret_cast<char *>(&enable_flag), sizeof(enable_flag));
|
||||
#endif
|
||||
|
||||
#if !defined(SO_NOSIGPIPE) && !defined(MSG_NOSIGNAL)
|
||||
@ -109,8 +107,7 @@ public:
|
||||
#else
|
||||
const int send_flags = 0;
|
||||
#endif
|
||||
auto write_result =
|
||||
::send(socket_, data + bytes_sent, n_bytes - bytes_sent, send_flags);
|
||||
auto write_result = ::send(socket_, data + bytes_sent, n_bytes - bytes_sent, send_flags);
|
||||
if (write_result < 0) {
|
||||
close();
|
||||
throw_spdlog_ex("write(2) failed", errno);
|
||||
|
@ -86,9 +86,7 @@ public:
|
||||
thread_pool(const thread_pool &) = delete;
|
||||
thread_pool &operator=(thread_pool &&) = delete;
|
||||
|
||||
void post_log(async_logger_ptr &&worker_ptr,
|
||||
const details::log_msg &msg,
|
||||
async_overflow_policy overflow_policy);
|
||||
void post_log(async_logger_ptr &&worker_ptr, const details::log_msg &msg, async_overflow_policy overflow_policy);
|
||||
void post_flush(async_logger_ptr &&worker_ptr, async_overflow_policy overflow_policy);
|
||||
size_t overrun_counter();
|
||||
void reset_overrun_counter();
|
||||
|
@ -40,9 +40,8 @@ class udp_client {
|
||||
|
||||
static void throw_winsock_error_(const std::string &msg, int last_error) {
|
||||
char buf[512];
|
||||
::FormatMessageA(FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, NULL,
|
||||
last_error, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), buf,
|
||||
(sizeof(buf) / sizeof(char)), NULL);
|
||||
::FormatMessageA(FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, NULL, last_error,
|
||||
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), buf, (sizeof(buf) / sizeof(char)), NULL);
|
||||
|
||||
throw_spdlog_ex(fmt_lib::format("udp_sink - {}: {}", msg, buf));
|
||||
}
|
||||
@ -76,8 +75,8 @@ public:
|
||||
}
|
||||
|
||||
int option_value = TX_BUFFER_SIZE;
|
||||
if (::setsockopt(socket_, SOL_SOCKET, SO_SNDBUF,
|
||||
reinterpret_cast<const char *>(&option_value), sizeof(option_value)) < 0) {
|
||||
if (::setsockopt(socket_, SOL_SOCKET, SO_SNDBUF, reinterpret_cast<const char *>(&option_value),
|
||||
sizeof(option_value)) < 0) {
|
||||
int last_error = ::WSAGetLastError();
|
||||
cleanup_();
|
||||
throw_winsock_error_("error: setsockopt(SO_SNDBUF) Failed!", last_error);
|
||||
@ -90,8 +89,7 @@ public:
|
||||
|
||||
void send(const char *data, size_t n_bytes) {
|
||||
socklen_t tolen = sizeof(struct sockaddr);
|
||||
if (::sendto(socket_, data, static_cast<int>(n_bytes), 0, (struct sockaddr *)&addr_,
|
||||
tolen) == -1) {
|
||||
if (::sendto(socket_, data, static_cast<int>(n_bytes), 0, (struct sockaddr *)&addr_, tolen) == -1) {
|
||||
throw_spdlog_ex("sendto(2) failed", errno);
|
||||
}
|
||||
}
|
||||
|
@ -46,8 +46,8 @@ public:
|
||||
}
|
||||
|
||||
int option_value = TX_BUFFER_SIZE;
|
||||
if (::setsockopt(socket_, SOL_SOCKET, SO_SNDBUF,
|
||||
reinterpret_cast<const char *>(&option_value), sizeof(option_value)) < 0) {
|
||||
if (::setsockopt(socket_, SOL_SOCKET, SO_SNDBUF, reinterpret_cast<const char *>(&option_value),
|
||||
sizeof(option_value)) < 0) {
|
||||
cleanup_();
|
||||
throw_spdlog_ex("error: setsockopt(SO_SNDBUF) Failed!");
|
||||
}
|
||||
@ -72,8 +72,7 @@ public:
|
||||
void send(const char *data, size_t n_bytes) {
|
||||
ssize_t toslen = 0;
|
||||
socklen_t tolen = sizeof(struct sockaddr);
|
||||
if ((toslen = ::sendto(socket_, data, n_bytes, 0, (struct sockaddr *)&sockAddr_, tolen)) ==
|
||||
-1) {
|
||||
if ((toslen = ::sendto(socket_, data, n_bytes, 0, (struct sockaddr *)&sockAddr_, tolen)) == -1) {
|
||||
throw_spdlog_ex("sendto(2) failed", errno);
|
||||
}
|
||||
}
|
||||
|
@ -63,8 +63,7 @@ private:
|
||||
template <typename Container>
|
||||
inline details::dump_info<typename Container::const_iterator> to_hex(const Container &container,
|
||||
size_t size_per_line = 32) {
|
||||
static_assert(sizeof(typename Container::value_type) == 1,
|
||||
"sizeof(Container::value_type) != 1");
|
||||
static_assert(sizeof(typename Container::value_type) == 1, "sizeof(Container::value_type) != 1");
|
||||
using Iter = typename Container::const_iterator;
|
||||
return details::dump_info<Iter>(std::begin(container), std::end(container), size_per_line);
|
||||
}
|
||||
@ -72,11 +71,10 @@ 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");
|
||||
static_assert(sizeof(typename Container::value_type) == 1, "sizeof(Container::value_type) != 1");
|
||||
using Iter = typename Container::iterator;
|
||||
return details::dump_info<Iter>(std::begin(container), std::end(container), size_per_line);
|
||||
}
|
||||
@ -85,9 +83,7 @@ inline details::dump_info<typename std::span<Value, Extent>::iterator> to_hex(
|
||||
|
||||
// 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);
|
||||
}
|
||||
|
||||
@ -160,8 +156,7 @@ struct formatter<spdlog::details::dump_info<T>, char> {
|
||||
for (auto i = the_range.get_begin(); i != the_range.get_end(); i++) {
|
||||
auto ch = static_cast<unsigned char>(*i);
|
||||
|
||||
if (put_newlines &&
|
||||
(i == the_range.get_begin() || i - start_of_line >= size_per_line)) {
|
||||
if (put_newlines && (i == the_range.get_begin() || i - start_of_line >= size_per_line)) {
|
||||
if (show_ascii && i != the_range.get_begin()) {
|
||||
*inserter++ = delimiter;
|
||||
*inserter++ = delimiter;
|
||||
|
@ -22,18 +22,17 @@
|
||||
#include "./sinks/sink.h"
|
||||
|
||||
#ifndef SPDLOG_NO_EXCEPTIONS
|
||||
#define SPDLOG_LOGGER_CATCH(location) \
|
||||
catch (const std::exception &ex) { \
|
||||
if (!location.empty()) { \
|
||||
err_handler_( \
|
||||
fmt_lib::format("{} [{}({})]", ex.what(), location.filename, location.line)); \
|
||||
} else { \
|
||||
err_handler_(ex.what()); \
|
||||
} \
|
||||
} \
|
||||
catch (...) { \
|
||||
err_handler_("Rethrowing unknown exception in logger"); \
|
||||
throw; \
|
||||
#define SPDLOG_LOGGER_CATCH(location) \
|
||||
catch (const std::exception &ex) { \
|
||||
if (!location.empty()) { \
|
||||
err_handler_(fmt_lib::format("{} [{}({})]", ex.what(), location.filename, location.line)); \
|
||||
} else { \
|
||||
err_handler_(ex.what()); \
|
||||
} \
|
||||
} \
|
||||
catch (...) { \
|
||||
err_handler_("Rethrowing unknown exception in logger"); \
|
||||
throw; \
|
||||
}
|
||||
#else
|
||||
#define SPDLOG_LOGGER_CATCH(location)
|
||||
@ -77,8 +76,7 @@ public:
|
||||
template <typename... Args>
|
||||
void log(level lvl, format_string_t<Args...> fmt, Args &&...args) {
|
||||
if (should_log(lvl)) {
|
||||
log_with_format_(source_loc{}, lvl, details::to_string_view(fmt),
|
||||
std::forward<Args>(args)...);
|
||||
log_with_format_(source_loc{}, lvl, details::to_string_view(fmt), std::forward<Args>(args)...);
|
||||
}
|
||||
}
|
||||
|
||||
@ -143,29 +141,17 @@ public:
|
||||
|
||||
// log functions with no format string, just string
|
||||
|
||||
void trace(string_view_t msg, source_loc loc = source_loc::current()) {
|
||||
log(loc, level::trace, msg);
|
||||
}
|
||||
void trace(string_view_t msg, source_loc loc = source_loc::current()) { log(loc, level::trace, msg); }
|
||||
|
||||
void debug(string_view_t msg, source_loc loc = source_loc::current()) {
|
||||
log(loc, level::debug, msg);
|
||||
}
|
||||
void debug(string_view_t msg, source_loc loc = source_loc::current()) { log(loc, level::debug, msg); }
|
||||
|
||||
void info(string_view_t msg, source_loc loc = source_loc::current()) {
|
||||
log(loc, level::info, msg);
|
||||
}
|
||||
void info(string_view_t msg, source_loc loc = source_loc::current()) { log(loc, level::info, msg); }
|
||||
|
||||
void warn(string_view_t msg, source_loc loc = source_loc::current()) {
|
||||
log(loc, level::warn, msg);
|
||||
}
|
||||
void warn(string_view_t msg, source_loc loc = source_loc::current()) { log(loc, level::warn, msg); }
|
||||
|
||||
void error(string_view_t msg, source_loc loc = source_loc::current()) {
|
||||
log(loc, level::err, msg);
|
||||
}
|
||||
void error(string_view_t msg, source_loc loc = source_loc::current()) { log(loc, level::err, msg); }
|
||||
|
||||
void critical(string_view_t msg, source_loc loc = source_loc::current()) {
|
||||
log(loc, level::critical, msg);
|
||||
}
|
||||
void critical(string_view_t msg, source_loc loc = source_loc::current()) { log(loc, level::critical, msg); }
|
||||
#else // without source location
|
||||
template <typename... Args>
|
||||
void trace(format_string_t<Args...> fmt, Args &&...args) {
|
||||
@ -207,9 +193,7 @@ public:
|
||||
#endif // SPDLOG_SOURCE_LOCATION
|
||||
|
||||
// return true if logging is enabled for the given level.
|
||||
[[nodiscard]] bool should_log(level msg_level) const {
|
||||
return msg_level >= level_.load(std::memory_order_relaxed);
|
||||
}
|
||||
[[nodiscard]] bool should_log(level msg_level) const { return msg_level >= level_.load(std::memory_order_relaxed); }
|
||||
|
||||
// set the level of logging
|
||||
void set_level(level level);
|
||||
|
@ -42,9 +42,7 @@ 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_;
|
||||
@ -56,9 +54,7 @@ class SPDLOG_API custom_flag_formatter : public details::flag_formatter {
|
||||
public:
|
||||
virtual std::unique_ptr<custom_flag_formatter> clone() const = 0;
|
||||
|
||||
void set_padding_info(const details::padding_info &padding) {
|
||||
flag_formatter::padinfo_ = padding;
|
||||
}
|
||||
void set_padding_info(const details::padding_info &padding) { flag_formatter::padinfo_ = padding; }
|
||||
};
|
||||
|
||||
class SPDLOG_API pattern_formatter final : public formatter {
|
||||
@ -105,8 +101,7 @@ private:
|
||||
// Extract given pad spec (e.g. %8X)
|
||||
// Advance the given it pass the end of the padding spec found (if any)
|
||||
// Return padding.
|
||||
static details::padding_info handle_padspec_(std::string::const_iterator &it,
|
||||
std::string::const_iterator end);
|
||||
static details::padding_info handle_padspec_(std::string::const_iterator &it, std::string::const_iterator end);
|
||||
|
||||
void compile_pattern_(const std::string &pattern);
|
||||
};
|
||||
|
@ -75,14 +75,16 @@ 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);
|
||||
}
|
||||
|
||||
@ -122,14 +124,12 @@ using android_sink_buf_st = android_sink<details::null_mutex, BufferId>;
|
||||
// Create and register android syslog logger
|
||||
|
||||
template <typename Factory = spdlog::synchronous_factory>
|
||||
inline std::shared_ptr<logger> android_logger_mt(const std::string &logger_name,
|
||||
const std::string &tag = "spdlog") {
|
||||
inline std::shared_ptr<logger> android_logger_mt(const std::string &logger_name, const std::string &tag = "spdlog") {
|
||||
return Factory::template create<sinks::android_sink_mt>(logger_name, tag);
|
||||
}
|
||||
|
||||
template <typename Factory = spdlog::synchronous_factory>
|
||||
inline std::shared_ptr<logger> android_logger_st(const std::string &logger_name,
|
||||
const std::string &tag = "spdlog") {
|
||||
inline std::shared_ptr<logger> android_logger_st(const std::string &logger_name, const std::string &tag = "spdlog") {
|
||||
return Factory::template create<sinks::android_sink_st>(logger_name, tag);
|
||||
}
|
||||
|
||||
|
@ -45,8 +45,7 @@ inline std::shared_ptr<logger> basic_logger_mt(const std::string &logger_name,
|
||||
const filename_t &filename,
|
||||
bool truncate = false,
|
||||
const file_event_handlers &event_handlers = {}) {
|
||||
return Factory::template create<sinks::basic_file_sink_mt>(logger_name, filename, truncate,
|
||||
event_handlers);
|
||||
return Factory::template create<sinks::basic_file_sink_mt>(logger_name, filename, truncate, event_handlers);
|
||||
}
|
||||
|
||||
template <typename Factory = spdlog::synchronous_factory>
|
||||
@ -54,8 +53,7 @@ inline std::shared_ptr<logger> basic_logger_st(const std::string &logger_name,
|
||||
const filename_t &filename,
|
||||
bool truncate = false,
|
||||
const file_event_handlers &event_handlers = {}) {
|
||||
return Factory::template create<sinks::basic_file_sink_st>(logger_name, filename, truncate,
|
||||
event_handlers);
|
||||
return Factory::template create<sinks::basic_file_sink_st>(logger_name, filename, truncate, event_handlers);
|
||||
}
|
||||
|
||||
} // namespace spdlog
|
||||
|
@ -42,14 +42,12 @@ using callback_sink_st = callback_sink<details::null_mutex>;
|
||||
// factory functions
|
||||
//
|
||||
template <typename Factory = spdlog::synchronous_factory>
|
||||
inline std::shared_ptr<logger> callback_logger_mt(const std::string &logger_name,
|
||||
const custom_log_callback &callback) {
|
||||
inline std::shared_ptr<logger> callback_logger_mt(const std::string &logger_name, const custom_log_callback &callback) {
|
||||
return Factory::template create<sinks::callback_sink_mt>(logger_name, callback);
|
||||
}
|
||||
|
||||
template <typename Factory = spdlog::synchronous_factory>
|
||||
inline std::shared_ptr<logger> callback_logger_st(const std::string &logger_name,
|
||||
const custom_log_callback &callback) {
|
||||
inline std::shared_ptr<logger> callback_logger_st(const std::string &logger_name, const custom_log_callback &callback) {
|
||||
return Factory::template create<sinks::callback_sink_st>(logger_name, callback);
|
||||
}
|
||||
|
||||
|
@ -19,7 +19,6 @@
|
||||
#include "./base_sink.h"
|
||||
#include "fmt/chrono.h"
|
||||
|
||||
|
||||
namespace spdlog {
|
||||
namespace sinks {
|
||||
|
||||
@ -31,8 +30,8 @@ struct daily_filename_calculator {
|
||||
static filename_t calc_filename(const filename_t &filename, const tm &now_tm) {
|
||||
filename_t basename, ext;
|
||||
std::tie(basename, ext) = details::file_helper::split_by_extension(filename);
|
||||
return fmt_lib::format(SPDLOG_FILENAME_T("{}_{:04d}-{:02d}-{:02d}{}"), basename,
|
||||
now_tm.tm_year + 1900, now_tm.tm_mon + 1, now_tm.tm_mday, ext);
|
||||
return fmt_lib::format(SPDLOG_FILENAME_T("{}_{:04d}-{:02d}-{:02d}{}"), basename, now_tm.tm_year + 1900,
|
||||
now_tm.tm_mon + 1, now_tm.tm_mday, ext);
|
||||
}
|
||||
};
|
||||
|
||||
@ -79,8 +78,7 @@ public:
|
||||
truncate_(truncate),
|
||||
max_files_(max_files),
|
||||
filenames_q_() {
|
||||
if (rotation_hour < 0 || rotation_hour > 23 || rotation_minute < 0 ||
|
||||
rotation_minute > 59) {
|
||||
if (rotation_hour < 0 || rotation_hour > 23 || rotation_minute < 0 || rotation_minute > 59) {
|
||||
throw_spdlog_ex("daily_file_sink: Invalid rotation time in ctor");
|
||||
}
|
||||
|
||||
@ -171,8 +169,7 @@ private:
|
||||
bool ok = remove_if_exists(old_filename) == 0;
|
||||
if (!ok) {
|
||||
filenames_q_.push_back(std::move(current_file));
|
||||
throw_spdlog_ex("Failed removing daily file " + filename_to_str(old_filename),
|
||||
errno);
|
||||
throw_spdlog_ex("Failed removing daily file " + filename_to_str(old_filename), errno);
|
||||
}
|
||||
}
|
||||
filenames_q_.push_back(std::move(current_file));
|
||||
@ -191,8 +188,7 @@ private:
|
||||
using daily_file_sink_mt = daily_file_sink<std::mutex>;
|
||||
using daily_file_sink_st = daily_file_sink<details::null_mutex>;
|
||||
using daily_file_format_sink_mt = daily_file_sink<std::mutex, daily_filename_format_calculator>;
|
||||
using daily_file_format_sink_st =
|
||||
daily_file_sink<details::null_mutex, daily_filename_format_calculator>;
|
||||
using daily_file_format_sink_st = daily_file_sink<details::null_mutex, daily_filename_format_calculator>;
|
||||
|
||||
} // namespace sinks
|
||||
|
||||
@ -207,21 +203,20 @@ inline std::shared_ptr<logger> daily_logger_mt(const std::string &logger_name,
|
||||
bool truncate = false,
|
||||
uint16_t max_files = 0,
|
||||
const file_event_handlers &event_handlers = {}) {
|
||||
return Factory::template create<sinks::daily_file_sink_mt>(logger_name, filename, hour, minute,
|
||||
truncate, max_files, event_handlers);
|
||||
return Factory::template create<sinks::daily_file_sink_mt>(logger_name, filename, hour, minute, truncate, max_files,
|
||||
event_handlers);
|
||||
}
|
||||
|
||||
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 = {}) {
|
||||
return Factory::template create<sinks::daily_file_format_sink_mt>(
|
||||
logger_name, filename, hour, minute, truncate, max_files, 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);
|
||||
}
|
||||
|
||||
template <typename Factory = spdlog::synchronous_factory>
|
||||
@ -232,20 +227,19 @@ inline std::shared_ptr<logger> daily_logger_st(const std::string &logger_name,
|
||||
bool truncate = false,
|
||||
uint16_t max_files = 0,
|
||||
const file_event_handlers &event_handlers = {}) {
|
||||
return Factory::template create<sinks::daily_file_sink_st>(logger_name, filename, hour, minute,
|
||||
truncate, max_files, event_handlers);
|
||||
return Factory::template create<sinks::daily_file_sink_st>(logger_name, filename, hour, minute, truncate, max_files,
|
||||
event_handlers);
|
||||
}
|
||||
|
||||
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 = {}) {
|
||||
return Factory::template create<sinks::daily_file_format_sink_st>(
|
||||
logger_name, filename, hour, minute, truncate, max_files, 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
|
||||
|
@ -62,8 +62,8 @@ protected:
|
||||
// log the "skipped.." message
|
||||
if (skip_counter_ > 0) {
|
||||
char buf[64];
|
||||
auto msg_size = ::snprintf(buf, sizeof(buf), "Skipped %u duplicate messages..",
|
||||
static_cast<unsigned>(skip_counter_));
|
||||
auto msg_size =
|
||||
::snprintf(buf, sizeof(buf), "Skipped %u duplicate messages..", static_cast<unsigned>(skip_counter_));
|
||||
if (msg_size > 0 && static_cast<size_t>(msg_size) < sizeof(buf)) {
|
||||
details::log_msg skipped_msg{msg.source, msg.logger_name, log_level_,
|
||||
string_view_t{buf, static_cast<size_t>(msg_size)}};
|
||||
|
@ -29,9 +29,8 @@ struct hourly_filename_calculator {
|
||||
static filename_t calc_filename(const filename_t &filename, const tm &now_tm) {
|
||||
filename_t basename, ext;
|
||||
std::tie(basename, ext) = details::file_helper::split_by_extension(filename);
|
||||
return fmt_lib::format(SPDLOG_FILENAME_T("{}_{:04d}-{:02d}-{:02d}_{:02d}{}"), basename,
|
||||
now_tm.tm_year + 1900, now_tm.tm_mon + 1, now_tm.tm_mday,
|
||||
now_tm.tm_hour, ext);
|
||||
return fmt_lib::format(SPDLOG_FILENAME_T("{}_{:04d}-{:02d}-{:02d}_{:02d}{}"), basename, now_tm.tm_year + 1900,
|
||||
now_tm.tm_mon + 1, now_tm.tm_mday, now_tm.tm_hour, ext);
|
||||
}
|
||||
};
|
||||
|
||||
@ -145,8 +144,7 @@ private:
|
||||
bool ok = remove_if_exists(old_filename) == 0;
|
||||
if (!ok) {
|
||||
filenames_q_.push_back(std::move(current_file));
|
||||
SPDLOG_THROW(spdlog_ex(
|
||||
"Failed removing hourly file " + filename_to_str(old_filename), errno));
|
||||
SPDLOG_THROW(spdlog_ex("Failed removing hourly file " + filename_to_str(old_filename), errno));
|
||||
}
|
||||
}
|
||||
filenames_q_.push_back(std::move(current_file));
|
||||
@ -175,8 +173,8 @@ inline std::shared_ptr<logger> hourly_logger_mt(const std::string &logger_name,
|
||||
bool truncate = false,
|
||||
uint16_t max_files = 0,
|
||||
const file_event_handlers &event_handlers = {}) {
|
||||
return Factory::template create<sinks::hourly_file_sink_mt>(logger_name, filename, truncate,
|
||||
max_files, event_handlers);
|
||||
return Factory::template create<sinks::hourly_file_sink_mt>(logger_name, filename, truncate, max_files,
|
||||
event_handlers);
|
||||
}
|
||||
|
||||
template <typename Factory = spdlog::synchronous_factory>
|
||||
@ -185,7 +183,7 @@ inline std::shared_ptr<logger> hourly_logger_st(const std::string &logger_name,
|
||||
bool truncate = false,
|
||||
uint16_t max_files = 0,
|
||||
const file_event_handlers &event_handlers = {}) {
|
||||
return Factory::template create<sinks::hourly_file_sink_st>(logger_name, filename, truncate,
|
||||
max_files, event_handlers);
|
||||
return Factory::template create<sinks::hourly_file_sink_st>(logger_name, filename, truncate, max_files,
|
||||
event_handlers);
|
||||
}
|
||||
} // namespace spdlog
|
||||
|
@ -44,11 +44,9 @@ public:
|
||||
try {
|
||||
std::string errstr;
|
||||
conf_.reset(RdKafka::Conf::create(RdKafka::Conf::CONF_GLOBAL));
|
||||
RdKafka::Conf::ConfResult confRes =
|
||||
conf_->set("bootstrap.servers", config_.server_addr, errstr);
|
||||
RdKafka::Conf::ConfResult confRes = conf_->set("bootstrap.servers", config_.server_addr, errstr);
|
||||
if (confRes != RdKafka::Conf::CONF_OK) {
|
||||
throw_spdlog_ex(
|
||||
fmt_lib::format("conf set bootstrap.servers failed err:{}", errstr));
|
||||
throw_spdlog_ex(fmt_lib::format("conf set bootstrap.servers failed err:{}", errstr));
|
||||
}
|
||||
|
||||
tconf_.reset(RdKafka::Conf::create(RdKafka::Conf::CONF_TOPIC));
|
||||
@ -60,8 +58,7 @@ public:
|
||||
if (producer_ == nullptr) {
|
||||
throw_spdlog_ex(fmt_lib::format("create producer failed err:{}", errstr));
|
||||
}
|
||||
topic_.reset(RdKafka::Topic::create(producer_.get(), config_.produce_topic,
|
||||
tconf_.get(), errstr));
|
||||
topic_.reset(RdKafka::Topic::create(producer_.get(), config_.produce_topic, tconf_.get(), errstr));
|
||||
if (topic_ == nullptr) {
|
||||
throw_spdlog_ex(fmt_lib::format("create topic failed err:{}", errstr));
|
||||
}
|
||||
@ -74,8 +71,8 @@ public:
|
||||
|
||||
protected:
|
||||
void sink_it_(const details::log_msg &msg) override {
|
||||
producer_->produce(topic_.get(), 0, RdKafka::Producer::RK_MSG_COPY,
|
||||
(void *)msg.payload.data(), msg.payload.size(), NULL, NULL);
|
||||
producer_->produce(topic_.get(), 0, RdKafka::Producer::RK_MSG_COPY, (void *)msg.payload.data(),
|
||||
msg.payload.size(), NULL, NULL);
|
||||
}
|
||||
|
||||
void flush_() override { producer_->flush(config_.flush_timeout_ms); }
|
||||
@ -106,14 +103,14 @@ 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);
|
||||
}
|
||||
|
||||
|
@ -58,12 +58,10 @@ protected:
|
||||
|
||||
if (client_ != nullptr) {
|
||||
auto doc = document{} << "timestamp" << bsoncxx::types::b_date(msg.time) << "level"
|
||||
<< level::to_string_view(msg.log_level).data() << "level_num"
|
||||
<< msg.log_level << "message"
|
||||
<< std::string(msg.payload.begin(), msg.payload.end())
|
||||
<< "logger_name"
|
||||
<< std::string(msg.logger_name.begin(), msg.logger_name.end())
|
||||
<< "thread_id" << static_cast<int>(msg.thread_id) << finalize;
|
||||
<< level::to_string_view(msg.log_level).data() << "level_num" << msg.log_level
|
||||
<< "message" << std::string(msg.payload.begin(), msg.payload.end()) << "logger_name"
|
||||
<< std::string(msg.logger_name.begin(), msg.logger_name.end()) << "thread_id"
|
||||
<< static_cast<int>(msg.thread_id) << finalize;
|
||||
client_->database(db_name_).collection(coll_name_).insert_one(doc.view());
|
||||
}
|
||||
}
|
||||
@ -86,23 +84,19 @@ using mongo_sink_st = mongo_sink<spdlog::details::null_mutex>;
|
||||
} // 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") {
|
||||
return Factory::template create<sinks::mongo_sink_mt>(logger_name, db_name, collection_name,
|
||||
uri);
|
||||
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") {
|
||||
return Factory::template create<sinks::mongo_sink_st>(logger_name, db_name, collection_name,
|
||||
uri);
|
||||
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
|
||||
|
@ -64,10 +64,7 @@ private:
|
||||
template <typename Mutex>
|
||||
class qt_color_sink : public base_sink<Mutex> {
|
||||
public:
|
||||
qt_color_sink(QTextEdit *qt_text_edit,
|
||||
int max_lines,
|
||||
bool dark_colors = false,
|
||||
bool is_utf8 = false)
|
||||
qt_color_sink(QTextEdit *qt_text_edit, int max_lines, bool dark_colors = false, bool is_utf8 = false)
|
||||
: qt_text_edit_(qt_text_edit),
|
||||
max_lines_(max_lines),
|
||||
is_utf8_(is_utf8) {
|
||||
@ -209,8 +206,8 @@ protected:
|
||||
|
||||
// insert the colorized text
|
||||
cursor.setCharFormat(params.level_color);
|
||||
cursor.insertText(params.payload.mid(params.color_range_start,
|
||||
params.color_range_end - params.color_range_start));
|
||||
cursor.insertText(
|
||||
params.payload.mid(params.color_range_start, params.color_range_end - params.color_range_start));
|
||||
|
||||
// insert the text after the color range with default format
|
||||
cursor.setCharFormat(params.default_color);
|
||||
@ -288,8 +285,7 @@ inline std::shared_ptr<logger> qt_color_logger_mt(const std::string &logger_name
|
||||
QTextEdit *qt_text_edit,
|
||||
int max_lines,
|
||||
bool is_utf8 = false) {
|
||||
return Factory::template create<sinks::qt_color_sink_mt>(logger_name, qt_text_edit, max_lines,
|
||||
false, is_utf8);
|
||||
return Factory::template create<sinks::qt_color_sink_mt>(logger_name, qt_text_edit, max_lines, false, is_utf8);
|
||||
}
|
||||
|
||||
template <typename Factory = spdlog::synchronous_factory>
|
||||
@ -297,8 +293,7 @@ inline std::shared_ptr<logger> qt_color_logger_st(const std::string &logger_name
|
||||
QTextEdit *qt_text_edit,
|
||||
int max_lines,
|
||||
bool is_utf8 = false) {
|
||||
return Factory::template create<sinks::qt_color_sink_st>(logger_name, qt_text_edit, max_lines,
|
||||
false, is_utf8);
|
||||
return Factory::template create<sinks::qt_color_sink_st>(logger_name, qt_text_edit, max_lines, false, is_utf8);
|
||||
}
|
||||
|
||||
} // namespace spdlog
|
||||
|
@ -47,9 +47,7 @@ public:
|
||||
}
|
||||
|
||||
protected:
|
||||
void sink_it_(const details::log_msg &msg) override {
|
||||
q_.push_back(details::log_msg_buffer{msg});
|
||||
}
|
||||
void sink_it_(const details::log_msg &msg) override { q_.push_back(details::log_msg_buffer{msg}); }
|
||||
void flush_() override {}
|
||||
|
||||
private:
|
||||
|
@ -68,8 +68,8 @@ inline std::shared_ptr<logger> rotating_logger_mt(const std::string &logger_name
|
||||
size_t max_files,
|
||||
bool rotate_on_open = false,
|
||||
const file_event_handlers &event_handlers = {}) {
|
||||
return Factory::template create<sinks::rotating_file_sink_mt>(
|
||||
logger_name, filename, max_file_size, max_files, rotate_on_open, event_handlers);
|
||||
return Factory::template create<sinks::rotating_file_sink_mt>(logger_name, filename, max_file_size, max_files,
|
||||
rotate_on_open, event_handlers);
|
||||
}
|
||||
|
||||
template <typename Factory = spdlog::synchronous_factory>
|
||||
@ -79,7 +79,7 @@ inline std::shared_ptr<logger> rotating_logger_st(const std::string &logger_name
|
||||
size_t max_files,
|
||||
bool rotate_on_open = false,
|
||||
const file_event_handlers &event_handlers = {}) {
|
||||
return Factory::template create<sinks::rotating_file_sink_st>(
|
||||
logger_name, filename, max_file_size, max_files, rotate_on_open, event_handlers);
|
||||
return Factory::template create<sinks::rotating_file_sink_st>(logger_name, filename, max_file_size, max_files,
|
||||
rotate_on_open, event_handlers);
|
||||
}
|
||||
} // namespace spdlog
|
||||
|
@ -29,19 +29,15 @@ using stderr_color_sink_st = ansicolor_stderr_sink_st;
|
||||
|
||||
// logger factory functions
|
||||
template <typename Factory = spdlog::synchronous_factory>
|
||||
std::shared_ptr<logger> stdout_color_mt(const std::string &logger_name,
|
||||
color_mode mode = color_mode::automatic);
|
||||
std::shared_ptr<logger> stdout_color_mt(const std::string &logger_name, color_mode mode = color_mode::automatic);
|
||||
|
||||
template <typename Factory = spdlog::synchronous_factory>
|
||||
std::shared_ptr<logger> stdout_color_st(const std::string &logger_name,
|
||||
color_mode mode = color_mode::automatic);
|
||||
std::shared_ptr<logger> stdout_color_st(const std::string &logger_name, color_mode mode = color_mode::automatic);
|
||||
|
||||
template <typename Factory = spdlog::synchronous_factory>
|
||||
std::shared_ptr<logger> stderr_color_mt(const std::string &logger_name,
|
||||
color_mode mode = color_mode::automatic);
|
||||
std::shared_ptr<logger> stderr_color_mt(const std::string &logger_name, color_mode mode = color_mode::automatic);
|
||||
|
||||
template <typename Factory = spdlog::synchronous_factory>
|
||||
std::shared_ptr<logger> stderr_color_st(const std::string &logger_name,
|
||||
color_mode mode = color_mode::automatic);
|
||||
std::shared_ptr<logger> stderr_color_st(const std::string &logger_name, color_mode mode = color_mode::automatic);
|
||||
|
||||
} // namespace spdlog
|
||||
|
@ -5,8 +5,8 @@
|
||||
|
||||
#include <cstdio>
|
||||
|
||||
#include "../details/synchronous_factory.h"
|
||||
#include "../details/null_mutex.h"
|
||||
#include "../details/synchronous_factory.h"
|
||||
#include "./base_sink.h"
|
||||
#include "./sink.h"
|
||||
|
||||
|
@ -88,8 +88,8 @@ inline std::shared_ptr<logger> syslog_logger_mt(const std::string &logger_name,
|
||||
int syslog_option = 0,
|
||||
int syslog_facility = LOG_USER,
|
||||
bool enable_formatting = false) {
|
||||
return Factory::template create<sinks::syslog_sink_mt>(logger_name, syslog_ident, syslog_option,
|
||||
syslog_facility, enable_formatting);
|
||||
return Factory::template create<sinks::syslog_sink_mt>(logger_name, syslog_ident, syslog_option, syslog_facility,
|
||||
enable_formatting);
|
||||
}
|
||||
|
||||
template <typename Factory = spdlog::synchronous_factory>
|
||||
@ -98,7 +98,7 @@ inline std::shared_ptr<logger> syslog_logger_st(const std::string &logger_name,
|
||||
int syslog_option = 0,
|
||||
int syslog_facility = LOG_USER,
|
||||
bool enable_formatting = false) {
|
||||
return Factory::template create<sinks::syslog_sink_st>(logger_name, syslog_ident, syslog_option,
|
||||
syslog_facility, enable_formatting);
|
||||
return Factory::template create<sinks::syslog_sink_st>(logger_name, syslog_ident, syslog_option, syslog_facility,
|
||||
enable_formatting);
|
||||
}
|
||||
} // namespace spdlog
|
||||
|
@ -67,25 +67,22 @@ protected:
|
||||
// Do not send source location if not available
|
||||
if (msg.source.empty()) {
|
||||
// Note: function call inside '()' to avoid macro expansion
|
||||
err = (sd_journal_send)("MESSAGE=%.*s", static_cast<int>(length), payload.data(),
|
||||
"PRIORITY=%d", syslog_level(msg.log_level),
|
||||
err = (sd_journal_send)("MESSAGE=%.*s", static_cast<int>(length), payload.data(), "PRIORITY=%d",
|
||||
syslog_level(msg.log_level),
|
||||
#ifndef SPDLOG_NO_THREAD_ID
|
||||
"TID=%zu", msg.thread_id,
|
||||
#endif
|
||||
"SYSLOG_IDENTIFIER=%.*s",
|
||||
static_cast<int>(syslog_identifier.size()),
|
||||
"SYSLOG_IDENTIFIER=%.*s", static_cast<int>(syslog_identifier.size()),
|
||||
syslog_identifier.data(), nullptr);
|
||||
} else {
|
||||
err = (sd_journal_send)("MESSAGE=%.*s", static_cast<int>(length), payload.data(),
|
||||
"PRIORITY=%d", syslog_level(msg.log_level),
|
||||
err = (sd_journal_send)("MESSAGE=%.*s", static_cast<int>(length), payload.data(), "PRIORITY=%d",
|
||||
syslog_level(msg.log_level),
|
||||
#ifndef SPDLOG_NO_THREAD_ID
|
||||
"TID=%zu", msg.thread_id,
|
||||
#endif
|
||||
"SYSLOG_IDENTIFIER=%.*s",
|
||||
static_cast<int>(syslog_identifier.size()),
|
||||
syslog_identifier.data(), "CODE_FILE=%s", msg.source.filename,
|
||||
"CODE_LINE=%d", msg.source.line, "CODE_FUNC=%s",
|
||||
msg.source.funcname, nullptr);
|
||||
"SYSLOG_IDENTIFIER=%.*s", static_cast<int>(syslog_identifier.size()),
|
||||
syslog_identifier.data(), "CODE_FILE=%s", msg.source.filename, "CODE_LINE=%d",
|
||||
msg.source.line, "CODE_FUNC=%s", msg.source.funcname, nullptr);
|
||||
}
|
||||
|
||||
if (err) {
|
||||
|
@ -61,8 +61,7 @@ using udp_sink_st = udp_sink<spdlog::details::null_mutex>;
|
||||
// factory functions
|
||||
//
|
||||
template <typename Factory = spdlog::synchronous_factory>
|
||||
inline std::shared_ptr<logger> udp_logger_mt(const std::string &logger_name,
|
||||
sinks::udp_sink_config skin_config) {
|
||||
inline std::shared_ptr<logger> udp_logger_mt(const std::string &logger_name, sinks::udp_sink_config skin_config) {
|
||||
return Factory::template create<sinks::udp_sink_mt>(logger_name, skin_config);
|
||||
}
|
||||
|
||||
|
@ -74,11 +74,9 @@ struct win32_error : public spdlog_ex {
|
||||
std::string system_message;
|
||||
|
||||
local_alloc_t format_message_result{};
|
||||
auto format_message_succeeded =
|
||||
::FormatMessageA(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM |
|
||||
FORMAT_MESSAGE_IGNORE_INSERTS,
|
||||
nullptr, error_code, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
|
||||
(LPSTR)&format_message_result.hlocal_, 0, nullptr);
|
||||
auto format_message_succeeded = ::FormatMessageA(
|
||||
FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, nullptr,
|
||||
error_code, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), (LPSTR)&format_message_result.hlocal_, 0, nullptr);
|
||||
|
||||
if (format_message_succeeded && format_message_result.hlocal_) {
|
||||
system_message = fmt_lib::format(" ({})", (LPSTR)format_message_result.hlocal_);
|
||||
@ -131,21 +129,19 @@ public:
|
||||
|
||||
~process_token_t() { ::CloseHandle(token_handle_); }
|
||||
|
||||
} current_process_token(
|
||||
::GetCurrentProcess()); // GetCurrentProcess returns pseudohandle, no leak here!
|
||||
} current_process_token(::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
|
||||
DWORD tusize = 0;
|
||||
if (::GetTokenInformation(current_process_token.token_handle_, TokenUser, NULL, 0,
|
||||
&tusize)) {
|
||||
if (::GetTokenInformation(current_process_token.token_handle_, TokenUser, NULL, 0, &tusize)) {
|
||||
SPDLOG_THROW(win32_error("GetTokenInformation should fail"));
|
||||
}
|
||||
|
||||
// get user token
|
||||
std::vector<unsigned char> buffer(static_cast<size_t>(tusize));
|
||||
if (!::GetTokenInformation(current_process_token.token_handle_, TokenUser,
|
||||
(LPVOID)buffer.data(), tusize, &tusize)) {
|
||||
if (!::GetTokenInformation(current_process_token.token_handle_, TokenUser, (LPVOID)buffer.data(), tusize,
|
||||
&tusize)) {
|
||||
SPDLOG_THROW(win32_error("GetTokenInformation"));
|
||||
}
|
||||
|
||||
@ -214,9 +210,9 @@ protected:
|
||||
formatted.push_back('\0');
|
||||
|
||||
LPCSTR lp_str = formatted.data();
|
||||
succeeded = static_cast<bool>(::ReportEventA(
|
||||
event_log_handle(), eventlog::get_event_type(msg), eventlog::get_event_category(msg),
|
||||
event_id_, current_user_sid_.as_sid(), 1, 0, &lp_str, nullptr));
|
||||
succeeded = static_cast<bool>(::ReportEventA(event_log_handle(), eventlog::get_event_type(msg),
|
||||
eventlog::get_event_category(msg), event_id_,
|
||||
current_user_sid_.as_sid(), 1, 0, &lp_str, nullptr));
|
||||
|
||||
if (!succeeded) {
|
||||
SPDLOG_THROW(win32_error("ReportEvent"));
|
||||
@ -226,8 +222,7 @@ protected:
|
||||
void flush_() override {}
|
||||
|
||||
public:
|
||||
win_eventlog_sink(std::string const &source,
|
||||
DWORD event_id = 1000 /* according to mscoree.dll */)
|
||||
win_eventlog_sink(std::string const &source, DWORD event_id = 1000 /* according to mscoree.dll */)
|
||||
: source_(source),
|
||||
event_id_(event_id) {
|
||||
try {
|
||||
|
@ -21,25 +21,20 @@ namespace spdlog {
|
||||
// std::experimental::source_location or empty
|
||||
struct source_loc {
|
||||
constexpr source_loc() = default;
|
||||
constexpr source_loc(const char *filename_in,
|
||||
std::uint_least32_t line_in,
|
||||
const char *funcname_in)
|
||||
constexpr source_loc(const char *filename_in, std::uint_least32_t line_in, const char *funcname_in)
|
||||
: filename{filename_in},
|
||||
short_filename{basename(filename_in)},
|
||||
line{line_in},
|
||||
funcname{funcname_in} {}
|
||||
|
||||
#ifdef SPDLOG_HAVE_STD_SOURCE_LOCATION
|
||||
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()};
|
||||
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()};
|
||||
}
|
||||
#elif defined(SPDLOG_HAVE_EXPERIMENTAL_SOURCE_LOCATION)
|
||||
static constexpr source_loc current(const std::experimental::source_location source_location =
|
||||
std::experimental::source_location::current()) {
|
||||
return source_loc{source_location.file_name(), source_location.line(),
|
||||
source_location.function_name()};
|
||||
static constexpr source_loc current(
|
||||
const std::experimental::source_location source_location = std::experimental::source_location::current()) {
|
||||
return source_loc{source_location.file_name(), source_location.line(), source_location.function_name()};
|
||||
}
|
||||
#else // no source location support
|
||||
static constexpr source_loc current() { return source_loc{}; }
|
||||
|
@ -33,8 +33,7 @@ using default_factory = synchronous_factory;
|
||||
// spdlog::create<daily_file_sink_st>("logger_name", "dailylog_filename", 11, 59);
|
||||
template <typename Sink, typename... SinkArgs>
|
||||
inline std::shared_ptr<spdlog::logger> create(std::string logger_name, SinkArgs &&...sink_args) {
|
||||
return default_factory::create<Sink>(std::move(logger_name),
|
||||
std::forward<SinkArgs>(sink_args)...);
|
||||
return default_factory::create<Sink>(std::move(logger_name), std::forward<SinkArgs>(sink_args)...);
|
||||
}
|
||||
|
||||
// Initialize and register a logger,
|
||||
@ -57,8 +56,7 @@ SPDLOG_API void set_formatter(std::unique_ptr<spdlog::formatter> formatter);
|
||||
|
||||
// Set global format string.
|
||||
// example: spdlog::set_pattern("%Y-%m-%d %H:%M:%S.%e %l : %v");
|
||||
SPDLOG_API void set_pattern(std::string pattern,
|
||||
pattern_time_type time_type = pattern_time_type::local);
|
||||
SPDLOG_API void set_pattern(std::string pattern, pattern_time_type time_type = pattern_time_type::local);
|
||||
|
||||
// Get global logging level
|
||||
SPDLOG_API level get_level();
|
||||
@ -184,29 +182,17 @@ inline void critical(loc_with_fmt fmt, Args &&...args) {
|
||||
}
|
||||
|
||||
// log functions with no format string, just string
|
||||
inline void trace(string_view_t msg, source_loc loc = source_loc::current()) {
|
||||
log(loc, level::trace, msg);
|
||||
}
|
||||
inline void trace(string_view_t msg, source_loc loc = source_loc::current()) { log(loc, level::trace, msg); }
|
||||
|
||||
inline void debug(string_view_t msg, source_loc loc = source_loc::current()) {
|
||||
log(loc, level::debug, msg);
|
||||
}
|
||||
inline void debug(string_view_t msg, source_loc loc = source_loc::current()) { log(loc, level::debug, msg); }
|
||||
|
||||
inline void info(string_view_t msg, source_loc loc = source_loc::current()) {
|
||||
log(loc, level::info, msg);
|
||||
}
|
||||
inline void info(string_view_t msg, source_loc loc = source_loc::current()) { log(loc, level::info, msg); }
|
||||
|
||||
inline void warn(string_view_t msg, source_loc loc = source_loc::current()) {
|
||||
log(loc, spdlog::level::warn, msg);
|
||||
}
|
||||
inline void warn(string_view_t msg, source_loc loc = source_loc::current()) { log(loc, spdlog::level::warn, msg); }
|
||||
|
||||
inline void error(string_view_t msg, source_loc loc = source_loc::current()) {
|
||||
log(loc, level::err, msg);
|
||||
}
|
||||
inline void error(string_view_t msg, source_loc loc = source_loc::current()) { log(loc, level::err, msg); }
|
||||
|
||||
inline void critical(string_view_t msg, source_loc loc = source_loc::current()) {
|
||||
log(loc, level::critical, msg);
|
||||
}
|
||||
inline void critical(string_view_t msg, source_loc loc = source_loc::current()) { log(loc, level::critical, msg); }
|
||||
#else
|
||||
template <typename... Args>
|
||||
inline void trace(format_string_t<Args...> fmt, Args &&...args) {
|
||||
@ -271,13 +257,11 @@ inline void critical(string_view_t msg) { log(level::critical, msg); }
|
||||
#define SPDLOG_LOGGER_CALL(logger, level, ...) \
|
||||
(logger)->log(spdlog::source_loc{__FILE__, __LINE__, SPDLOG_FUNCTION}, level, __VA_ARGS__)
|
||||
#else
|
||||
#define SPDLOG_LOGGER_CALL(logger, level, ...) \
|
||||
(logger)->log(spdlog::source_loc{}, level, __VA_ARGS__)
|
||||
#define SPDLOG_LOGGER_CALL(logger, level, ...) (logger)->log(spdlog::source_loc{}, level, __VA_ARGS__)
|
||||
#endif
|
||||
|
||||
#if SPDLOG_ACTIVE_LEVEL <= SPDLOG_LEVEL_TRACE
|
||||
#define SPDLOG_LOGGER_TRACE(logger, ...) \
|
||||
SPDLOG_LOGGER_CALL(logger, spdlog::level::trace, __VA_ARGS__)
|
||||
#define SPDLOG_LOGGER_TRACE(logger, ...) SPDLOG_LOGGER_CALL(logger, spdlog::level::trace, __VA_ARGS__)
|
||||
#define SPDLOG_TRACE(...) SPDLOG_LOGGER_TRACE(spdlog::default_logger_raw(), __VA_ARGS__)
|
||||
#else
|
||||
#define SPDLOG_LOGGER_TRACE(logger, ...) (void)0
|
||||
@ -285,8 +269,7 @@ inline void critical(string_view_t msg) { log(level::critical, msg); }
|
||||
#endif
|
||||
|
||||
#if SPDLOG_ACTIVE_LEVEL <= SPDLOG_LEVEL_DEBUG
|
||||
#define SPDLOG_LOGGER_DEBUG(logger, ...) \
|
||||
SPDLOG_LOGGER_CALL(logger, spdlog::level::debug, __VA_ARGS__)
|
||||
#define SPDLOG_LOGGER_DEBUG(logger, ...) SPDLOG_LOGGER_CALL(logger, spdlog::level::debug, __VA_ARGS__)
|
||||
#define SPDLOG_DEBUG(...) SPDLOG_LOGGER_DEBUG(spdlog::default_logger_raw(), __VA_ARGS__)
|
||||
#else
|
||||
#define SPDLOG_LOGGER_DEBUG(logger, ...) (void)0
|
||||
@ -294,8 +277,7 @@ inline void critical(string_view_t msg) { log(level::critical, msg); }
|
||||
#endif
|
||||
|
||||
#if SPDLOG_ACTIVE_LEVEL <= SPDLOG_LEVEL_INFO
|
||||
#define SPDLOG_LOGGER_INFO(logger, ...) \
|
||||
SPDLOG_LOGGER_CALL(logger, spdlog::level::info, __VA_ARGS__)
|
||||
#define SPDLOG_LOGGER_INFO(logger, ...) SPDLOG_LOGGER_CALL(logger, spdlog::level::info, __VA_ARGS__)
|
||||
#define SPDLOG_INFO(...) SPDLOG_LOGGER_INFO(spdlog::default_logger_raw(), __VA_ARGS__)
|
||||
#else
|
||||
#define SPDLOG_LOGGER_INFO(logger, ...) (void)0
|
||||
@ -303,8 +285,7 @@ inline void critical(string_view_t msg) { log(level::critical, msg); }
|
||||
#endif
|
||||
|
||||
#if SPDLOG_ACTIVE_LEVEL <= SPDLOG_LEVEL_WARN
|
||||
#define SPDLOG_LOGGER_WARN(logger, ...) \
|
||||
SPDLOG_LOGGER_CALL(logger, spdlog::level::warn, __VA_ARGS__)
|
||||
#define SPDLOG_LOGGER_WARN(logger, ...) SPDLOG_LOGGER_CALL(logger, spdlog::level::warn, __VA_ARGS__)
|
||||
#define SPDLOG_WARN(...) SPDLOG_LOGGER_WARN(spdlog::default_logger_raw(), __VA_ARGS__)
|
||||
#else
|
||||
#define SPDLOG_LOGGER_WARN(logger, ...) (void)0
|
||||
@ -312,8 +293,7 @@ inline void critical(string_view_t msg) { log(level::critical, msg); }
|
||||
#endif
|
||||
|
||||
#if SPDLOG_ACTIVE_LEVEL <= SPDLOG_LEVEL_ERROR
|
||||
#define SPDLOG_LOGGER_ERROR(logger, ...) \
|
||||
SPDLOG_LOGGER_CALL(logger, spdlog::level::err, __VA_ARGS__)
|
||||
#define SPDLOG_LOGGER_ERROR(logger, ...) SPDLOG_LOGGER_CALL(logger, spdlog::level::err, __VA_ARGS__)
|
||||
#define SPDLOG_ERROR(...) SPDLOG_LOGGER_ERROR(spdlog::default_logger_raw(), __VA_ARGS__)
|
||||
#else
|
||||
#define SPDLOG_LOGGER_ERROR(logger, ...) (void)0
|
||||
@ -321,8 +301,7 @@ inline void critical(string_view_t msg) { log(level::critical, msg); }
|
||||
#endif
|
||||
|
||||
#if SPDLOG_ACTIVE_LEVEL <= SPDLOG_LEVEL_CRITICAL
|
||||
#define SPDLOG_LOGGER_CRITICAL(logger, ...) \
|
||||
SPDLOG_LOGGER_CALL(logger, spdlog::level::critical, __VA_ARGS__)
|
||||
#define SPDLOG_LOGGER_CRITICAL(logger, ...) SPDLOG_LOGGER_CALL(logger, spdlog::level::critical, __VA_ARGS__)
|
||||
#define SPDLOG_CRITICAL(...) SPDLOG_LOGGER_CRITICAL(spdlog::default_logger_raw(), __VA_ARGS__)
|
||||
#else
|
||||
#define SPDLOG_LOGGER_CRITICAL(logger, ...) (void)0
|
||||
|
@ -36,9 +36,7 @@ public:
|
||||
stopwatch()
|
||||
: start_tp_{clock::now()} {}
|
||||
|
||||
std::chrono::duration<double> elapsed() const {
|
||||
return std::chrono::duration<double>(clock::now() - start_tp_);
|
||||
}
|
||||
std::chrono::duration<double> elapsed() const { return std::chrono::duration<double>(clock::now() - start_tp_); }
|
||||
|
||||
void reset() { start_tp_ = clock::now(); }
|
||||
};
|
||||
|
@ -13,18 +13,13 @@ spdlog::async_logger::async_logger(std::string logger_name,
|
||||
sinks_init_list sinks_list,
|
||||
std::weak_ptr<details::thread_pool> tp,
|
||||
async_overflow_policy overflow_policy)
|
||||
: async_logger(std::move(logger_name),
|
||||
sinks_list.begin(),
|
||||
sinks_list.end(),
|
||||
std::move(tp),
|
||||
overflow_policy) {}
|
||||
: async_logger(std::move(logger_name), sinks_list.begin(), sinks_list.end(), std::move(tp), overflow_policy) {}
|
||||
|
||||
spdlog::async_logger::async_logger(std::string logger_name,
|
||||
sink_ptr single_sink,
|
||||
std::weak_ptr<details::thread_pool> tp,
|
||||
async_overflow_policy overflow_policy)
|
||||
: async_logger(
|
||||
std::move(logger_name), {std::move(single_sink)}, std::move(tp), overflow_policy) {}
|
||||
: async_logger(std::move(logger_name), {std::move(single_sink)}, std::move(tp), overflow_policy) {}
|
||||
|
||||
// send the log message to the thread pool
|
||||
void spdlog::async_logger::sink_it_(const details::log_msg &msg) {
|
||||
|
@ -17,9 +17,8 @@ namespace helpers {
|
||||
|
||||
// inplace convert to lowercase
|
||||
inline std::string &to_lower_(std::string &str) {
|
||||
std::transform(str.begin(), str.end(), str.begin(), [](char ch) {
|
||||
return static_cast<char>((ch >= 'A' && ch <= 'Z') ? ch + ('a' - 'A') : ch);
|
||||
});
|
||||
std::transform(str.begin(), str.end(), str.begin(),
|
||||
[](char ch) { return static_cast<char>((ch >= 'A' && ch <= 'Z') ? ch + ('a' - 'A') : ch); });
|
||||
return str;
|
||||
}
|
||||
|
||||
@ -93,8 +92,7 @@ void load_levels(const std::string &input) {
|
||||
}
|
||||
}
|
||||
|
||||
details::registry::instance().set_levels(std::move(levels),
|
||||
global_level_found ? &global_level : nullptr);
|
||||
details::registry::instance().set_levels(std::move(levels), global_level_found ? &global_level : nullptr);
|
||||
}
|
||||
|
||||
} // namespace helpers
|
||||
|
@ -38,9 +38,7 @@ spdlog_ex::spdlog_ex(const std::string &msg, int last_errno) {
|
||||
|
||||
const char *spdlog_ex::what() const noexcept { return msg_.c_str(); }
|
||||
|
||||
void throw_spdlog_ex(const std::string &msg, int last_errno) {
|
||||
SPDLOG_THROW(spdlog_ex(msg, last_errno));
|
||||
}
|
||||
void throw_spdlog_ex(const std::string &msg, int last_errno) { SPDLOG_THROW(spdlog_ex(msg, last_errno)); }
|
||||
|
||||
void throw_spdlog_ex(std::string msg) { SPDLOG_THROW(spdlog_ex(std::move(msg))); }
|
||||
|
||||
|
@ -53,8 +53,7 @@ void file_helper::open(const filename_t &fname, bool truncate) {
|
||||
details::os::sleep_for_millis(open_interval_);
|
||||
}
|
||||
|
||||
throw_spdlog_ex("Failed opening file " + os::filename_to_str(filename_) + " for writing",
|
||||
errno);
|
||||
throw_spdlog_ex("Failed opening file " + os::filename_to_str(filename_) + " for writing", errno);
|
||||
}
|
||||
|
||||
void file_helper::reopen(bool truncate) {
|
||||
@ -92,7 +91,7 @@ void file_helper::close() {
|
||||
}
|
||||
|
||||
void file_helper::write(const memory_buf_t &buf) {
|
||||
if(fd_ == nullptr) return;
|
||||
if (fd_ == nullptr) return;
|
||||
size_t msg_size = buf.size();
|
||||
auto data = buf.data();
|
||||
if (std::fwrite(data, 1, msg_size, fd_) != msg_size) {
|
||||
|
@ -25,10 +25,7 @@ log_msg::log_msg(spdlog::log_clock::time_point log_time,
|
||||
payload(msg) {
|
||||
}
|
||||
|
||||
log_msg::log_msg(spdlog::source_loc loc,
|
||||
string_view_t a_logger_name,
|
||||
spdlog::level lvl,
|
||||
spdlog::string_view_t msg)
|
||||
log_msg::log_msg(spdlog::source_loc loc, string_view_t a_logger_name, spdlog::level lvl, spdlog::string_view_t msg)
|
||||
: log_msg(os::now(), loc, a_logger_name, lvl, msg) {}
|
||||
|
||||
log_msg::log_msg(string_view_t a_logger_name, spdlog::level lvl, spdlog::string_view_t msg)
|
||||
|
@ -76,8 +76,8 @@ spdlog::log_clock::time_point now() noexcept {
|
||||
timespec ts;
|
||||
::clock_gettime(CLOCK_REALTIME_COARSE, &ts);
|
||||
return std::chrono::time_point<log_clock, typename log_clock::duration>(
|
||||
std::chrono::duration_cast<typename log_clock::duration>(
|
||||
std::chrono::seconds(ts.tv_sec) + std::chrono::nanoseconds(ts.tv_nsec)));
|
||||
std::chrono::duration_cast<typename log_clock::duration>(std::chrono::seconds(ts.tv_sec) +
|
||||
std::chrono::nanoseconds(ts.tv_nsec)));
|
||||
|
||||
#else
|
||||
return log_clock::now();
|
||||
@ -135,8 +135,7 @@ bool fopen_s(FILE **fp, const filename_t &filename, const filename_t &mode) {
|
||||
#else // unix
|
||||
#if defined(SPDLOG_PREVENT_CHILD_FD)
|
||||
const int mode_flag = mode == SPDLOG_FILENAME_T("ab") ? O_APPEND : O_TRUNC;
|
||||
const int fd =
|
||||
::open((filename.c_str()), O_CREAT | O_WRONLY | O_CLOEXEC | mode_flag, mode_t(0644));
|
||||
const int fd = ::open((filename.c_str()), O_CREAT | O_WRONLY | O_CLOEXEC | mode_flag, mode_t(0644));
|
||||
if (fd == -1) {
|
||||
return true;
|
||||
}
|
||||
@ -160,9 +159,7 @@ int remove(const filename_t &filename) noexcept {
|
||||
#endif
|
||||
}
|
||||
|
||||
int remove_if_exists(const filename_t &filename) noexcept {
|
||||
return path_exists(filename) ? remove(filename) : 0;
|
||||
}
|
||||
int remove_if_exists(const filename_t &filename) noexcept { return path_exists(filename) ? remove(filename) : 0; }
|
||||
|
||||
int rename(const filename_t &filename1, const filename_t &filename2) noexcept {
|
||||
#if defined(_WIN32) && defined(SPDLOG_WCHAR_FILENAMES)
|
||||
@ -263,8 +260,7 @@ int utc_minutes_offset(const std::tm &tm) {
|
||||
return offset;
|
||||
#else
|
||||
|
||||
#if defined(sun) || defined(__sun) || defined(_AIX) || \
|
||||
(defined(__NEWLIB__) && !defined(__TM_GMTOFF)) || \
|
||||
#if defined(sun) || defined(__sun) || defined(_AIX) || (defined(__NEWLIB__) && !defined(__TM_GMTOFF)) || \
|
||||
(!defined(_BSD_SOURCE) && !defined(_GNU_SOURCE))
|
||||
// 'tm_gmtoff' field is BSD extension and it's missing on SunOS/Solaris
|
||||
struct helper {
|
||||
@ -404,18 +400,17 @@ bool is_color_terminal() noexcept {
|
||||
return true;
|
||||
}
|
||||
|
||||
static constexpr std::array<const char *, 16> terms = {
|
||||
{"ansi", "color", "console", "cygwin", "gnome", "konsole", "kterm", "linux", "msys",
|
||||
"putty", "rxvt", "screen", "vt100", "xterm", "alacritty", "vt102"}};
|
||||
static constexpr std::array<const char *, 16> terms = {{"ansi", "color", "console", "cygwin", "gnome",
|
||||
"konsole", "kterm", "linux", "msys", "putty", "rxvt",
|
||||
"screen", "vt100", "xterm", "alacritty", "vt102"}};
|
||||
|
||||
const char *env_term_p = std::getenv("TERM");
|
||||
if (env_term_p == nullptr) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return std::any_of(terms.begin(), terms.end(), [&](const char *term) {
|
||||
return std::strstr(env_term_p, term) != nullptr;
|
||||
});
|
||||
return std::any_of(terms.begin(), terms.end(),
|
||||
[&](const char *term) { return std::strstr(env_term_p, term) != nullptr; });
|
||||
}();
|
||||
|
||||
return result;
|
||||
@ -446,14 +441,12 @@ void wstr_to_utf8buf(wstring_view_t wstr, memory_buf_t &target) {
|
||||
|
||||
int result_size = static_cast<int>(target.capacity());
|
||||
if ((wstr_size + 1) * 2 > result_size) {
|
||||
result_size =
|
||||
::WideCharToMultiByte(CP_UTF8, 0, wstr.data(), wstr_size, NULL, 0, NULL, NULL);
|
||||
result_size = ::WideCharToMultiByte(CP_UTF8, 0, wstr.data(), wstr_size, NULL, 0, NULL, NULL);
|
||||
}
|
||||
|
||||
if (result_size > 0) {
|
||||
target.resize(result_size);
|
||||
result_size = ::WideCharToMultiByte(CP_UTF8, 0, wstr.data(), wstr_size, target.data(),
|
||||
result_size, NULL, NULL);
|
||||
result_size = ::WideCharToMultiByte(CP_UTF8, 0, wstr.data(), wstr_size, target.data(), result_size, NULL, NULL);
|
||||
|
||||
if (result_size > 0) {
|
||||
target.resize(result_size);
|
||||
@ -461,8 +454,7 @@ void wstr_to_utf8buf(wstring_view_t wstr, memory_buf_t &target) {
|
||||
}
|
||||
}
|
||||
|
||||
throw_spdlog_ex(
|
||||
fmt_lib::format("WideCharToMultiByte failed. Last error: {}", ::GetLastError()));
|
||||
throw_spdlog_ex(fmt_lib::format("WideCharToMultiByte failed. Last error: {}", ::GetLastError()));
|
||||
}
|
||||
|
||||
void utf8_to_wstrbuf(string_view_t str, wmemory_buf_t &target) {
|
||||
@ -477,21 +469,19 @@ void utf8_to_wstrbuf(string_view_t str, wmemory_buf_t &target) {
|
||||
}
|
||||
|
||||
// find the size to allocate for the result buffer
|
||||
int result_size =
|
||||
::MultiByteToWideChar(CP_UTF8, MB_ERR_INVALID_CHARS, str.data(), str_size, NULL, 0);
|
||||
int result_size = ::MultiByteToWideChar(CP_UTF8, MB_ERR_INVALID_CHARS, str.data(), str_size, NULL, 0);
|
||||
|
||||
if (result_size > 0) {
|
||||
target.resize(result_size);
|
||||
result_size = ::MultiByteToWideChar(CP_UTF8, MB_ERR_INVALID_CHARS, str.data(), str_size,
|
||||
target.data(), result_size);
|
||||
result_size =
|
||||
::MultiByteToWideChar(CP_UTF8, MB_ERR_INVALID_CHARS, str.data(), str_size, target.data(), result_size);
|
||||
if (result_size > 0) {
|
||||
assert(result_size == target.size());
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
throw_spdlog_ex(
|
||||
fmt_lib::format("MultiByteToWideChar failed. Last error: {}", ::GetLastError()));
|
||||
throw_spdlog_ex(fmt_lib::format("MultiByteToWideChar failed. Last error: {}", ::GetLastError()));
|
||||
}
|
||||
#endif // defined(SPDLOG_WCHAR_FILENAMES) && defined(_WIN32)
|
||||
|
||||
|
@ -29,9 +29,7 @@ thread_pool::thread_pool(size_t q_max_items,
|
||||
}
|
||||
}
|
||||
|
||||
thread_pool::thread_pool(size_t q_max_items,
|
||||
size_t threads_n,
|
||||
std::function<void()> on_thread_start)
|
||||
thread_pool::thread_pool(size_t q_max_items, size_t threads_n, std::function<void()> on_thread_start)
|
||||
: thread_pool(q_max_items, threads_n, on_thread_start, [] {}) {}
|
||||
|
||||
thread_pool::thread_pool(size_t q_max_items, size_t threads_n)
|
||||
|
@ -4,7 +4,7 @@
|
||||
|
||||
#if defined(SPDLOG_USE_STD_FORMAT)
|
||||
|
||||
#include "spdlog/fmt/bundled/format-inl.h"
|
||||
#include "spdlog/fmt/bundled/format-inl.h"
|
||||
FMT_BEGIN_NAMESPACE
|
||||
namespace detail {
|
||||
|
||||
@ -23,10 +23,7 @@ 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.
|
||||
|
||||
|
@ -104,11 +104,10 @@ void logger::err_handler_(const std::string &msg) {
|
||||
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
|
||||
REprintf("[*** LOG ERROR #%04zu ***] [%s] [%s] %s\n", err_counter, date_buf, name().c_str(),
|
||||
msg.c_str());
|
||||
REprintf("[*** LOG ERROR #%04zu ***] [%s] [%s] %s\n", err_counter, date_buf, name().c_str(), msg.c_str());
|
||||
#else
|
||||
std::fprintf(stderr, "[*** LOG ERROR #%04zu ***] [%s] [%s] %s\n", err_counter, date_buf,
|
||||
name().c_str(), msg.c_str());
|
||||
std::fprintf(stderr, "[*** LOG ERROR #%04zu ***] [%s] [%s] %s\n", err_counter, date_buf, name().c_str(),
|
||||
msg.c_str());
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
@ -63,8 +63,7 @@ public:
|
||||
|
||||
private:
|
||||
void pad_it(long count) {
|
||||
fmt_helper::append_string_view(string_view_t(spaces_.data(), static_cast<size_t>(count)),
|
||||
dest_);
|
||||
fmt_helper::append_string_view(string_view_t(spaces_.data(), static_cast<size_t>(count)), dest_);
|
||||
}
|
||||
|
||||
const padding_info &padinfo_;
|
||||
@ -74,9 +73,7 @@ private:
|
||||
};
|
||||
|
||||
struct null_scoped_padder {
|
||||
null_scoped_padder(size_t /*wrapped_size*/,
|
||||
const padding_info & /*padinfo*/,
|
||||
memory_buf_t & /*dest*/) {}
|
||||
null_scoped_padder(size_t /*wrapped_size*/, const padding_info & /*padinfo*/, memory_buf_t & /*dest*/) {}
|
||||
|
||||
template <typename T>
|
||||
static unsigned int count_digits(T /* number */) {
|
||||
@ -183,9 +180,8 @@ public:
|
||||
};
|
||||
|
||||
// Full month name
|
||||
static const std::array<const char *, 12> full_months{{"January", "February", "March", "April",
|
||||
"May", "June", "July", "August", "September",
|
||||
"October", "November", "December"}};
|
||||
static const std::array<const char *, 12> full_months{{"January", "February", "March", "April", "May", "June", "July",
|
||||
"August", "September", "October", "November", "December"}};
|
||||
|
||||
template <typename ScopedPadder>
|
||||
class B_formatter final : public flag_formatter {
|
||||
@ -582,9 +578,7 @@ public:
|
||||
explicit ch_formatter(char ch)
|
||||
: ch_(ch) {}
|
||||
|
||||
void format(const details::log_msg &, const std::tm &, memory_buf_t &dest) override {
|
||||
dest.push_back(ch_);
|
||||
}
|
||||
void format(const details::log_msg &, const std::tm &, memory_buf_t &dest) override { dest.push_back(ch_); }
|
||||
|
||||
private:
|
||||
char ch_;
|
||||
@ -641,8 +635,8 @@ public:
|
||||
size_t text_size;
|
||||
if (padinfo_.enabled()) {
|
||||
// calc text size for padding based on "filename:line"
|
||||
text_size = std::char_traits<char>::length(msg.source.filename) +
|
||||
ScopedPadder::count_digits(msg.source.line) + 1;
|
||||
text_size =
|
||||
std::char_traits<char>::length(msg.source.filename) + ScopedPadder::count_digits(msg.source.line) + 1;
|
||||
} else {
|
||||
text_size = 0;
|
||||
}
|
||||
@ -666,8 +660,7 @@ public:
|
||||
ScopedPadder p(0, padinfo_, dest);
|
||||
return;
|
||||
}
|
||||
size_t text_size =
|
||||
padinfo_.enabled() ? std::char_traits<char>::length(msg.source.filename) : 0;
|
||||
size_t text_size = padinfo_.enabled() ? std::char_traits<char>::length(msg.source.filename) : 0;
|
||||
ScopedPadder p(text_size, padinfo_, dest);
|
||||
fmt_helper::append_string_view(msg.source.filename, dest);
|
||||
}
|
||||
@ -721,8 +714,7 @@ public:
|
||||
ScopedPadder p(0, padinfo_, dest);
|
||||
return;
|
||||
}
|
||||
size_t text_size =
|
||||
padinfo_.enabled() ? std::char_traits<char>::length(msg.source.funcname) : 0;
|
||||
size_t text_size = padinfo_.enabled() ? std::char_traits<char>::length(msg.source.funcname) : 0;
|
||||
ScopedPadder p(text_size, padinfo_, dest);
|
||||
fmt_helper::append_string_view(msg.source.funcname, dest);
|
||||
}
|
||||
@ -866,8 +858,8 @@ std::unique_ptr<formatter> pattern_formatter::clone() const {
|
||||
for (auto &it : custom_handlers_) {
|
||||
cloned_custom_formatters[it.first] = it.second->clone();
|
||||
}
|
||||
auto cloned = std::make_unique<pattern_formatter>(pattern_, pattern_time_type_, eol_,
|
||||
std::move(cloned_custom_formatters));
|
||||
auto cloned =
|
||||
std::make_unique<pattern_formatter>(pattern_, pattern_time_type_, eol_, std::move(cloned_custom_formatters));
|
||||
cloned->need_localtime(need_localtime_);
|
||||
#if defined(__GNUC__) && __GNUC__ < 5
|
||||
return std::move(cloned);
|
||||
@ -878,8 +870,7 @@ std::unique_ptr<formatter> pattern_formatter::clone() const {
|
||||
|
||||
void pattern_formatter::format(const details::log_msg &msg, memory_buf_t &dest) {
|
||||
if (need_localtime_) {
|
||||
const auto secs =
|
||||
std::chrono::duration_cast<std::chrono::seconds>(msg.time.time_since_epoch());
|
||||
const auto secs = std::chrono::duration_cast<std::chrono::seconds>(msg.time.time_since_epoch());
|
||||
if (secs != last_log_secs_) {
|
||||
cached_tm_ = get_time_(msg);
|
||||
last_log_secs_ = secs;
|
||||
@ -935,8 +926,7 @@ void pattern_formatter::handle_flag_(char flag, details::padding_info padding) {
|
||||
break;
|
||||
|
||||
case 'L': // short level
|
||||
formatters_.push_back(
|
||||
std::make_unique<details::short_level_formatter<Padder>>(padding));
|
||||
formatters_.push_back(std::make_unique<details::short_level_formatter<Padder>>(padding));
|
||||
break;
|
||||
|
||||
case ('t'): // thread id
|
||||
@ -1074,28 +1064,23 @@ void pattern_formatter::handle_flag_(char flag, details::padding_info padding) {
|
||||
break;
|
||||
|
||||
case ('@'): // source location (filename:filenumber)
|
||||
formatters_.push_back(
|
||||
std::make_unique<details::source_location_formatter<Padder>>(padding));
|
||||
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));
|
||||
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));
|
||||
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));
|
||||
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));
|
||||
formatters_.push_back(std::make_unique<details::source_funcname_formatter<Padder>>(padding));
|
||||
break;
|
||||
|
||||
case ('%'): // % char
|
||||
@ -1104,26 +1089,21 @@ void pattern_formatter::handle_flag_(char flag, details::padding_info padding) {
|
||||
|
||||
case ('u'): // elapsed time since last log message in nanos
|
||||
formatters_.push_back(
|
||||
std::make_unique<details::elapsed_formatter<Padder, std::chrono::nanoseconds>>(
|
||||
padding));
|
||||
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));
|
||||
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));
|
||||
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));
|
||||
formatters_.push_back(std::make_unique<details::elapsed_formatter<Padder, std::chrono::seconds>>(padding));
|
||||
break;
|
||||
|
||||
default: // Unknown flag appears as is
|
||||
@ -1139,8 +1119,7 @@ void pattern_formatter::handle_flag_(char flag, details::padding_info padding) {
|
||||
// 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));
|
||||
formatters_.push_back(std::make_unique<details::source_funcname_formatter<Padder>>(padding));
|
||||
unknown_flag->add_ch(flag);
|
||||
formatters_.push_back((std::move(unknown_flag)));
|
||||
}
|
||||
|
@ -45,8 +45,7 @@ void ansicolor_sink<Mutex>::set_color_mode(color_mode mode) {
|
||||
should_do_colors_ = true;
|
||||
return;
|
||||
case color_mode::automatic:
|
||||
should_do_colors_ =
|
||||
details::os::in_terminal(target_file_) && details::os::is_color_terminal();
|
||||
should_do_colors_ = details::os::in_terminal(target_file_) && details::os::is_color_terminal();
|
||||
return;
|
||||
case color_mode::never:
|
||||
should_do_colors_ = false;
|
||||
|
@ -7,8 +7,8 @@
|
||||
#include <mutex>
|
||||
|
||||
#include "spdlog/common.h"
|
||||
#include "spdlog/pattern_formatter.h"
|
||||
#include "spdlog/details/null_mutex.h"
|
||||
#include "spdlog/pattern_formatter.h"
|
||||
|
||||
template <typename Mutex>
|
||||
spdlog::sinks::base_sink<Mutex>::base_sink()
|
||||
@ -37,8 +37,7 @@ void spdlog::sinks::base_sink<Mutex>::set_pattern(const std::string &pattern) {
|
||||
}
|
||||
|
||||
template <typename Mutex>
|
||||
void spdlog::sinks::base_sink<Mutex>::set_formatter(
|
||||
std::unique_ptr<spdlog::formatter> sink_formatter) {
|
||||
void spdlog::sinks::base_sink<Mutex>::set_formatter(std::unique_ptr<spdlog::formatter> sink_formatter) {
|
||||
std::lock_guard<Mutex> lock(mutex_);
|
||||
set_formatter_(std::move(sink_formatter));
|
||||
}
|
||||
@ -49,8 +48,7 @@ void spdlog::sinks::base_sink<Mutex>::set_pattern_(const std::string &pattern) {
|
||||
}
|
||||
|
||||
template <typename Mutex>
|
||||
void spdlog::sinks::base_sink<Mutex>::set_formatter_(
|
||||
std::unique_ptr<spdlog::formatter> sink_formatter) {
|
||||
void spdlog::sinks::base_sink<Mutex>::set_formatter_(std::unique_ptr<spdlog::formatter> sink_formatter) {
|
||||
formatter_ = std::move(sink_formatter);
|
||||
}
|
||||
|
||||
|
@ -11,7 +11,7 @@
|
||||
#include "spdlog/common.h"
|
||||
#include "spdlog/details/file_helper.h"
|
||||
#include "spdlog/details/os.h"
|
||||
//#include "spdlog/fmt/fmt.h"
|
||||
// #include "spdlog/fmt/fmt.h"
|
||||
|
||||
namespace spdlog {
|
||||
namespace sinks {
|
||||
@ -113,9 +113,9 @@ void rotating_file_sink<Mutex>::rotate_() {
|
||||
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),
|
||||
errno);
|
||||
throw_spdlog_ex(
|
||||
"rotating_file_sink: failed renaming " + filename_to_str(src) + " to " + filename_to_str(target),
|
||||
errno);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -125,8 +125,7 @@ void rotating_file_sink<Mutex>::rotate_() {
|
||||
// delete the target if exists, and rename the src file to target
|
||||
// return true on success, false otherwise.
|
||||
template <typename Mutex>
|
||||
bool rotating_file_sink<Mutex>::rename_file_(const filename_t &src_filename,
|
||||
const filename_t &target_filename) {
|
||||
bool rotating_file_sink<Mutex>::rename_file_(const filename_t &src_filename, const filename_t &target_filename) {
|
||||
// try to delete the target file in case it already exists.
|
||||
(void)details::os::remove(target_filename);
|
||||
return details::os::rename(src_filename, target_filename) == 0;
|
||||
|
@ -32,21 +32,17 @@ std::shared_ptr<logger> stderr_color_st(const std::string &logger_name, color_mo
|
||||
} // namespace spdlog
|
||||
|
||||
// template instantiations
|
||||
template SPDLOG_API std::shared_ptr<spdlog::logger>
|
||||
spdlog::stdout_color_mt<spdlog::synchronous_factory>(const std::string &logger_name,
|
||||
color_mode mode);
|
||||
template SPDLOG_API std::shared_ptr<spdlog::logger> spdlog::stdout_color_mt<spdlog::synchronous_factory>(
|
||||
const std::string &logger_name, color_mode mode);
|
||||
|
||||
template SPDLOG_API std::shared_ptr<spdlog::logger>
|
||||
spdlog::stdout_color_st<spdlog::synchronous_factory>(const std::string &logger_name,
|
||||
color_mode mode);
|
||||
template SPDLOG_API std::shared_ptr<spdlog::logger> spdlog::stdout_color_st<spdlog::synchronous_factory>(
|
||||
const std::string &logger_name, color_mode mode);
|
||||
|
||||
template SPDLOG_API std::shared_ptr<spdlog::logger>
|
||||
spdlog::stderr_color_mt<spdlog::synchronous_factory>(const std::string &logger_name,
|
||||
color_mode mode);
|
||||
template SPDLOG_API std::shared_ptr<spdlog::logger> spdlog::stderr_color_mt<spdlog::synchronous_factory>(
|
||||
const std::string &logger_name, color_mode mode);
|
||||
|
||||
template SPDLOG_API std::shared_ptr<spdlog::logger>
|
||||
spdlog::stderr_color_st<spdlog::synchronous_factory>(const std::string &logger_name,
|
||||
color_mode mode);
|
||||
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);
|
||||
|
@ -56,8 +56,7 @@ void stdout_sink_base<Mutex>::sink_it_(const details::log_msg &msg) {
|
||||
DWORD bytes_written = 0;
|
||||
bool ok = ::WriteFile(handle_, formatted.data(), size, &bytes_written, nullptr) != 0;
|
||||
if (!ok) {
|
||||
throw_spdlog_ex("stdout_sink_base: WriteFile() failed. GetLastError(): " +
|
||||
std::to_string(::GetLastError()));
|
||||
throw_spdlog_ex("stdout_sink_base: WriteFile() failed. GetLastError(): " + std::to_string(::GetLastError()));
|
||||
}
|
||||
#else
|
||||
memory_buf_t formatted;
|
||||
@ -118,14 +117,14 @@ template class SPDLOG_API spdlog::sinks::stderr_sink<spdlog::details::null_mutex
|
||||
#include "spdlog/async.h"
|
||||
#include "spdlog/details/synchronous_factory.h"
|
||||
|
||||
template SPDLOG_API std::shared_ptr<spdlog::logger>
|
||||
spdlog::stdout_logger_mt<spdlog::synchronous_factory>(const std::string &logger_name);
|
||||
template SPDLOG_API std::shared_ptr<spdlog::logger>
|
||||
spdlog::stdout_logger_st<spdlog::synchronous_factory>(const std::string &logger_name);
|
||||
template SPDLOG_API std::shared_ptr<spdlog::logger>
|
||||
spdlog::stderr_logger_mt<spdlog::synchronous_factory>(const std::string &logger_name);
|
||||
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::synchronous_factory>(
|
||||
const std::string &logger_name);
|
||||
template SPDLOG_API std::shared_ptr<spdlog::logger> spdlog::stdout_logger_st<spdlog::synchronous_factory>(
|
||||
const std::string &logger_name);
|
||||
template SPDLOG_API std::shared_ptr<spdlog::logger> spdlog::stderr_logger_mt<spdlog::synchronous_factory>(
|
||||
const std::string &logger_name);
|
||||
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);
|
||||
|
@ -20,16 +20,15 @@ wincolor_sink<Mutex>::wincolor_sink(void *out_handle, color_mode mode)
|
||||
: out_handle_(out_handle) {
|
||||
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
|
||||
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
|
||||
colors_.at(level_to_number(level::warn)) =
|
||||
FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_INTENSITY; // intense yellow
|
||||
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
|
||||
colors_.at(level_to_number(level::critical)) = BACKGROUND_RED | FOREGROUND_RED | FOREGROUND_GREEN |
|
||||
FOREGROUND_BLUE |
|
||||
FOREGROUND_INTENSITY; // intense white on red background
|
||||
colors_.at(level_to_number(level::off)) = 0;
|
||||
}
|
||||
|
||||
@ -59,8 +58,7 @@ void wincolor_sink<Mutex>::sink_it_(const details::log_msg &msg) {
|
||||
// before color range
|
||||
print_range_(formatted, 0, msg.color_range_start);
|
||||
// in color range
|
||||
auto orig_attribs =
|
||||
static_cast<WORD>(set_foreground_color_(colors_[static_cast<size_t>(msg.log_level)]));
|
||||
auto orig_attribs = static_cast<WORD>(set_foreground_color_(colors_[static_cast<size_t>(msg.log_level)]));
|
||||
print_range_(formatted, msg.color_range_start, msg.color_range_end);
|
||||
// reset to orig colors
|
||||
::SetConsoleTextAttribute(static_cast<HANDLE>(out_handle_), orig_attribs);
|
||||
@ -105,8 +103,7 @@ std::uint16_t wincolor_sink<Mutex>::set_foreground_color_(std::uint16_t attribs)
|
||||
|
||||
// change only the foreground bits (lowest 4 bits)
|
||||
auto new_attribs = static_cast<WORD>(attribs) | (orig_buffer_info.wAttributes & 0xfff0);
|
||||
auto ignored =
|
||||
::SetConsoleTextAttribute(static_cast<HANDLE>(out_handle_), static_cast<WORD>(new_attribs));
|
||||
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
|
||||
}
|
||||
@ -116,8 +113,8 @@ template <typename Mutex>
|
||||
void wincolor_sink<Mutex>::print_range_(const memory_buf_t &formatted, size_t start, size_t end) {
|
||||
if (end > start) {
|
||||
auto size = static_cast<DWORD>(end - start);
|
||||
auto ignored = ::WriteConsoleA(static_cast<HANDLE>(out_handle_), formatted.data() + start,
|
||||
size, nullptr, nullptr);
|
||||
auto ignored =
|
||||
::WriteConsoleA(static_cast<HANDLE>(out_handle_), formatted.data() + start, size, nullptr, nullptr);
|
||||
(void)(ignored);
|
||||
}
|
||||
}
|
||||
@ -126,8 +123,7 @@ template <typename Mutex>
|
||||
void wincolor_sink<Mutex>::write_to_file_(const memory_buf_t &formatted) {
|
||||
auto size = static_cast<DWORD>(formatted.size());
|
||||
DWORD bytes_written = 0;
|
||||
auto ignored = ::WriteFile(static_cast<HANDLE>(out_handle_), formatted.data(), size,
|
||||
&bytes_written, nullptr);
|
||||
auto ignored = ::WriteFile(static_cast<HANDLE>(out_handle_), formatted.data(), size, &bytes_written, nullptr);
|
||||
(void)(ignored);
|
||||
}
|
||||
|
||||
|
@ -16,9 +16,7 @@ void initialize_logger(std::shared_ptr<logger> logger) {
|
||||
details::registry::instance().initialize_logger(std::move(logger));
|
||||
}
|
||||
|
||||
std::shared_ptr<logger> get(const std::string &name) {
|
||||
return details::registry::instance().get(name);
|
||||
}
|
||||
std::shared_ptr<logger> get(const std::string &name) { return details::registry::instance().get(name); }
|
||||
|
||||
void set_formatter(std::unique_ptr<spdlog::formatter> formatter) {
|
||||
details::registry::instance().set_formatter(std::move(formatter));
|
||||
@ -58,9 +56,7 @@ void set_automatic_registration(bool automatic_registration) {
|
||||
details::registry::instance().set_automatic_registration(automatic_registration);
|
||||
}
|
||||
|
||||
std::shared_ptr<spdlog::logger> default_logger() {
|
||||
return details::registry::instance().default_logger();
|
||||
}
|
||||
std::shared_ptr<spdlog::logger> default_logger() { return details::registry::instance().default_logger(); }
|
||||
|
||||
spdlog::logger *default_logger_raw() { return details::registry::instance().get_default_raw(); }
|
||||
|
||||
|
@ -12,8 +12,7 @@ TEST_CASE("basic async test ", "[async]") {
|
||||
size_t messages = 256;
|
||||
{
|
||||
auto tp = std::make_shared<spdlog::details::thread_pool>(queue_size, 1);
|
||||
auto logger = std::make_shared<spdlog::async_logger>("as", test_sink, tp,
|
||||
spdlog::async_overflow_policy::block);
|
||||
auto logger = std::make_shared<spdlog::async_logger>("as", test_sink, tp, spdlog::async_overflow_policy::block);
|
||||
for (size_t i = 0; i < messages; i++) {
|
||||
logger->info("Hello message #{}", i);
|
||||
}
|
||||
@ -32,8 +31,8 @@ TEST_CASE("discard policy ", "[async]") {
|
||||
size_t messages = 1024;
|
||||
|
||||
auto tp = std::make_shared<spdlog::details::thread_pool>(queue_size, 1);
|
||||
auto logger = std::make_shared<spdlog::async_logger>(
|
||||
"as", test_sink, tp, spdlog::async_overflow_policy::overrun_oldest);
|
||||
auto logger =
|
||||
std::make_shared<spdlog::async_logger>("as", test_sink, tp, spdlog::async_overflow_policy::overrun_oldest);
|
||||
for (size_t i = 0; i < messages; i++) {
|
||||
logger->info("Hello message");
|
||||
}
|
||||
@ -48,8 +47,8 @@ TEST_CASE("discard policy discard_new ", "[async]") {
|
||||
size_t messages = 1024;
|
||||
|
||||
auto tp = std::make_shared<spdlog::details::thread_pool>(queue_size, 1);
|
||||
auto logger = std::make_shared<spdlog::async_logger>(
|
||||
"as", test_sink, tp, spdlog::async_overflow_policy::discard_new);
|
||||
auto logger =
|
||||
std::make_shared<spdlog::async_logger>("as", test_sink, tp, spdlog::async_overflow_policy::discard_new);
|
||||
for (size_t i = 0; i < messages; i++) {
|
||||
logger->info("Hello message");
|
||||
}
|
||||
@ -80,8 +79,7 @@ TEST_CASE("flush", "[async]") {
|
||||
size_t messages = 256;
|
||||
{
|
||||
auto tp = std::make_shared<spdlog::details::thread_pool>(queue_size, 1);
|
||||
auto logger = std::make_shared<spdlog::async_logger>("as", test_sink, tp,
|
||||
spdlog::async_overflow_policy::block);
|
||||
auto logger = std::make_shared<spdlog::async_logger>("as", test_sink, tp, spdlog::async_overflow_policy::block);
|
||||
for (size_t i = 0; i < messages; i++) {
|
||||
logger->info("Hello message #{}", i);
|
||||
}
|
||||
@ -110,8 +108,7 @@ TEST_CASE("tp->wait_empty() ", "[async]") {
|
||||
size_t messages = 100;
|
||||
|
||||
auto tp = std::make_shared<spdlog::details::thread_pool>(messages, 2);
|
||||
auto logger = std::make_shared<spdlog::async_logger>("as", test_sink, tp,
|
||||
spdlog::async_overflow_policy::block);
|
||||
auto logger = std::make_shared<spdlog::async_logger>("as", test_sink, tp, spdlog::async_overflow_policy::block);
|
||||
for (size_t i = 0; i < messages; i++) {
|
||||
logger->info("Hello message #{}", i);
|
||||
}
|
||||
@ -129,8 +126,7 @@ TEST_CASE("multi threads", "[async]") {
|
||||
size_t n_threads = 10;
|
||||
{
|
||||
auto tp = std::make_shared<spdlog::details::thread_pool>(queue_size, 1);
|
||||
auto logger = std::make_shared<spdlog::async_logger>("as", test_sink, tp,
|
||||
spdlog::async_overflow_policy::block);
|
||||
auto logger = std::make_shared<spdlog::async_logger>("as", test_sink, tp, spdlog::async_overflow_policy::block);
|
||||
|
||||
std::vector<std::thread> threads;
|
||||
for (size_t i = 0; i < n_threads; i++) {
|
||||
@ -159,8 +155,7 @@ TEST_CASE("to_file", "[async]") {
|
||||
{
|
||||
auto file_sink = std::make_shared<spdlog::sinks::basic_file_sink_mt>(filename, true);
|
||||
auto tp = std::make_shared<spdlog::details::thread_pool>(messages, tp_threads);
|
||||
auto logger =
|
||||
std::make_shared<spdlog::async_logger>("as", std::move(file_sink), std::move(tp));
|
||||
auto logger = std::make_shared<spdlog::async_logger>("as", std::move(file_sink), std::move(tp));
|
||||
|
||||
for (size_t j = 0; j < messages; j++) {
|
||||
logger->info("Hello message #{}", j);
|
||||
@ -181,8 +176,7 @@ TEST_CASE("to_file multi-workers", "[async]") {
|
||||
{
|
||||
auto file_sink = std::make_shared<spdlog::sinks::basic_file_sink_mt>(filename, true);
|
||||
auto tp = std::make_shared<spdlog::details::thread_pool>(messages, tp_threads);
|
||||
auto logger =
|
||||
std::make_shared<spdlog::async_logger>("as", std::move(file_sink), std::move(tp));
|
||||
auto logger = std::make_shared<spdlog::async_logger>("as", std::move(file_sink), std::move(tp));
|
||||
|
||||
for (size_t j = 0; j < messages; j++) {
|
||||
logger->info("Hello message #{}", j);
|
||||
|
@ -12,8 +12,7 @@ TEST_CASE("to_hex", "[to_hex]") {
|
||||
oss_logger.info("{}", spdlog::to_hex(v));
|
||||
|
||||
auto output = oss.str();
|
||||
REQUIRE(ends_with(output,
|
||||
"0000: 09 0a 0b 0c ff ff" + std::string(spdlog::details::os::default_eol)));
|
||||
REQUIRE(ends_with(output, "0000: 09 0a 0b 0c ff ff" + std::string(spdlog::details::os::default_eol)));
|
||||
}
|
||||
|
||||
TEST_CASE("to_hex_upper", "[to_hex]") {
|
||||
@ -25,8 +24,7 @@ TEST_CASE("to_hex_upper", "[to_hex]") {
|
||||
oss_logger.info("{:X}", spdlog::to_hex(v));
|
||||
|
||||
auto output = oss.str();
|
||||
REQUIRE(ends_with(output,
|
||||
"0000: 09 0A 0B 0C FF FF" + std::string(spdlog::details::os::default_eol)));
|
||||
REQUIRE(ends_with(output, "0000: 09 0A 0B 0C FF FF" + std::string(spdlog::details::os::default_eol)));
|
||||
}
|
||||
|
||||
TEST_CASE("to_hex_no_delimiter", "[to_hex]") {
|
||||
@ -38,8 +36,7 @@ TEST_CASE("to_hex_no_delimiter", "[to_hex]") {
|
||||
oss_logger.info("{:sX}", spdlog::to_hex(v));
|
||||
|
||||
auto output = oss.str();
|
||||
REQUIRE(
|
||||
ends_with(output, "0000: 090A0B0CFFFF" + std::string(spdlog::details::os::default_eol)));
|
||||
REQUIRE(ends_with(output, "0000: 090A0B0CFFFF" + std::string(spdlog::details::os::default_eol)));
|
||||
}
|
||||
|
||||
TEST_CASE("to_hex_show_ascii", "[to_hex]") {
|
||||
@ -50,8 +47,7 @@ TEST_CASE("to_hex_show_ascii", "[to_hex]") {
|
||||
std::vector<unsigned char> v{9, 0xa, 0xb, 0x41, 0xc, 0x4b, 0xff, 0xff};
|
||||
oss_logger.info("{:Xsa}", spdlog::to_hex(v, 8));
|
||||
|
||||
REQUIRE(ends_with(oss.str(), "0000: 090A0B410C4BFFFF ...A.K.." +
|
||||
std::string(spdlog::details::os::default_eol)));
|
||||
REQUIRE(ends_with(oss.str(), "0000: 090A0B410C4BFFFF ...A.K.." + std::string(spdlog::details::os::default_eol)));
|
||||
}
|
||||
|
||||
TEST_CASE("to_hex_different_size_per_line", "[to_hex]") {
|
||||
@ -62,21 +58,17 @@ TEST_CASE("to_hex_different_size_per_line", "[to_hex]") {
|
||||
std::vector<unsigned char> v{9, 0xa, 0xb, 0x41, 0xc, 0x4b, 0xff, 0xff};
|
||||
|
||||
oss_logger.info("{:Xsa}", spdlog::to_hex(v, 10));
|
||||
REQUIRE(ends_with(oss.str(), "0000: 090A0B410C4BFFFF ...A.K.." +
|
||||
std::string(spdlog::details::os::default_eol)));
|
||||
REQUIRE(ends_with(oss.str(), "0000: 090A0B410C4BFFFF ...A.K.." + std::string(spdlog::details::os::default_eol)));
|
||||
|
||||
oss_logger.info("{:Xs}", spdlog::to_hex(v, 10));
|
||||
REQUIRE(ends_with(oss.str(),
|
||||
"0000: 090A0B410C4BFFFF" + std::string(spdlog::details::os::default_eol)));
|
||||
REQUIRE(ends_with(oss.str(), "0000: 090A0B410C4BFFFF" + std::string(spdlog::details::os::default_eol)));
|
||||
|
||||
oss_logger.info("{:Xsa}", spdlog::to_hex(v, 6));
|
||||
REQUIRE(ends_with(
|
||||
oss.str(), "0000: 090A0B410C4B ...A.K" + std::string(spdlog::details::os::default_eol) +
|
||||
"0006: FFFF .." + std::string(spdlog::details::os::default_eol)));
|
||||
REQUIRE(ends_with(oss.str(), "0000: 090A0B410C4B ...A.K" + std::string(spdlog::details::os::default_eol) +
|
||||
"0006: FFFF .." + std::string(spdlog::details::os::default_eol)));
|
||||
|
||||
oss_logger.info("{:Xs}", spdlog::to_hex(v, 6));
|
||||
REQUIRE(ends_with(oss.str(), "0000: 090A0B410C4B" +
|
||||
std::string(spdlog::details::os::default_eol) + "0006: FFFF" +
|
||||
REQUIRE(ends_with(oss.str(), "0000: 090A0B410C4B" + std::string(spdlog::details::os::default_eol) + "0006: FFFF" +
|
||||
std::string(spdlog::details::os::default_eol)));
|
||||
}
|
||||
|
||||
@ -88,11 +80,9 @@ TEST_CASE("to_hex_no_ascii", "[to_hex]") {
|
||||
std::vector<unsigned char> v{9, 0xa, 0xb, 0x41, 0xc, 0x4b, 0xff, 0xff};
|
||||
oss_logger.info("{:Xs}", spdlog::to_hex(v, 8));
|
||||
|
||||
REQUIRE(ends_with(oss.str(),
|
||||
"0000: 090A0B410C4BFFFF" + std::string(spdlog::details::os::default_eol)));
|
||||
REQUIRE(ends_with(oss.str(), "0000: 090A0B410C4BFFFF" + std::string(spdlog::details::os::default_eol)));
|
||||
|
||||
oss_logger.info("{:Xsna}", spdlog::to_hex(v, 8));
|
||||
|
||||
REQUIRE(
|
||||
ends_with(oss.str(), "090A0B410C4BFFFF" + std::string(spdlog::details::os::default_eol)));
|
||||
REQUIRE(ends_with(oss.str(), "090A0B410C4BFFFF" + std::string(spdlog::details::os::default_eol)));
|
||||
}
|
||||
|
@ -16,23 +16,19 @@ bool try_create_dir(const spdlog::filename_t &path, const spdlog::filename_t &no
|
||||
TEST_CASE("create_dir", "[create_dir]") {
|
||||
prepare_logdir();
|
||||
|
||||
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")));
|
||||
REQUIRE(try_create_dir(SPDLOG_FILENAME_T("test_logs/dir1/dir1"),
|
||||
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"),
|
||||
SPDLOG_FILENAME_T("test_logs/dir1/dir3")));
|
||||
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"), SPDLOG_FILENAME_T("test_logs/dir1/dir3")));
|
||||
REQUIRE(try_create_dir(SPDLOG_FILENAME_T("test_logs/../test_logs/dir1/dir4"),
|
||||
SPDLOG_FILENAME_T("test_logs/dir1/dir4")));
|
||||
|
||||
#ifdef WIN32
|
||||
// test backslash folder separator
|
||||
REQUIRE(try_create_dir(SPDLOG_FILENAME_T("test_logs\\dir1\\dir222"),
|
||||
SPDLOG_FILENAME_T("test_logs\\dir1\\dir222")));
|
||||
REQUIRE(try_create_dir(SPDLOG_FILENAME_T("test_logs\\dir1\\dir223\\"),
|
||||
SPDLOG_FILENAME_T("test_logs\\dir1\\dir223\\")));
|
||||
REQUIRE(try_create_dir(SPDLOG_FILENAME_T("test_logs\\dir1\\dir222"), SPDLOG_FILENAME_T("test_logs\\dir1\\dir222")));
|
||||
REQUIRE(
|
||||
try_create_dir(SPDLOG_FILENAME_T("test_logs\\dir1\\dir223\\"), SPDLOG_FILENAME_T("test_logs\\dir1\\dir223\\")));
|
||||
REQUIRE(try_create_dir(SPDLOG_FILENAME_T(".\\test_logs\\dir1\\dir2\\dir99\\..\\dir23"),
|
||||
SPDLOG_FILENAME_T("test_logs\\dir1\\dir2\\dir23")));
|
||||
REQUIRE(try_create_dir(SPDLOG_FILENAME_T("test_logs\\..\\test_logs\\dir1\\dir5"),
|
||||
@ -60,16 +56,13 @@ TEST_CASE("dir_name", "[create_dir]") {
|
||||
REQUIRE(dir_name(SPDLOG_FILENAME_T(R"(dir/file)")) == SPDLOG_FILENAME_T("dir"));
|
||||
REQUIRE(dir_name(SPDLOG_FILENAME_T(R"(dir\file.txt)")) == SPDLOG_FILENAME_T("dir"));
|
||||
REQUIRE(dir_name(SPDLOG_FILENAME_T(R"(dir/file)")) == SPDLOG_FILENAME_T("dir"));
|
||||
REQUIRE(dir_name(SPDLOG_FILENAME_T(R"(dir\file.txt\)")) ==
|
||||
SPDLOG_FILENAME_T(R"(dir\file.txt)"));
|
||||
REQUIRE(dir_name(SPDLOG_FILENAME_T(R"(dir\file.txt\)")) == SPDLOG_FILENAME_T(R"(dir\file.txt)"));
|
||||
REQUIRE(dir_name(SPDLOG_FILENAME_T(R"(\dir\file.txt)")) == SPDLOG_FILENAME_T(R"(\dir)"));
|
||||
REQUIRE(dir_name(SPDLOG_FILENAME_T(R"(\\dir\file.txt)")) == SPDLOG_FILENAME_T(R"(\\dir)"));
|
||||
REQUIRE(dir_name(SPDLOG_FILENAME_T(R"(..\file.txt)")) == SPDLOG_FILENAME_T(".."));
|
||||
REQUIRE(dir_name(SPDLOG_FILENAME_T(R"(.\file.txt)")) == SPDLOG_FILENAME_T("."));
|
||||
REQUIRE(dir_name(SPDLOG_FILENAME_T(R"(c:\\a\b\c\d\file.txt)")) ==
|
||||
SPDLOG_FILENAME_T(R"(c:\\a\b\c\d)"));
|
||||
REQUIRE(dir_name(SPDLOG_FILENAME_T(R"(c://a/b/c/d/file.txt)")) ==
|
||||
SPDLOG_FILENAME_T(R"(c://a/b/c/d)"));
|
||||
REQUIRE(dir_name(SPDLOG_FILENAME_T(R"(c:\\a\b\c\d\file.txt)")) == SPDLOG_FILENAME_T(R"(c:\\a\b\c\d)"));
|
||||
REQUIRE(dir_name(SPDLOG_FILENAME_T(R"(c://a/b/c/d/file.txt)")) == SPDLOG_FILENAME_T(R"(c://a/b/c/d)"));
|
||||
#endif
|
||||
REQUIRE(dir_name(SPDLOG_FILENAME_T("dir/")) == SPDLOG_FILENAME_T("dir"));
|
||||
REQUIRE(dir_name(SPDLOG_FILENAME_T("dir///")) == SPDLOG_FILENAME_T("dir//"));
|
||||
|
@ -11,13 +11,12 @@
|
||||
TEST_CASE("custom_callback_logger", "[custom_callback_logger]") {
|
||||
std::vector<std::string> lines;
|
||||
spdlog::pattern_formatter formatter;
|
||||
auto callback_logger =
|
||||
std::make_shared<spdlog::sinks::callback_sink_st>([&](const spdlog::details::log_msg &msg) {
|
||||
spdlog::memory_buf_t formatted;
|
||||
formatter.format(msg, formatted);
|
||||
auto eol_len = strlen(spdlog::details::os::default_eol);
|
||||
lines.emplace_back(formatted.begin(), formatted.end() - eol_len);
|
||||
});
|
||||
auto callback_logger = std::make_shared<spdlog::sinks::callback_sink_st>([&](const spdlog::details::log_msg &msg) {
|
||||
spdlog::memory_buf_t formatted;
|
||||
formatter.format(msg, formatted);
|
||||
auto eol_len = strlen(spdlog::details::os::default_eol);
|
||||
lines.emplace_back(formatted.begin(), formatted.end() - eol_len);
|
||||
});
|
||||
std::shared_ptr<spdlog::sinks::test_sink_st> test_sink(new spdlog::sinks::test_sink_st);
|
||||
|
||||
spdlog::logger logger("test-callback", {callback_logger, test_sink});
|
||||
|
@ -19,14 +19,11 @@ std::string filename_buf_to_utf8string(const filename_memory_buf_t &w) {
|
||||
return SPDLOG_BUF_TO_STRING(buf);
|
||||
}
|
||||
#else
|
||||
std::string filename_buf_to_utf8string(const filename_memory_buf_t &w) {
|
||||
return SPDLOG_BUF_TO_STRING(w);
|
||||
}
|
||||
std::string filename_buf_to_utf8string(const filename_memory_buf_t &w) { return SPDLOG_BUF_TO_STRING(w); }
|
||||
#endif
|
||||
|
||||
TEST_CASE("daily_logger with dateonly calculator", "[daily_logger]") {
|
||||
using sink_type =
|
||||
spdlog::sinks::daily_file_sink<std::mutex, spdlog::sinks::daily_filename_calculator>;
|
||||
using sink_type = spdlog::sinks::daily_file_sink<std::mutex, spdlog::sinks::daily_filename_calculator>;
|
||||
|
||||
prepare_logdir();
|
||||
|
||||
@ -34,8 +31,8 @@ TEST_CASE("daily_logger with dateonly calculator", "[daily_logger]") {
|
||||
spdlog::filename_t basename = SPDLOG_FILENAME_T("test_logs/daily_dateonly");
|
||||
std::tm tm = spdlog::details::os::localtime();
|
||||
filename_memory_buf_t w;
|
||||
spdlog::fmt_lib::format_to(std::back_inserter(w), SPDLOG_FILENAME_T("{}_{:04d}-{:02d}-{:02d}"),
|
||||
basename, tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday);
|
||||
spdlog::fmt_lib::format_to(std::back_inserter(w), SPDLOG_FILENAME_T("{}_{:04d}-{:02d}-{:02d}"), basename,
|
||||
tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday);
|
||||
|
||||
auto logger = spdlog::create<sink_type>("logger", basename, 0, 0);
|
||||
for (int i = 0; i < 10; ++i) {
|
||||
@ -49,9 +46,8 @@ TEST_CASE("daily_logger with dateonly calculator", "[daily_logger]") {
|
||||
struct custom_daily_file_name_calculator {
|
||||
static spdlog::filename_t calc_filename(const spdlog::filename_t &basename, const tm &now_tm) {
|
||||
filename_memory_buf_t w;
|
||||
spdlog::fmt_lib::format_to(std::back_inserter(w), SPDLOG_FILENAME_T("{}{:04d}{:02d}{:02d}"),
|
||||
basename, now_tm.tm_year + 1900, now_tm.tm_mon + 1,
|
||||
now_tm.tm_mday);
|
||||
spdlog::fmt_lib::format_to(std::back_inserter(w), SPDLOG_FILENAME_T("{}{:04d}{:02d}{:02d}"), basename,
|
||||
now_tm.tm_year + 1900, now_tm.tm_mon + 1, now_tm.tm_mday);
|
||||
|
||||
return SPDLOG_BUF_TO_STRING(w);
|
||||
}
|
||||
@ -66,8 +62,8 @@ TEST_CASE("daily_logger with custom calculator", "[daily_logger]") {
|
||||
spdlog::filename_t basename = SPDLOG_FILENAME_T("test_logs/daily_dateonly");
|
||||
std::tm tm = spdlog::details::os::localtime();
|
||||
filename_memory_buf_t w;
|
||||
spdlog::fmt_lib::format_to(std::back_inserter(w), SPDLOG_FILENAME_T("{}{:04d}{:02d}{:02d}"),
|
||||
basename, tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday);
|
||||
spdlog::fmt_lib::format_to(std::back_inserter(w), SPDLOG_FILENAME_T("{}{:04d}{:02d}{:02d}"), basename,
|
||||
tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday);
|
||||
|
||||
auto logger = spdlog::create<sink_type>("logger", basename, 0, 0);
|
||||
for (int i = 0; i < 10; ++i) {
|
||||
@ -83,20 +79,17 @@ TEST_CASE("daily_logger with custom calculator", "[daily_logger]") {
|
||||
*/
|
||||
|
||||
TEST_CASE("rotating_file_sink::calc_filename1", "[rotating_file_sink]") {
|
||||
auto filename =
|
||||
spdlog::sinks::rotating_file_sink_st::calc_filename(SPDLOG_FILENAME_T("rotated.txt"), 3);
|
||||
auto filename = spdlog::sinks::rotating_file_sink_st::calc_filename(SPDLOG_FILENAME_T("rotated.txt"), 3);
|
||||
REQUIRE(filename == SPDLOG_FILENAME_T("rotated.3.txt"));
|
||||
}
|
||||
|
||||
TEST_CASE("rotating_file_sink::calc_filename2", "[rotating_file_sink]") {
|
||||
auto filename =
|
||||
spdlog::sinks::rotating_file_sink_st::calc_filename(SPDLOG_FILENAME_T("rotated"), 3);
|
||||
auto filename = spdlog::sinks::rotating_file_sink_st::calc_filename(SPDLOG_FILENAME_T("rotated"), 3);
|
||||
REQUIRE(filename == SPDLOG_FILENAME_T("rotated.3"));
|
||||
}
|
||||
|
||||
TEST_CASE("rotating_file_sink::calc_filename3", "[rotating_file_sink]") {
|
||||
auto filename =
|
||||
spdlog::sinks::rotating_file_sink_st::calc_filename(SPDLOG_FILENAME_T("rotated.txt"), 0);
|
||||
auto filename = spdlog::sinks::rotating_file_sink_st::calc_filename(SPDLOG_FILENAME_T("rotated.txt"), 0);
|
||||
REQUIRE(filename == SPDLOG_FILENAME_T("rotated.txt"));
|
||||
}
|
||||
|
||||
@ -107,8 +100,8 @@ TEST_CASE("rotating_file_sink::calc_filename3", "[rotating_file_sink]") {
|
||||
|
||||
TEST_CASE("daily_file_sink::daily_filename_calculator", "[daily_file_sink]") {
|
||||
// daily_YYYY-MM-DD_hh-mm.txt
|
||||
auto filename = spdlog::sinks::daily_filename_calculator::calc_filename(
|
||||
SPDLOG_FILENAME_T("daily.txt"), spdlog::details::os::localtime());
|
||||
auto filename = spdlog::sinks::daily_filename_calculator::calc_filename(SPDLOG_FILENAME_T("daily.txt"),
|
||||
spdlog::details::os::localtime());
|
||||
// date regex based on https://www.regular-expressions.info/dates.html
|
||||
std::basic_regex<spdlog::filename_t::value_type> re(
|
||||
SPDLOG_FILENAME_T(R"(^daily_(19|20)\d\d-(0[1-9]|1[012])-(0[1-9]|[12][0-9]|3[01])\.txt$)"));
|
||||
@ -120,12 +113,11 @@ TEST_CASE("daily_file_sink::daily_filename_calculator", "[daily_file_sink]") {
|
||||
TEST_CASE("daily_file_sink::daily_filename_format_calculator", "[daily_file_sink]") {
|
||||
std::tm tm = spdlog::details::os::localtime();
|
||||
// example-YYYY-MM-DD.log
|
||||
auto filename = spdlog::sinks::daily_filename_format_calculator::calc_filename(
|
||||
SPDLOG_FILENAME_T("example-%Y-%m-%d.log"), tm);
|
||||
auto filename =
|
||||
spdlog::sinks::daily_filename_format_calculator::calc_filename(SPDLOG_FILENAME_T("example-%Y-%m-%d.log"), tm);
|
||||
|
||||
REQUIRE(filename ==
|
||||
spdlog::fmt_lib::format(SPDLOG_FILENAME_T("example-{:04d}-{:02d}-{:02d}.log"),
|
||||
tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday));
|
||||
REQUIRE(filename == spdlog::fmt_lib::format(SPDLOG_FILENAME_T("example-{:04d}-{:02d}-{:02d}.log"),
|
||||
tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday));
|
||||
}
|
||||
|
||||
/* Test removal of old files */
|
||||
|
@ -77,7 +77,6 @@ TEST_CASE("dup_filter_test5", "[dup_filter_sink]") {
|
||||
dup_sink.log(spdlog::details::log_msg{"test", spdlog::level::info, "message1"});
|
||||
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
|
||||
REQUIRE(test_sink->msg_counter() == 3); // skip 2 messages but log the "skipped.." message before message2
|
||||
REQUIRE(test_sink->lines()[1] == "Skipped 2 duplicate messages..");
|
||||
}
|
||||
|
@ -71,8 +71,7 @@ TEST_CASE("async_error_handler", "[errors]") {
|
||||
spdlog::filename_t filename = SPDLOG_FILENAME_T(SIMPLE_ASYNC_LOG);
|
||||
{
|
||||
spdlog::init_thread_pool(128, 1);
|
||||
auto logger =
|
||||
spdlog::create_async<spdlog::sinks::basic_file_sink_mt>("logger", filename, true);
|
||||
auto logger = spdlog::create_async<spdlog::sinks::basic_file_sink_mt>("logger", filename, true);
|
||||
logger->set_error_handler([=](const std::string &) {
|
||||
std::ofstream ofs("test_logs/custom_err.txt");
|
||||
if (!ofs) {
|
||||
|
@ -10,8 +10,7 @@ static void test_single_print(std::function<void(std::string const &)> do_log,
|
||||
WORD expected_ev_type) {
|
||||
using namespace std::chrono;
|
||||
do_log(expected_contents);
|
||||
const auto expected_time_generated =
|
||||
duration_cast<seconds>(system_clock::now().time_since_epoch()).count();
|
||||
const auto expected_time_generated = duration_cast<seconds>(system_clock::now().time_since_epoch()).count();
|
||||
|
||||
struct handle_t {
|
||||
HANDLE handle_;
|
||||
@ -26,16 +25,16 @@ static void test_single_print(std::function<void(std::string const &)> do_log,
|
||||
REQUIRE(event_log.handle_);
|
||||
|
||||
DWORD read_bytes{}, size_needed{};
|
||||
auto ok = ::ReadEventLogA(event_log.handle_, EVENTLOG_SEQUENTIAL_READ | EVENTLOG_BACKWARDS_READ,
|
||||
0, &read_bytes, 0, &read_bytes, &size_needed);
|
||||
auto ok = ::ReadEventLogA(event_log.handle_, EVENTLOG_SEQUENTIAL_READ | EVENTLOG_BACKWARDS_READ, 0, &read_bytes, 0,
|
||||
&read_bytes, &size_needed);
|
||||
REQUIRE(!ok);
|
||||
REQUIRE(::GetLastError() == ERROR_INSUFFICIENT_BUFFER);
|
||||
|
||||
std::vector<char> record_buffer(size_needed);
|
||||
PEVENTLOGRECORD record = (PEVENTLOGRECORD)record_buffer.data();
|
||||
|
||||
ok = ::ReadEventLogA(event_log.handle_, EVENTLOG_SEQUENTIAL_READ | EVENTLOG_BACKWARDS_READ, 0,
|
||||
record, size_needed, &read_bytes, &size_needed);
|
||||
ok = ::ReadEventLogA(event_log.handle_, EVENTLOG_SEQUENTIAL_READ | EVENTLOG_BACKWARDS_READ, 0, record, size_needed,
|
||||
&read_bytes, &size_needed);
|
||||
REQUIRE(ok);
|
||||
|
||||
REQUIRE(record->NumStrings == 1);
|
||||
@ -56,16 +55,16 @@ TEST_CASE("eventlog", "[eventlog]") {
|
||||
|
||||
test_sink->set_pattern("%v");
|
||||
|
||||
test_single_print([&test_logger](std::string const &msg) { test_logger.trace(msg); },
|
||||
"my trace message", EVENTLOG_SUCCESS);
|
||||
test_single_print([&test_logger](std::string const &msg) { test_logger.debug(msg); },
|
||||
"my debug message", EVENTLOG_SUCCESS);
|
||||
test_single_print([&test_logger](std::string const &msg) { test_logger.info(msg); },
|
||||
"my info message", EVENTLOG_INFORMATION_TYPE);
|
||||
test_single_print([&test_logger](std::string const &msg) { test_logger.warn(msg); },
|
||||
"my warn message", EVENTLOG_WARNING_TYPE);
|
||||
test_single_print([&test_logger](std::string const &msg) { test_logger.error(msg); },
|
||||
"my error message", EVENTLOG_ERROR_TYPE);
|
||||
test_single_print([&test_logger](std::string const &msg) { test_logger.critical(msg); },
|
||||
"my critical message", EVENTLOG_ERROR_TYPE);
|
||||
test_single_print([&test_logger](std::string const &msg) { test_logger.trace(msg); }, "my trace message",
|
||||
EVENTLOG_SUCCESS);
|
||||
test_single_print([&test_logger](std::string const &msg) { test_logger.debug(msg); }, "my debug message",
|
||||
EVENTLOG_SUCCESS);
|
||||
test_single_print([&test_logger](std::string const &msg) { test_logger.info(msg); }, "my info message",
|
||||
EVENTLOG_INFORMATION_TYPE);
|
||||
test_single_print([&test_logger](std::string const &msg) { test_logger.warn(msg); }, "my warn message",
|
||||
EVENTLOG_WARNING_TYPE);
|
||||
test_single_print([&test_logger](std::string const &msg) { test_logger.error(msg); }, "my error message",
|
||||
EVENTLOG_ERROR_TYPE);
|
||||
test_single_print([&test_logger](std::string const &msg) { test_logger.critical(msg); }, "my critical message",
|
||||
EVENTLOG_ERROR_TYPE);
|
||||
}
|
||||
|
@ -76,35 +76,28 @@ static void test_split_ext(const spdlog::filename_t::value_type *fname,
|
||||
}
|
||||
|
||||
TEST_CASE("file_helper_split_by_extension", "[file_helper::split_by_extension()]") {
|
||||
test_split_ext(SPDLOG_FILENAME_T("mylog.txt"), SPDLOG_FILENAME_T("mylog"),
|
||||
SPDLOG_FILENAME_T(".txt"));
|
||||
test_split_ext(SPDLOG_FILENAME_T(".mylog.txt"), SPDLOG_FILENAME_T(".mylog"),
|
||||
SPDLOG_FILENAME_T(".txt"));
|
||||
test_split_ext(SPDLOG_FILENAME_T("mylog.txt"), SPDLOG_FILENAME_T("mylog"), SPDLOG_FILENAME_T(".txt"));
|
||||
test_split_ext(SPDLOG_FILENAME_T(".mylog.txt"), SPDLOG_FILENAME_T(".mylog"), SPDLOG_FILENAME_T(".txt"));
|
||||
test_split_ext(SPDLOG_FILENAME_T(".mylog"), SPDLOG_FILENAME_T(".mylog"), SPDLOG_FILENAME_T(""));
|
||||
test_split_ext(SPDLOG_FILENAME_T("/aaa/bb.d/mylog"), SPDLOG_FILENAME_T("/aaa/bb.d/mylog"),
|
||||
SPDLOG_FILENAME_T(""));
|
||||
test_split_ext(SPDLOG_FILENAME_T("/aaa/bb.d/mylog"), SPDLOG_FILENAME_T("/aaa/bb.d/mylog"), SPDLOG_FILENAME_T(""));
|
||||
test_split_ext(SPDLOG_FILENAME_T("/aaa/bb.d/mylog.txt"), SPDLOG_FILENAME_T("/aaa/bb.d/mylog"),
|
||||
SPDLOG_FILENAME_T(".txt"));
|
||||
test_split_ext(SPDLOG_FILENAME_T("aaa/bbb/ccc/mylog.txt"),
|
||||
SPDLOG_FILENAME_T("aaa/bbb/ccc/mylog"), SPDLOG_FILENAME_T(".txt"));
|
||||
test_split_ext(SPDLOG_FILENAME_T("aaa/bbb/ccc/mylog.txt"), SPDLOG_FILENAME_T("aaa/bbb/ccc/mylog"),
|
||||
SPDLOG_FILENAME_T(".txt"));
|
||||
test_split_ext(SPDLOG_FILENAME_T("aaa/bbb/ccc/mylog."), SPDLOG_FILENAME_T("aaa/bbb/ccc/mylog."),
|
||||
SPDLOG_FILENAME_T(""));
|
||||
test_split_ext(SPDLOG_FILENAME_T("aaa/bbb/ccc/.mylog.txt"),
|
||||
SPDLOG_FILENAME_T("aaa/bbb/ccc/.mylog"), SPDLOG_FILENAME_T(".txt"));
|
||||
test_split_ext(SPDLOG_FILENAME_T("/aaa/bbb/ccc/mylog.txt"),
|
||||
SPDLOG_FILENAME_T("/aaa/bbb/ccc/mylog"), SPDLOG_FILENAME_T(".txt"));
|
||||
test_split_ext(SPDLOG_FILENAME_T("/aaa/bbb/ccc/.mylog"),
|
||||
SPDLOG_FILENAME_T("/aaa/bbb/ccc/.mylog"), SPDLOG_FILENAME_T(""));
|
||||
test_split_ext(SPDLOG_FILENAME_T("../mylog.txt"), SPDLOG_FILENAME_T("../mylog"),
|
||||
test_split_ext(SPDLOG_FILENAME_T("aaa/bbb/ccc/.mylog.txt"), SPDLOG_FILENAME_T("aaa/bbb/ccc/.mylog"),
|
||||
SPDLOG_FILENAME_T(".txt"));
|
||||
test_split_ext(SPDLOG_FILENAME_T(".././mylog.txt"), SPDLOG_FILENAME_T(".././mylog"),
|
||||
test_split_ext(SPDLOG_FILENAME_T("/aaa/bbb/ccc/mylog.txt"), SPDLOG_FILENAME_T("/aaa/bbb/ccc/mylog"),
|
||||
SPDLOG_FILENAME_T(".txt"));
|
||||
test_split_ext(SPDLOG_FILENAME_T("/aaa/bbb/ccc/.mylog"), SPDLOG_FILENAME_T("/aaa/bbb/ccc/.mylog"),
|
||||
SPDLOG_FILENAME_T(""));
|
||||
test_split_ext(SPDLOG_FILENAME_T("../mylog.txt"), SPDLOG_FILENAME_T("../mylog"), SPDLOG_FILENAME_T(".txt"));
|
||||
test_split_ext(SPDLOG_FILENAME_T(".././mylog.txt"), SPDLOG_FILENAME_T(".././mylog"), SPDLOG_FILENAME_T(".txt"));
|
||||
test_split_ext(SPDLOG_FILENAME_T(".././mylog.txt/xxx"), SPDLOG_FILENAME_T(".././mylog.txt/xxx"),
|
||||
SPDLOG_FILENAME_T(""));
|
||||
test_split_ext(SPDLOG_FILENAME_T("/mylog.txt"), SPDLOG_FILENAME_T("/mylog"),
|
||||
SPDLOG_FILENAME_T(".txt"));
|
||||
test_split_ext(SPDLOG_FILENAME_T("//mylog.txt"), SPDLOG_FILENAME_T("//mylog"),
|
||||
SPDLOG_FILENAME_T(".txt"));
|
||||
test_split_ext(SPDLOG_FILENAME_T("/mylog.txt"), SPDLOG_FILENAME_T("/mylog"), SPDLOG_FILENAME_T(".txt"));
|
||||
test_split_ext(SPDLOG_FILENAME_T("//mylog.txt"), SPDLOG_FILENAME_T("//mylog"), SPDLOG_FILENAME_T(".txt"));
|
||||
test_split_ext(SPDLOG_FILENAME_T(""), SPDLOG_FILENAME_T(""), SPDLOG_FILENAME_T(""));
|
||||
test_split_ext(SPDLOG_FILENAME_T("."), SPDLOG_FILENAME_T("."), SPDLOG_FILENAME_T(""));
|
||||
test_split_ext(SPDLOG_FILENAME_T("..txt"), SPDLOG_FILENAME_T("."), SPDLOG_FILENAME_T(".txt"));
|
||||
|
@ -43,8 +43,8 @@ TEST_CASE("flush_on", "[flush_on]") {
|
||||
require_message_count(SIMPLE_LOG, 3);
|
||||
using spdlog::details::os::default_eol;
|
||||
REQUIRE(file_contents(SIMPLE_LOG) ==
|
||||
spdlog::fmt_lib::format("Should not be flushed{}Test message 1{}Test message 2{}",
|
||||
default_eol, default_eol, default_eol));
|
||||
spdlog::fmt_lib::format("Should not be flushed{}Test message 1{}Test message 2{}", default_eol, default_eol,
|
||||
default_eol));
|
||||
}
|
||||
|
||||
TEST_CASE("rotating_file_logger1", "[rotating_logger]") {
|
||||
@ -100,6 +100,5 @@ TEST_CASE("rotating_file_logger3", "[rotating_logger]") {
|
||||
prepare_logdir();
|
||||
size_t max_size = 0;
|
||||
spdlog::filename_t basename = SPDLOG_FILENAME_T(ROTATING_LOG);
|
||||
REQUIRE_THROWS_AS(spdlog::rotating_logger_mt("logger", basename, max_size, 0),
|
||||
spdlog::spdlog_ex);
|
||||
REQUIRE_THROWS_AS(spdlog::rotating_logger_mt("logger", basename, max_size, 0), spdlog::spdlog_ex);
|
||||
}
|
||||
|
@ -38,10 +38,8 @@ auto get_expected_messages(spdlog::level level) {
|
||||
// expected messages for each level
|
||||
static const std::map<spdlog::level, std::vector<std::string>> messages = {
|
||||
{spdlog::level::trace,
|
||||
{"trace hello", "debug hello", "info hello", "warning hello", "error hello",
|
||||
"critical hello"}},
|
||||
{spdlog::level::debug,
|
||||
{"debug hello", "info hello", "warning hello", "error hello", "critical hello"}},
|
||||
{"trace hello", "debug hello", "info hello", "warning hello", "error hello", "critical hello"}},
|
||||
{spdlog::level::debug, {"debug hello", "info hello", "warning hello", "error hello", "critical hello"}},
|
||||
{spdlog::level::info, {"info hello", "warning hello", "error hello", "critical hello"}},
|
||||
{spdlog::level::warn, {"warning hello", "error hello", "critical hello"}},
|
||||
{spdlog::level::err, {"error hello", "critical hello"}},
|
||||
|
@ -25,8 +25,7 @@ TEST_CASE("debug and trace w/o format string", "[macros]") {
|
||||
logger->flush();
|
||||
|
||||
using spdlog::details::os::default_eol;
|
||||
REQUIRE(ends_with(file_contents(TEST_FILENAME),
|
||||
spdlog::fmt_lib::format("Test message 2{}", default_eol)));
|
||||
REQUIRE(ends_with(file_contents(TEST_FILENAME), spdlog::fmt_lib::format("Test message 2{}", default_eol)));
|
||||
REQUIRE(count_lines(TEST_FILENAME) == 1);
|
||||
|
||||
auto orig_default_logger = spdlog::default_logger();
|
||||
@ -37,8 +36,7 @@ TEST_CASE("debug and trace w/o format string", "[macros]") {
|
||||
logger->flush();
|
||||
|
||||
require_message_count(TEST_FILENAME, 2);
|
||||
REQUIRE(ends_with(file_contents(TEST_FILENAME),
|
||||
spdlog::fmt_lib::format("Test message 4{}", default_eol)));
|
||||
REQUIRE(ends_with(file_contents(TEST_FILENAME), spdlog::fmt_lib::format("Test message 4{}", default_eol)));
|
||||
spdlog::set_default_logger(std::move(orig_default_logger));
|
||||
}
|
||||
|
||||
|
@ -13,8 +13,7 @@ static std::string log_to_str(const std::string &msg, const Args &...args) {
|
||||
spdlog::logger oss_logger("pattern_tester", oss_sink);
|
||||
oss_logger.set_level(spdlog::level::info);
|
||||
|
||||
oss_logger.set_formatter(
|
||||
std::unique_ptr<spdlog::formatter>(new spdlog::pattern_formatter(args...)));
|
||||
oss_logger.set_formatter(std::unique_ptr<spdlog::formatter>(new spdlog::pattern_formatter(args...)));
|
||||
|
||||
oss_logger.info(msg);
|
||||
return oss.str();
|
||||
@ -35,13 +34,11 @@ TEST_CASE("empty format2", "[pattern_formatter]") {
|
||||
}
|
||||
|
||||
TEST_CASE("level", "[pattern_formatter]") {
|
||||
REQUIRE(log_to_str("Some message", "[%l] %v", spdlog::pattern_time_type::local, "\n") ==
|
||||
"[info] Some message\n");
|
||||
REQUIRE(log_to_str("Some message", "[%l] %v", spdlog::pattern_time_type::local, "\n") == "[info] Some message\n");
|
||||
}
|
||||
|
||||
TEST_CASE("short level", "[pattern_formatter]") {
|
||||
REQUIRE(log_to_str("Some message", "[%L] %v", spdlog::pattern_time_type::local, "\n") ==
|
||||
"[I] Some message\n");
|
||||
REQUIRE(log_to_str("Some message", "[%L] %v", spdlog::pattern_time_type::local, "\n") == "[I] Some message\n");
|
||||
}
|
||||
|
||||
TEST_CASE("name", "[pattern_formatter]") {
|
||||
@ -52,23 +49,19 @@ TEST_CASE("name", "[pattern_formatter]") {
|
||||
TEST_CASE("date MM/DD/YY ", "[pattern_formatter]") {
|
||||
auto now_tm = spdlog::details::os::localtime();
|
||||
std::stringstream oss;
|
||||
oss << std::setfill('0') << std::setw(2) << now_tm.tm_mon + 1 << "/" << std::setw(2)
|
||||
<< now_tm.tm_mday << "/" << std::setw(2) << (now_tm.tm_year + 1900) % 1000
|
||||
<< " Some message\n";
|
||||
REQUIRE(log_to_str("Some message", "%D %v", spdlog::pattern_time_type::local, "\n") ==
|
||||
oss.str());
|
||||
oss << std::setfill('0') << std::setw(2) << now_tm.tm_mon + 1 << "/" << std::setw(2) << now_tm.tm_mday << "/"
|
||||
<< std::setw(2) << (now_tm.tm_year + 1900) % 1000 << " Some message\n";
|
||||
REQUIRE(log_to_str("Some message", "%D %v", spdlog::pattern_time_type::local, "\n") == oss.str());
|
||||
}
|
||||
|
||||
TEST_CASE("color range test1", "[pattern_formatter]") {
|
||||
auto formatter = std::make_shared<spdlog::pattern_formatter>(
|
||||
"%^%v%$", spdlog::pattern_time_type::local, "\n");
|
||||
auto formatter = std::make_shared<spdlog::pattern_formatter>("%^%v%$", spdlog::pattern_time_type::local, "\n");
|
||||
|
||||
memory_buf_t buf;
|
||||
spdlog::fmt_lib::format_to(std::back_inserter(buf), "Hello");
|
||||
memory_buf_t formatted;
|
||||
std::string logger_name = "test";
|
||||
spdlog::details::log_msg msg(logger_name, spdlog::level::info,
|
||||
spdlog::string_view_t(buf.data(), buf.size()));
|
||||
spdlog::details::log_msg msg(logger_name, spdlog::level::info, spdlog::string_view_t(buf.data(), buf.size()));
|
||||
formatter->format(msg, formatted);
|
||||
REQUIRE(msg.color_range_start == 0);
|
||||
REQUIRE(msg.color_range_end == 5);
|
||||
@ -76,8 +69,7 @@ TEST_CASE("color range test1", "[pattern_formatter]") {
|
||||
}
|
||||
|
||||
TEST_CASE("color range test2", "[pattern_formatter]") {
|
||||
auto formatter =
|
||||
std::make_shared<spdlog::pattern_formatter>("%^%$", spdlog::pattern_time_type::local, "\n");
|
||||
auto formatter = std::make_shared<spdlog::pattern_formatter>("%^%$", spdlog::pattern_time_type::local, "\n");
|
||||
std::string logger_name = "test";
|
||||
spdlog::details::log_msg msg(logger_name, spdlog::level::info, "");
|
||||
memory_buf_t formatted;
|
||||
@ -98,8 +90,7 @@ TEST_CASE("color range test3", "[pattern_formatter]") {
|
||||
}
|
||||
|
||||
TEST_CASE("color range test4", "[pattern_formatter]") {
|
||||
auto formatter = std::make_shared<spdlog::pattern_formatter>(
|
||||
"XX%^YYY%$", spdlog::pattern_time_type::local, "\n");
|
||||
auto formatter = std::make_shared<spdlog::pattern_formatter>("XX%^YYY%$", spdlog::pattern_time_type::local, "\n");
|
||||
std::string logger_name = "test";
|
||||
spdlog::details::log_msg msg(logger_name, spdlog::level::info, "ignored");
|
||||
|
||||
@ -107,8 +98,7 @@ TEST_CASE("color range test4", "[pattern_formatter]") {
|
||||
formatter->format(msg, formatted);
|
||||
REQUIRE(msg.color_range_start == 2);
|
||||
REQUIRE(msg.color_range_end == 5);
|
||||
REQUIRE(log_to_str("ignored", "XX%^YYY%$", spdlog::pattern_time_type::local, "\n") ==
|
||||
"XXYYY\n");
|
||||
REQUIRE(log_to_str("ignored", "XX%^YYY%$", spdlog::pattern_time_type::local, "\n") == "XXYYY\n");
|
||||
}
|
||||
|
||||
TEST_CASE("color range test5", "[pattern_formatter]") {
|
||||
@ -157,45 +147,36 @@ TEST_CASE("level_center_padded", "[pattern_formatter]") {
|
||||
}
|
||||
|
||||
TEST_CASE("short level_left_padded", "[pattern_formatter]") {
|
||||
REQUIRE(log_to_str("Some message", "[%3L] %v", spdlog::pattern_time_type::local, "\n") ==
|
||||
"[ I] Some message\n");
|
||||
REQUIRE(log_to_str("Some message", "[%3!L] %v", spdlog::pattern_time_type::local, "\n") ==
|
||||
"[ I] Some message\n");
|
||||
REQUIRE(log_to_str("Some message", "[%3L] %v", spdlog::pattern_time_type::local, "\n") == "[ I] Some message\n");
|
||||
REQUIRE(log_to_str("Some message", "[%3!L] %v", spdlog::pattern_time_type::local, "\n") == "[ I] Some message\n");
|
||||
}
|
||||
|
||||
TEST_CASE("short level_right_padded", "[pattern_formatter]") {
|
||||
REQUIRE(log_to_str("Some message", "[%-3L] %v", spdlog::pattern_time_type::local, "\n") ==
|
||||
"[I ] Some message\n");
|
||||
REQUIRE(log_to_str("Some message", "[%-3!L] %v", spdlog::pattern_time_type::local, "\n") ==
|
||||
"[I ] Some message\n");
|
||||
REQUIRE(log_to_str("Some message", "[%-3L] %v", spdlog::pattern_time_type::local, "\n") == "[I ] Some message\n");
|
||||
REQUIRE(log_to_str("Some message", "[%-3!L] %v", spdlog::pattern_time_type::local, "\n") == "[I ] Some message\n");
|
||||
}
|
||||
|
||||
TEST_CASE("short level_center_padded", "[pattern_formatter]") {
|
||||
REQUIRE(log_to_str("Some message", "[%=3L] %v", spdlog::pattern_time_type::local, "\n") ==
|
||||
"[ I ] Some message\n");
|
||||
REQUIRE(log_to_str("Some message", "[%=3!L] %v", spdlog::pattern_time_type::local, "\n") ==
|
||||
"[ I ] Some message\n");
|
||||
REQUIRE(log_to_str("Some message", "[%=3L] %v", spdlog::pattern_time_type::local, "\n") == "[ I ] Some message\n");
|
||||
REQUIRE(log_to_str("Some message", "[%=3!L] %v", spdlog::pattern_time_type::local, "\n") == "[ I ] Some message\n");
|
||||
}
|
||||
|
||||
TEST_CASE("left_padded_short", "[pattern_formatter]") {
|
||||
REQUIRE(log_to_str("Some message", "[%3n] %v", spdlog::pattern_time_type::local, "\n") ==
|
||||
"[pattern_tester] Some message\n");
|
||||
REQUIRE(log_to_str("Some message", "[%3!n] %v", spdlog::pattern_time_type::local, "\n") ==
|
||||
"[pat] Some message\n");
|
||||
REQUIRE(log_to_str("Some message", "[%3!n] %v", spdlog::pattern_time_type::local, "\n") == "[pat] Some message\n");
|
||||
}
|
||||
|
||||
TEST_CASE("right_padded_short", "[pattern_formatter]") {
|
||||
REQUIRE(log_to_str("Some message", "[%-3n] %v", spdlog::pattern_time_type::local, "\n") ==
|
||||
"[pattern_tester] Some message\n");
|
||||
REQUIRE(log_to_str("Some message", "[%-3!n] %v", spdlog::pattern_time_type::local, "\n") ==
|
||||
"[pat] Some message\n");
|
||||
REQUIRE(log_to_str("Some message", "[%-3!n] %v", spdlog::pattern_time_type::local, "\n") == "[pat] Some message\n");
|
||||
}
|
||||
|
||||
TEST_CASE("center_padded_short", "[pattern_formatter]") {
|
||||
REQUIRE(log_to_str("Some message", "[%=3n] %v", spdlog::pattern_time_type::local, "\n") ==
|
||||
"[pattern_tester] Some message\n");
|
||||
REQUIRE(log_to_str("Some message", "[%=3!n] %v", spdlog::pattern_time_type::local, "\n") ==
|
||||
"[pat] Some message\n");
|
||||
REQUIRE(log_to_str("Some message", "[%=3!n] %v", spdlog::pattern_time_type::local, "\n") == "[pat] Some message\n");
|
||||
}
|
||||
|
||||
TEST_CASE("left_padded_huge", "[pattern_formatter]") {
|
||||
@ -239,13 +220,13 @@ TEST_CASE("padding_truncate_funcname", "[pattern_formatter]") {
|
||||
auto formatter = std::unique_ptr<spdlog::formatter>(new spdlog::pattern_formatter(pattern));
|
||||
test_sink.set_formatter(std::move(formatter));
|
||||
|
||||
spdlog::details::log_msg msg1{spdlog::source_loc{"ignored", 1, "func"}, "test_logger",
|
||||
spdlog::level::info, "message"};
|
||||
spdlog::details::log_msg msg1{spdlog::source_loc{"ignored", 1, "func"}, "test_logger", spdlog::level::info,
|
||||
"message"};
|
||||
test_sink.log(msg1);
|
||||
REQUIRE(test_sink.lines()[0] == "message [ func]");
|
||||
|
||||
spdlog::details::log_msg msg2{spdlog::source_loc{"ignored", 1, "function"}, "test_logger",
|
||||
spdlog::level::info, "message"};
|
||||
spdlog::details::log_msg msg2{spdlog::source_loc{"ignored", 1, "function"}, "test_logger", spdlog::level::info,
|
||||
"message"};
|
||||
test_sink.log(msg2);
|
||||
REQUIRE(test_sink.lines()[1] == "message [funct]");
|
||||
}
|
||||
@ -257,13 +238,13 @@ TEST_CASE("padding_funcname", "[pattern_formatter]") {
|
||||
auto formatter = std::unique_ptr<spdlog::formatter>(new spdlog::pattern_formatter(pattern));
|
||||
test_sink.set_formatter(std::move(formatter));
|
||||
|
||||
spdlog::details::log_msg msg1{spdlog::source_loc{"ignored", 1, "func"}, "test_logger",
|
||||
spdlog::level::info, "message"};
|
||||
spdlog::details::log_msg msg1{spdlog::source_loc{"ignored", 1, "func"}, "test_logger", spdlog::level::info,
|
||||
"message"};
|
||||
test_sink.log(msg1);
|
||||
REQUIRE(test_sink.lines()[0] == "message [ func]");
|
||||
|
||||
spdlog::details::log_msg msg2{spdlog::source_loc{"ignored", 1, "func567890123"}, "test_logger",
|
||||
spdlog::level::info, "message"};
|
||||
spdlog::details::log_msg msg2{spdlog::source_loc{"ignored", 1, "func567890123"}, "test_logger", spdlog::level::info,
|
||||
"message"};
|
||||
test_sink.log(msg2);
|
||||
REQUIRE(test_sink.lines()[1] == "message [func567890123]");
|
||||
}
|
||||
@ -312,8 +293,8 @@ TEST_CASE("clone-formatter", "[pattern_formatter]") {
|
||||
|
||||
TEST_CASE("clone-formatter-2", "[pattern_formatter]") {
|
||||
using spdlog::pattern_time_type;
|
||||
auto formatter_1 = std::make_shared<spdlog::pattern_formatter>(
|
||||
"%D %X [%] [%n] %v", pattern_time_type::utc, "xxxxxx\n");
|
||||
auto formatter_1 =
|
||||
std::make_shared<spdlog::pattern_formatter>("%D %X [%] [%n] %v", pattern_time_type::utc, "xxxxxx\n");
|
||||
auto formatter_2 = formatter_1->clone();
|
||||
std::string logger_name = "test2";
|
||||
spdlog::details::log_msg msg(logger_name, spdlog::level::info, "some message");
|
||||
@ -331,14 +312,12 @@ public:
|
||||
explicit custom_test_flag(std::string txt)
|
||||
: some_txt{std::move(txt)} {}
|
||||
|
||||
void format(const spdlog::details::log_msg &,
|
||||
const std::tm &tm,
|
||||
spdlog::memory_buf_t &dest) override {
|
||||
void format(const spdlog::details::log_msg &, const std::tm &tm, spdlog::memory_buf_t &dest) override {
|
||||
if (some_txt == "throw_me") {
|
||||
throw spdlog::spdlog_ex("custom_flag_exception_test");
|
||||
} else if (some_txt == "time") {
|
||||
auto formatted = spdlog::fmt_lib::format("{:d}:{:02d}{:s}", tm.tm_hour % 12, tm.tm_min,
|
||||
tm.tm_hour / 12 ? "PM" : "AM");
|
||||
auto formatted =
|
||||
spdlog::fmt_lib::format("{:d}:{:02d}{:s}", tm.tm_hour % 12, tm.tm_min, tm.tm_hour / 12 ? "PM" : "AM");
|
||||
dest.append(formatted.data(), formatted.data() + formatted.size());
|
||||
return;
|
||||
}
|
||||
@ -366,8 +345,8 @@ TEST_CASE("clone-custom_formatter", "[pattern_formatter]") {
|
||||
formatter_1->format(msg, formatted_1);
|
||||
formatter_2->format(msg, formatted_2);
|
||||
|
||||
auto expected = spdlog::fmt_lib::format("[logger-name] [custom_output] some message{}",
|
||||
spdlog::details::os::default_eol);
|
||||
auto expected =
|
||||
spdlog::fmt_lib::format("[logger-name] [custom_output] some message{}", spdlog::details::os::default_eol);
|
||||
|
||||
REQUIRE(to_string_view(formatted_1) == expected);
|
||||
REQUIRE(to_string_view(formatted_2) == expected);
|
||||
@ -435,11 +414,10 @@ TEST_CASE("custom flags", "[pattern_formatter]") {
|
||||
|
||||
memory_buf_t formatted;
|
||||
|
||||
spdlog::details::log_msg msg(spdlog::source_loc{}, "logger-name", spdlog::level::info,
|
||||
"some message");
|
||||
spdlog::details::log_msg msg(spdlog::source_loc{}, "logger-name", spdlog::level::info, "some message");
|
||||
formatter->format(msg, formatted);
|
||||
auto expected = spdlog::fmt_lib::format("[logger-name] [custom1] [custom2] some message{}",
|
||||
spdlog::details::os::default_eol);
|
||||
auto expected =
|
||||
spdlog::fmt_lib::format("[logger-name] [custom1] [custom2] some message{}", spdlog::details::os::default_eol);
|
||||
|
||||
REQUIRE(to_string_view(formatted) == expected);
|
||||
}
|
||||
@ -452,8 +430,7 @@ TEST_CASE("custom flags-padding", "[pattern_formatter]") {
|
||||
|
||||
memory_buf_t formatted;
|
||||
|
||||
spdlog::details::log_msg msg(spdlog::source_loc{}, "logger-name", spdlog::level::info,
|
||||
"some message");
|
||||
spdlog::details::log_msg msg(spdlog::source_loc{}, "logger-name", spdlog::level::info, "some message");
|
||||
formatter->format(msg, formatted);
|
||||
auto expected = spdlog::fmt_lib::format("[logger-name] [custom1] [ custom2] some message{}",
|
||||
spdlog::details::os::default_eol);
|
||||
@ -468,20 +445,17 @@ TEST_CASE("custom flags-exception", "[pattern_formatter]") {
|
||||
.set_pattern("[%n] [%t] [%u] %v");
|
||||
|
||||
memory_buf_t formatted;
|
||||
spdlog::details::log_msg msg(spdlog::source_loc{}, "logger-name", spdlog::level::info,
|
||||
"some message");
|
||||
spdlog::details::log_msg msg(spdlog::source_loc{}, "logger-name", spdlog::level::info, "some message");
|
||||
CHECK_THROWS_AS(formatter->format(msg, formatted), spdlog::spdlog_ex);
|
||||
}
|
||||
|
||||
TEST_CASE("override need_localtime", "[pattern_formatter]") {
|
||||
auto formatter =
|
||||
std::make_shared<spdlog::pattern_formatter>(spdlog::pattern_time_type::local, "\n");
|
||||
auto formatter = std::make_shared<spdlog::pattern_formatter>(spdlog::pattern_time_type::local, "\n");
|
||||
formatter->add_flag<custom_test_flag>('t', "time").set_pattern("%t> %v");
|
||||
|
||||
{
|
||||
memory_buf_t formatted;
|
||||
spdlog::details::log_msg msg(spdlog::source_loc{}, "logger-name", spdlog::level::info,
|
||||
"some message");
|
||||
spdlog::details::log_msg msg(spdlog::source_loc{}, "logger-name", spdlog::level::info, "some message");
|
||||
formatter->format(msg, formatted);
|
||||
REQUIRE(to_string_view(formatted) == "0:00AM> some message\n");
|
||||
}
|
||||
@ -495,8 +469,7 @@ TEST_CASE("override need_localtime", "[pattern_formatter]") {
|
||||
<< (now_tm.tm_hour / 12 ? "PM" : "AM") << "> some message\n";
|
||||
|
||||
memory_buf_t formatted;
|
||||
spdlog::details::log_msg msg(spdlog::source_loc{}, "logger-name", spdlog::level::info,
|
||||
"some message");
|
||||
spdlog::details::log_msg msg(spdlog::source_loc{}, "logger-name", spdlog::level::info, "some message");
|
||||
formatter->format(msg, formatted);
|
||||
REQUIRE(to_string_view(formatted) == oss.str());
|
||||
}
|
||||
|
@ -11,29 +11,25 @@ TEST_CASE("register_drop", "[registry]") {
|
||||
spdlog::create<spdlog::sinks::null_sink_mt>(tested_logger_name);
|
||||
REQUIRE(spdlog::get(tested_logger_name) != nullptr);
|
||||
// Throw if registering existing name
|
||||
REQUIRE_THROWS_AS(spdlog::create<spdlog::sinks::null_sink_mt>(tested_logger_name),
|
||||
spdlog::spdlog_ex);
|
||||
REQUIRE_THROWS_AS(spdlog::create<spdlog::sinks::null_sink_mt>(tested_logger_name), spdlog::spdlog_ex);
|
||||
}
|
||||
|
||||
TEST_CASE("explicit register", "[registry]") {
|
||||
spdlog::drop_all();
|
||||
auto logger = std::make_shared<spdlog::logger>(tested_logger_name,
|
||||
std::make_shared<spdlog::sinks::null_sink_st>());
|
||||
auto logger = std::make_shared<spdlog::logger>(tested_logger_name, std::make_shared<spdlog::sinks::null_sink_st>());
|
||||
spdlog::register_logger(logger);
|
||||
REQUIRE(spdlog::get(tested_logger_name) != nullptr);
|
||||
// Throw if registering existing name
|
||||
REQUIRE_THROWS_AS(spdlog::create<spdlog::sinks::null_sink_mt>(tested_logger_name),
|
||||
spdlog::spdlog_ex);
|
||||
REQUIRE_THROWS_AS(spdlog::create<spdlog::sinks::null_sink_mt>(tested_logger_name), spdlog::spdlog_ex);
|
||||
}
|
||||
#endif
|
||||
|
||||
TEST_CASE("apply_all", "[registry]") {
|
||||
spdlog::drop_all();
|
||||
auto logger = std::make_shared<spdlog::logger>(tested_logger_name,
|
||||
std::make_shared<spdlog::sinks::null_sink_st>());
|
||||
auto logger = std::make_shared<spdlog::logger>(tested_logger_name, std::make_shared<spdlog::sinks::null_sink_st>());
|
||||
spdlog::register_logger(logger);
|
||||
auto logger2 = std::make_shared<spdlog::logger>(
|
||||
tested_logger_name2, std::make_shared<spdlog::sinks::null_sink_st>());
|
||||
auto logger2 =
|
||||
std::make_shared<spdlog::logger>(tested_logger_name2, std::make_shared<spdlog::sinks::null_sink_st>());
|
||||
spdlog::register_logger(logger2);
|
||||
|
||||
int counter = 0;
|
||||
@ -100,8 +96,8 @@ TEST_CASE("disable automatic registration", "[registry]") {
|
||||
spdlog::set_level(level);
|
||||
// but disable automatic registration
|
||||
spdlog::set_automatic_registration(false);
|
||||
auto logger1 = spdlog::create<spdlog::sinks::daily_file_sink_st>(
|
||||
tested_logger_name, SPDLOG_FILENAME_T("filename"), 11, 59);
|
||||
auto logger1 =
|
||||
spdlog::create<spdlog::sinks::daily_file_sink_st>(tested_logger_name, SPDLOG_FILENAME_T("filename"), 11, 59);
|
||||
auto logger2 = spdlog::create_async<spdlog::sinks::stdout_color_sink_mt>(tested_logger_name2);
|
||||
// loggers should not be part of the registry
|
||||
REQUIRE_FALSE(spdlog::get(tested_logger_name));
|
||||
|
@ -16,8 +16,7 @@ TEST_CASE("test_drain", "[ringbuffer_sink]") {
|
||||
|
||||
int counter = 0;
|
||||
sink->drain([&](std::string_view msg) {
|
||||
REQUIRE(msg == spdlog::fmt_lib::format("*** {}{}", counter + 1,
|
||||
spdlog::details::os::default_eol));
|
||||
REQUIRE(msg == spdlog::fmt_lib::format("*** {}{}", counter + 1, spdlog::details::os::default_eol));
|
||||
counter++;
|
||||
});
|
||||
|
||||
|
@ -14,8 +14,7 @@ TEST_CASE("test_source_location", "[source_location]") {
|
||||
oss_logger.set_pattern("%s:%# %v");
|
||||
|
||||
oss_logger.info("Hello {}", "source location");
|
||||
REQUIRE(oss.str() ==
|
||||
std::string("test_source_location.cpp:16 Hello source location") + default_eol);
|
||||
REQUIRE(oss.str() == std::string("test_source_location.cpp:16 Hello source location") + default_eol);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
Loading…
Reference in New Issue
Block a user