More fixes relating to removal of factory and registry

This commit is contained in:
gabime 2024-11-23 16:50:47 +02:00
parent 659eda9afd
commit 20cd4462b3
10 changed files with 122 additions and 233 deletions

View File

@ -10,7 +10,7 @@
#include "benchmark/benchmark.h" #include "benchmark/benchmark.h"
#include "spdlog/spdlog.h" #include "spdlog/spdlog.h"
#include "spdlog/async.h" #include "spdlog/async_logger.h"
#include "spdlog/sinks/basic_file_sink.h" #include "spdlog/sinks/basic_file_sink.h"
#include "spdlog/sinks/daily_file_sink.h" #include "spdlog/sinks/daily_file_sink.h"
#include "spdlog/sinks/null_sink.h" #include "spdlog/sinks/null_sink.h"
@ -69,15 +69,15 @@ void bench_disabled_macro_global_logger(benchmark::State &state,
#ifdef __linux__ #ifdef __linux__
void bench_dev_null() { void bench_dev_null() {
auto dev_null_st = spdlog::basic_logger_st("/dev/null_st", "/dev/null"); auto sink_st = std::make_shared<spdlog::sinks::basic_file_sink_st>("/dev/null");
benchmark::RegisterBenchmark("/dev/null_st", bench_logger, std::move(dev_null_st)) auto dev_null_st = std::make_shared<spdlog::logger>("/dev/null_st", std::move(sink_st));
RegisterBenchmark("/dev/null_st", bench_logger, std::move(dev_null_st))
->UseRealTime(); ->UseRealTime();
spdlog::drop("/dev/null_st");
auto dev_null_mt = spdlog::basic_logger_mt("/dev/null_mt", "/dev/null"); auto sink_mt = std::make_shared<spdlog::sinks::basic_file_sink_st>("/dev/null");
benchmark::RegisterBenchmark("/dev/null_mt", bench_logger, std::move(dev_null_mt)) auto dev_null_mt = std::make_shared<spdlog::logger>("/dev/null_mt", std::move(sink_mt));
RegisterBenchmark("/dev/null_mt", bench_logger, std::move(dev_null_mt))
->UseRealTime(); ->UseRealTime();
spdlog::drop("/dev/null_mt");
} }
#endif // __linux__ #endif // __linux__
@ -95,31 +95,31 @@ int main(int argc, char *argv[]) {
auto disabled_logger = auto disabled_logger =
std::make_shared<spdlog::logger>("bench", std::make_shared<null_sink_mt>()); std::make_shared<spdlog::logger>("bench", std::make_shared<null_sink_mt>());
disabled_logger->set_level(spdlog::level::off); disabled_logger->set_level(spdlog::level::off);
benchmark::RegisterBenchmark("disabled-at-compile-time", bench_disabled_macro, disabled_logger); RegisterBenchmark("disabled-at-compile-time", bench_disabled_macro, disabled_logger);
benchmark::RegisterBenchmark("disabled-at-compile-time (global logger)", RegisterBenchmark("disabled-at-compile-time (global logger)",
bench_disabled_macro_global_logger, disabled_logger); bench_disabled_macro_global_logger, disabled_logger);
benchmark::RegisterBenchmark("disabled-at-runtime", bench_logger, disabled_logger); RegisterBenchmark("disabled-at-runtime", bench_logger, disabled_logger);
benchmark::RegisterBenchmark("disabled-at-runtime (global logger)", bench_global_logger, RegisterBenchmark("disabled-at-runtime (global logger)", bench_global_logger,
disabled_logger); disabled_logger);
// with backtrace of 64 // with backtrace of 64
auto tracing_disabled_logger = auto tracing_disabled_logger =
std::make_shared<spdlog::logger>("bench", std::make_shared<null_sink_mt>()); std::make_shared<spdlog::logger>("bench", std::make_shared<null_sink_mt>());
tracing_disabled_logger->enable_backtrace(64); tracing_disabled_logger->enable_backtrace(64);
benchmark::RegisterBenchmark("disabled-at-runtime/backtrace", bench_logger, RegisterBenchmark("disabled-at-runtime/backtrace", bench_logger,
tracing_disabled_logger); tracing_disabled_logger);
auto null_logger_st = auto null_logger_st =
std::make_shared<spdlog::logger>("bench", std::make_shared<null_sink_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, RegisterBenchmark("null_sink_st (500_bytes c_str)", bench_c_string,
std::move(null_logger_st)); std::move(null_logger_st));
benchmark::RegisterBenchmark("null_sink_st", bench_logger, null_logger_st); RegisterBenchmark("null_sink_st", bench_logger, null_logger_st);
benchmark::RegisterBenchmark("null_sink_st (global logger)", bench_global_logger, RegisterBenchmark("null_sink_st (global logger)", bench_global_logger,
null_logger_st); null_logger_st);
// with backtrace of 64 // with backtrace of 64
auto tracing_null_logger_st = auto tracing_null_logger_st =
std::make_shared<spdlog::logger>("bench", std::make_shared<null_sink_st>()); std::make_shared<spdlog::logger>("bench", std::make_shared<null_sink_st>());
tracing_null_logger_st->enable_backtrace(64); tracing_null_logger_st->enable_backtrace(64);
benchmark::RegisterBenchmark("null_sink_st/backtrace", bench_logger, tracing_null_logger_st); RegisterBenchmark("null_sink_st/backtrace", bench_logger, tracing_null_logger_st);
#ifdef __linux__ #ifdef __linux__
bench_dev_null(); bench_dev_null();
@ -127,74 +127,82 @@ int main(int argc, char *argv[]) {
if (full_bench) { if (full_bench) {
// basic_st // basic_st
auto basic_st = spdlog::basic_logger_st("basic_st", "latency_logs/basic_st.log", true); auto sink =
benchmark::RegisterBenchmark("basic_st", bench_logger, std::move(basic_st))->UseRealTime(); std::make_shared<spdlog::sinks::basic_file_sink_st>("latency_logs/basic_st.log", true);
spdlog::drop("basic_st"); auto basic_st = std::make_shared<spdlog::logger>("basic_st", std::move(sink));
RegisterBenchmark("basic_st", bench_logger, std::move(basic_st))->UseRealTime();
// with backtrace of 64 // with backtrace of 64
auto sink2 = std::make_shared<spdlog::sinks::basic_file_sink_st>(
"latency_logs/tracing_basic_st.log", true);
auto tracing_basic_st = auto tracing_basic_st =
spdlog::basic_logger_st("tracing_basic_st", "latency_logs/tracing_basic_st.log", true); std::make_shared<spdlog::logger>("tracing_basic_st", std::move(sink2));
tracing_basic_st->enable_backtrace(64); tracing_basic_st->enable_backtrace(64);
benchmark::RegisterBenchmark("basic_st/backtrace", bench_logger, RegisterBenchmark("basic_st/backtrace", bench_logger,
std::move(tracing_basic_st)) std::move(tracing_basic_st))
->UseRealTime(); ->UseRealTime();
spdlog::drop("tracing_basic_st");
// rotating st // rotating st
auto rotating_st = spdlog::rotating_logger_st("rotating_st", "latency_logs/rotating_st.log", auto sink3 = std::make_shared<spdlog::sinks::rotating_file_sink_st>(
file_size, rotating_files); "latency_logs/rotating_st.log", file_size, rotating_files);
benchmark::RegisterBenchmark("rotating_st", bench_logger, std::move(rotating_st)) auto rotating_st = std::make_shared<spdlog::logger>("rotate_st", std::move(sink3));
RegisterBenchmark("rotating_st", bench_logger, std::move(rotating_st))
->UseRealTime(); ->UseRealTime();
spdlog::drop("rotating_st");
// with backtrace of 64 // with backtrace of 64
auto tracing_rotating_st = spdlog::rotating_logger_st( auto sink4 = std::make_shared<spdlog::sinks::rotating_file_sink_st>(
"tracing_rotating_st", "latency_logs/tracing_rotating_st.log", file_size, "latency_logs/tracing_rotating_st.log", file_size, rotating_files);
rotating_files);
benchmark::RegisterBenchmark("rotating_st/backtrace", bench_logger, auto tracing_rotating_st =
std::move(tracing_rotating_st)) std::make_shared<spdlog::logger>("tracing_rotating_st", std::move(sink4));
->UseRealTime(); RegisterBenchmark("rotating_st/backtrace", bench_logger, std::move(tracing_rotating_st))->UseRealTime();
spdlog::drop("tracing_rotating_st");
// daily st // daily st
auto daily_st = spdlog::daily_logger_mt("daily_st", "latency_logs/daily_st.log"); auto sink5 =
benchmark::RegisterBenchmark("daily_st", bench_logger, std::move(daily_st))->UseRealTime(); std::make_shared<spdlog::sinks::daily_file_sink_st>("latency_logs/daily_st.log", 1, 0);
spdlog::drop("daily_st"); auto daily_st = std::make_shared<spdlog::logger>("daily_st", std::move(sink5));
RegisterBenchmark("daily_st", bench_logger, std::move(daily_st))->UseRealTime();
auto sink6 = std::make_shared<spdlog::sinks::daily_file_sink_st>("latency_logs/tracing_daily_st.log", 1, 0);
auto tracing_daily_st = auto tracing_daily_st =
spdlog::daily_logger_mt("tracing_daily_st", "latency_logs/daily_st.log"); std::make_shared<spdlog::logger>("logger", std::move(sink6));
benchmark::RegisterBenchmark("daily_st/backtrace", bench_logger, RegisterBenchmark("daily_st/backtrace", bench_logger,
std::move(tracing_daily_st)) std::move(tracing_daily_st))
->UseRealTime(); ->UseRealTime();
spdlog::drop("tracing_daily_st");
// //
// Multi threaded bench, 10 loggers using same logger concurrently // Multi threaded bench, 10 loggers using same logger concurrently
// //
auto null_logger_mt = auto null_logger_mt =
std::make_shared<spdlog::logger>("bench", std::make_shared<null_sink_mt>()); std::make_shared<spdlog::logger>("logger", std::make_shared<null_sink_mt>());
benchmark::RegisterBenchmark("null_sink_mt", bench_logger, null_logger_mt) RegisterBenchmark("null_sink_mt", bench_logger, null_logger_mt)
->Threads(n_threads) ->Threads(n_threads)
->UseRealTime(); ->UseRealTime();
// basic_mt // basic_mt
auto basic_mt = spdlog::basic_logger_mt("basic_mt", "latency_logs/basic_mt.log", true); auto sink7 =
benchmark::RegisterBenchmark("basic_mt", bench_logger, std::move(basic_mt)) std::make_shared<spdlog::sinks::basic_file_sink_mt>("latency_logs/basic_mt.log", true);
auto basic_mt = std::make_shared<spdlog::logger>("logger", std::move(sink7));
RegisterBenchmark("basic_mt", bench_logger, std::move(basic_mt))
->Threads(n_threads) ->Threads(n_threads)
->UseRealTime(); ->UseRealTime();
spdlog::drop("basic_mt");
// rotating mt // rotating mt
auto rotating_mt = spdlog::rotating_logger_mt("rotating_mt", "latency_logs/rotating_mt.log", auto sink8 = std::make_shared<spdlog::sinks::rotating_file_sink_mt>(
file_size, rotating_files); "latency_logs/rotating_mt.log", file_size, rotating_files);
benchmark::RegisterBenchmark("rotating_mt", bench_logger, std::move(rotating_mt))
auto rotating_mt = std::make_shared<spdlog::logger>("logger", std::move(sink8));
RegisterBenchmark("rotating_mt", bench_logger, std::move(rotating_mt))
->Threads(n_threads) ->Threads(n_threads)
->UseRealTime(); ->UseRealTime();
spdlog::drop("rotating_mt");
// daily mt // daily mt
auto daily_mt = spdlog::daily_logger_mt("daily_mt", "latency_logs/daily_mt.log"); auto sink9 =
benchmark::RegisterBenchmark("daily_mt", bench_logger, std::move(daily_mt)) std::make_shared<spdlog::sinks::daily_file_sink_mt>("latency_logs/daily_mt.log",1,0);
auto daily_mt = std::make_shared<spdlog::logger>("logger", std::move(sink9));
RegisterBenchmark("daily_mt", bench_logger, std::move(daily_mt))
->Threads(n_threads) ->Threads(n_threads)
->UseRealTime(); ->UseRealTime();
spdlog::drop("daily_mt");
} }
// async // async
@ -203,7 +211,7 @@ int main(int argc, char *argv[]) {
auto async_logger = std::make_shared<spdlog::async_logger>( auto async_logger = std::make_shared<spdlog::async_logger>(
"async_logger", std::make_shared<null_sink_mt>(), std::move(tp), "async_logger", std::make_shared<null_sink_mt>(), std::move(tp),
spdlog::async_overflow_policy::overrun_oldest); spdlog::async_overflow_policy::overrun_oldest);
benchmark::RegisterBenchmark("async_logger", bench_logger, async_logger) RegisterBenchmark("async_logger", bench_logger, async_logger)
->Threads(n_threads) ->Threads(n_threads)
->UseRealTime(); ->UseRealTime();
@ -211,7 +219,7 @@ int main(int argc, char *argv[]) {
"async_logger_tracing", std::make_shared<null_sink_mt>(), std::move(tp), "async_logger_tracing", std::make_shared<null_sink_mt>(), std::move(tp),
spdlog::async_overflow_policy::overrun_oldest); spdlog::async_overflow_policy::overrun_oldest);
async_logger_tracing->enable_backtrace(32); async_logger_tracing->enable_backtrace(32);
benchmark::RegisterBenchmark("async_logger/tracing", bench_logger, async_logger_tracing) RegisterBenchmark("async_logger/tracing", bench_logger, async_logger_tracing)
->Threads(n_threads) ->Threads(n_threads)
->UseRealTime(); ->UseRealTime();

View File

@ -4,8 +4,9 @@ Removed registry api
Removed spdlog/cfg/* api Removed spdlog/cfg/* api
(?) Renamed set/get_default_logger() to set/get_logger() (?) Renamed set/get_default_logger() to set/get_logger()
Removed all factory functions. Use the logger constructor instead. Removed all factory functions. Use the logger constructor instead.
Removed flush_every
TODO TODO
Thread pool singleton and clean async.h Thread pool singleton and clean async.h
flush_every removed() ? remove periodic worker files

View File

@ -28,7 +28,6 @@ void file_events_example();
void replace_default_logger_example(); void replace_default_logger_example();
#include "spdlog/spdlog.h" #include "spdlog/spdlog.h"
#include "spdlog/cfg/env.h" // support for loading levels from the environment variable
#include "spdlog/fmt/ostr.h" // support for user defined types #include "spdlog/fmt/ostr.h" // support for user defined types
int main(int, char *[]) { int main(int, char *[]) {
@ -85,14 +84,7 @@ int main(int, char *[]) {
file_events_example(); file_events_example();
replace_default_logger_example(); replace_default_logger_example();
// Flush all *registered* loggers using a worker thread every 3 seconds. // Release the default logger
// note: registered loggers *must* be thread safe for this to work correctly!
spdlog::flush_every(std::chrono::seconds(3));
// Apply some function on all registered loggers
spdlog::apply_all([&](std::shared_ptr<spdlog::logger> l) { l->info("End of example."); });
// Release all spdlog resources, and drop all loggers in the registry.
// This is optional (only mandatory if using windows + async log). // This is optional (only mandatory if using windows + async log).
spdlog::shutdown(); spdlog::shutdown();
} }
@ -108,63 +100,50 @@ int main(int, char *[]) {
// or #include "spdlog/sinks/stdout_sinks.h" if no colors needed. // or #include "spdlog/sinks/stdout_sinks.h" if no colors needed.
void stdout_logger_example() { void stdout_logger_example() {
// Create color multi threaded logger. // Create color multi threaded logger.
auto console = spdlog::stdout_color_mt("console"); auto sink = std::make_shared<spdlog::sinks::stdout_color_sink_mt>();
// or for stderr: // or for stderr:
// auto console = spdlog::stderr_color_mt("error-logger"); // auto sink = std::make_shared<spdlog::sinks::stderr_color_sink_mt>();
spdlog::logger logger("console", std::move(sink));
} }
#include "spdlog/sinks/basic_file_sink.h" #include "spdlog/sinks/basic_file_sink.h"
void basic_example() { void basic_example() {
// Create basic file logger (not rotated). // Create basic file logger (not rotated).
auto my_logger = spdlog::basic_logger_mt("file_logger", "logs/basic-log.txt", true); auto sink = std::make_shared<spdlog::sinks::basic_file_sink_mt>("logs/basic-log.txt", true);
spdlog::logger logger("basic_logger", std::move(sink));
} }
#include "spdlog/sinks/rotating_file_sink.h" #include "spdlog/sinks/rotating_file_sink.h"
void rotating_example() { void rotating_example() {
// Create a file rotating logger with 5mb size max and 3 rotated files. // Create a file rotating logger with 5mb size max and 3 rotated files.
auto rotating_logger = auto sink =
spdlog::rotating_logger_mt("some_logger_name", "logs/rotating.txt", 1048576 * 5, 3); std::make_shared<spdlog::sinks::rotating_file_sink_mt>("logs/rotating.txt", 1048576 * 5, 3);
spdlog::logger logger("rotating_logger", std::move(sink));
} }
#include "spdlog/sinks/daily_file_sink.h" #include "spdlog/sinks/daily_file_sink.h"
void daily_example() { void daily_example() {
// Create a daily logger - a new file is created every day on 2:30am. // Create a daily logger - a new file is created every day on 2:30am.
auto daily_logger = spdlog::daily_logger_mt("daily_logger", "logs/daily.txt", 2, 30); auto sink = std::make_shared<spdlog::sinks::daily_file_sink_mt>("logs/daily.txt", 2, 30);
spdlog::logger logger("daily_logger", std::move(sink));
} }
#include "spdlog/sinks/callback_sink.h" #include "spdlog/sinks/callback_sink.h"
void callback_example() { void callback_example() {
// Create the logger // Create the logger
auto logger = spdlog::callback_logger_mt("custom_callback_logger", auto sink = std::make_shared<spdlog::sinks::callback_sink_mt>(
[](const spdlog::details::log_msg & /*msg*/) { [](const spdlog::details::log_msg & /*msg*/) { /* do something with the message */ });
// do what you need to do with msg spdlog::logger logger("callback_logger", std::move(sink));
});
} }
#include "spdlog/cfg/env.h" #include "spdlog/async_logger.h"
void load_levels_example() {
// Set the log level to "info" and mylogger to "trace":
// SPDLOG_LEVEL=info,mylogger=trace && ./example
spdlog::cfg::load_env_levels();
// or from command line:
// ./example SPDLOG_LEVEL=info,mylogger=trace
// #include "spdlog/cfg/argv.h" // for loading levels from argv
// spdlog::cfg::load_argv_levels(args, argv);
}
#include "spdlog/async.h"
void async_example() { void async_example() {
// Default thread pool settings can be modified *before* creating the async logger: auto tp = std::make_shared<spdlog::details::thread_pool>(32768, 1);
// spdlog::init_thread_pool(32768, 1); // queue with max 32k items 1 backing thread. auto sink = std::make_shared<spdlog::sinks::basic_file_sink_mt>("logs/async_log.txt");
auto async_file = auto logger = std::make_shared<spdlog::async_logger>(
spdlog::basic_logger_mt<spdlog::async_factory>("async_file_logger", "logs/async_log.txt"); "async_file_logger", std::move(sink), std::move(tp), spdlog::async_overflow_policy::block);
// alternatively:
// auto async_file =
// spdlog::create_async<spdlog::sinks::basic_file_sink_mt>("async_file_logger",
// "logs/async_log.txt");
for (int i = 1; i < 101; ++i) { for (int i = 1; i < 101; ++i) {
async_file->info("Async message #{}", i); logger->info("Async message #{}", i);
} }
} }
@ -222,9 +201,9 @@ void trace_example() {
// debug from default logger // debug from default logger
SPDLOG_DEBUG("Some debug message.. {} ,{}", 1, 3.23); SPDLOG_DEBUG("Some debug message.. {} ,{}", 1, 3.23);
// trace from logger object // trace from named logger
auto logger = spdlog::get("file_logger"); spdlog::logger some_logger("some_logger");
SPDLOG_LOGGER_TRACE(logger, "another trace message"); SPDLOG_LOGGER_TRACE(some_logger, "another trace message");
} }
// stopwatch example // stopwatch example
@ -239,9 +218,10 @@ void stopwatch_example() {
#include "spdlog/sinks/udp_sink.h" #include "spdlog/sinks/udp_sink.h"
void udp_example() { void udp_example() {
spdlog::sinks::udp_sink_config cfg("127.0.0.1", 11091); spdlog::sinks::udp_sink_config cfg("127.0.0.1", 11091);
auto my_logger = spdlog::udp_logger_mt("udplog", cfg); auto sink = std::make_shared<spdlog::sinks::udp_sink_mt>(cfg);
my_logger->set_level(spdlog::level::debug); spdlog::logger logger("udp_logger", std::move(sink));
my_logger->info("hello world"); logger.set_level(spdlog::level::debug);
logger.info("hello world");
} }
// A logger with multiple sinks (stdout and file) - each with a different format and log level. // A logger with multiple sinks (stdout and file) - each with a different format and log level.
@ -299,8 +279,12 @@ void err_handler_example() {
#include "spdlog/sinks/syslog_sink.h" #include "spdlog/sinks/syslog_sink.h"
void syslog_example() { void syslog_example() {
std::string ident = "spdlog-example"; std::string ident = "spdlog-example";
auto syslog_logger = spdlog::syslog_logger_mt("syslog", ident, LOG_PID); int syslog_option = 0;
syslog_logger->warn("This is warning that will end up in syslog."); int syslog_facility = LOG_USER;
bool enable_formatting = false;
auto sink = std::make_shared<spdlog::sinks::syslog_sink_mt>(ident, syslog_option,
syslog_facility, enable_formatting);
spdlog::logger logger("syslog_logger", std::move(sink));
} }
#endif #endif
@ -365,14 +349,12 @@ void file_events_example() {
void replace_default_logger_example() { void replace_default_logger_example() {
// store the old logger so we don't break other examples. // store the old logger so we don't break other examples.
auto old_logger = spdlog::default_logger(); auto old_logger = spdlog::default_logger();
auto new_logger = std::make_shared<spdlog::logger>("new_default_logger");
auto new_logger =
spdlog::basic_logger_mt("new_default_logger", "logs/new-default-log.txt", true);
spdlog::set_default_logger(new_logger); spdlog::set_default_logger(new_logger);
spdlog::set_level(spdlog::level::info); spdlog::set_level(spdlog::level::info);
spdlog::debug("This message should not be displayed!"); spdlog::debug("This message should not be displayed!");
spdlog::set_level(spdlog::level::trace); spdlog::set_level(spdlog::level::trace);
spdlog::debug("This message should be displayed.."); spdlog::debug("This message should be displayed..");
// restore the prev logger
spdlog::set_default_logger(old_logger); spdlog::set_default_logger(old_logger);
} }

View File

@ -1,87 +0,0 @@
// // Copyright(c) 2015-present, Gabi Melman & spdlog contributors.
// // Distributed under the MIT License (http://opensource.org/licenses/MIT)
//
// #pragma once
//
// //
// // Async logging using global thread pool
// // All loggers created here share same global thread pool.
// // Each log message is pushed to a queue along with a shared pointer to the
// // logger.
// // If a logger deleted while having pending messages in the queue, it's actual
// // destruction will defer
// // until all its messages are processed by the thread pool.
// // This is because each message in the queue holds a shared_ptr to the
// // originating logger.
//
// #include <spdlog/async_logger.h>
// #include <spdlog/details/thread_pool.h>
//
// #include <functional>
// #include <memory>
// #include <mutex>
//
// namespace spdlog {
//
// namespace details {
// static const size_t default_async_q_size = 8192;
// }
//
// // async logger factory - creates async loggers backed with thread pool.
// // if a global thread pool doesn't already exist, create it with default queue
// // size of 8192 items and single thread.
// template <async_overflow_policy OverflowPolicy = async_overflow_policy::block>
// struct async_factory_impl {
// template <typename Sink, typename... SinkArgs>
// static std::shared_ptr<async_logger> create(std::string logger_name, SinkArgs &&...args) {
// auto tp = std::make_shared<details::thread_pool>(details::default_async_q_size, 1U);
// 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);
// return new_logger;
// }
// };
//
// 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)...);
// }
//
// 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)...);
// }
//
// // // set global thread pool.
// // 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);
// // 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) {
// // init_thread_pool(q_size, thread_count, on_thread_start, [] {});
// // }
// //
// // inline void init_thread_pool(size_t q_size, size_t thread_count) {
// // init_thread_pool(
// // q_size, thread_count, [] {}, [] {});
// // }
//
// // get the global thread pool.
// // inline std::shared_ptr<spdlog::details::thread_pool> thread_pool() {
// // return details::registry::instance().get_tp();
// // }
// } // namespace spdlog

View File

@ -15,6 +15,7 @@
// destructing.. // destructing..
#include <spdlog/logger.h> #include <spdlog/logger.h>
#include <spdlog/details/thread_pool.h>
namespace spdlog { namespace spdlog {

View File

@ -4,7 +4,6 @@
#pragma once #pragma once
#include <spdlog/details/null_mutex.h> #include <spdlog/details/null_mutex.h>
#include <spdlog/details/synchronous_factory.h>
#include <spdlog/sinks/base_sink.h> #include <spdlog/sinks/base_sink.h>
#include <array> #include <array>
@ -81,24 +80,24 @@ using syslog_sink_mt = syslog_sink<std::mutex>;
using syslog_sink_st = syslog_sink<details::null_mutex>; using syslog_sink_st = syslog_sink<details::null_mutex>;
} // namespace sinks } // namespace sinks
// Create and register a syslog logger // // Create and register a syslog logger
template <typename Factory = spdlog::synchronous_factory> // template <typename Factory = spdlog::synchronous_factory>
inline std::shared_ptr<logger> syslog_logger_mt(const std::string &logger_name, // inline std::shared_ptr<logger> syslog_logger_mt(const std::string &logger_name,
const std::string &syslog_ident = "", // const std::string &syslog_ident = "",
int syslog_option = 0, // int syslog_option = 0,
int syslog_facility = LOG_USER, // int syslog_facility = LOG_USER,
bool enable_formatting = false) { // bool enable_formatting = false) {
return Factory::template create<sinks::syslog_sink_mt>(logger_name, syslog_ident, syslog_option, // return Factory::template create<sinks::syslog_sink_mt>(logger_name, syslog_ident, syslog_option,
syslog_facility, enable_formatting); // syslog_facility, enable_formatting);
} // }
//
template <typename Factory = spdlog::synchronous_factory> // template <typename Factory = spdlog::synchronous_factory>
inline std::shared_ptr<logger> syslog_logger_st(const std::string &logger_name, // inline std::shared_ptr<logger> syslog_logger_st(const std::string &logger_name,
const std::string &syslog_ident = "", // const std::string &syslog_ident = "",
int syslog_option = 0, // int syslog_option = 0,
int syslog_facility = LOG_USER, // int syslog_facility = LOG_USER,
bool enable_formatting = false) { // bool enable_formatting = false) {
return Factory::template create<sinks::syslog_sink_st>(logger_name, syslog_ident, syslog_option, // return Factory::template create<sinks::syslog_sink_st>(logger_name, syslog_ident, syslog_option,
syslog_facility, enable_formatting); // syslog_facility, enable_formatting);
} //}
} // namespace spdlog } // namespace spdlog

View File

@ -54,16 +54,5 @@ protected:
using udp_sink_mt = udp_sink<std::mutex>; using udp_sink_mt = udp_sink<std::mutex>;
using udp_sink_st = udp_sink<spdlog::details::null_mutex>; using udp_sink_st = udp_sink<spdlog::details::null_mutex>;
} // namespace sinks } // namespace sinks
//
// 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) {
return Factory::template create<sinks::udp_sink_mt>(logger_name, skin_config);
}
} // namespace spdlog } // namespace spdlog

View File

@ -5,7 +5,6 @@
#error Please define SPDLOG_COMPILED_LIB to compile this file. #error Please define SPDLOG_COMPILED_LIB to compile this file.
#endif #endif
#include <spdlog/async.h>
#include <spdlog/async_logger-inl.h> #include <spdlog/async_logger-inl.h>
#include <spdlog/details/periodic_worker-inl.h> #include <spdlog/details/periodic_worker-inl.h>
#include <spdlog/details/thread_pool-inl.h> #include <spdlog/details/thread_pool-inl.h>

View File

@ -6,8 +6,6 @@
#endif #endif
#include <mutex> #include <mutex>
#include <spdlog/async.h>
#include <spdlog/details/null_mutex.h> #include <spdlog/details/null_mutex.h>
// //
// color sinks // color sinks

View File

@ -7,7 +7,6 @@
#include <mutex> #include <mutex>
#include <spdlog/async.h>
#include <spdlog/details/null_mutex.h> #include <spdlog/details/null_mutex.h>
#include <spdlog/sinks/stdout_sinks-inl.h> #include <spdlog/sinks/stdout_sinks-inl.h>