mirror of
https://github.com/gabime/spdlog.git
synced 2025-01-12 17:00:25 +08:00
More fixes relating to removal of factory and registry
This commit is contained in:
parent
659eda9afd
commit
20cd4462b3
@ -10,7 +10,7 @@
|
||||
#include "benchmark/benchmark.h"
|
||||
|
||||
#include "spdlog/spdlog.h"
|
||||
#include "spdlog/async.h"
|
||||
#include "spdlog/async_logger.h"
|
||||
#include "spdlog/sinks/basic_file_sink.h"
|
||||
#include "spdlog/sinks/daily_file_sink.h"
|
||||
#include "spdlog/sinks/null_sink.h"
|
||||
@ -69,15 +69,15 @@ 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))
|
||||
auto sink_st = std::make_shared<spdlog::sinks::basic_file_sink_st>("/dev/null");
|
||||
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();
|
||||
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))
|
||||
auto sink_mt = std::make_shared<spdlog::sinks::basic_file_sink_st>("/dev/null");
|
||||
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();
|
||||
spdlog::drop("/dev/null_mt");
|
||||
}
|
||||
#endif // __linux__
|
||||
|
||||
@ -95,31 +95,31 @@ int main(int argc, char *argv[]) {
|
||||
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)",
|
||||
RegisterBenchmark("disabled-at-compile-time", bench_disabled_macro, disabled_logger);
|
||||
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,
|
||||
RegisterBenchmark("disabled-at-runtime", bench_logger, disabled_logger);
|
||||
RegisterBenchmark("disabled-at-runtime (global logger)", bench_global_logger,
|
||||
disabled_logger);
|
||||
// with backtrace of 64
|
||||
auto tracing_disabled_logger =
|
||||
std::make_shared<spdlog::logger>("bench", std::make_shared<null_sink_mt>());
|
||||
tracing_disabled_logger->enable_backtrace(64);
|
||||
benchmark::RegisterBenchmark("disabled-at-runtime/backtrace", bench_logger,
|
||||
RegisterBenchmark("disabled-at-runtime/backtrace", bench_logger,
|
||||
tracing_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,
|
||||
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,
|
||||
RegisterBenchmark("null_sink_st", bench_logger, null_logger_st);
|
||||
RegisterBenchmark("null_sink_st (global logger)", bench_global_logger,
|
||||
null_logger_st);
|
||||
// with backtrace of 64
|
||||
auto tracing_null_logger_st =
|
||||
std::make_shared<spdlog::logger>("bench", std::make_shared<null_sink_st>());
|
||||
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__
|
||||
bench_dev_null();
|
||||
@ -127,74 +127,82 @@ int main(int argc, char *argv[]) {
|
||||
|
||||
if (full_bench) {
|
||||
// basic_st
|
||||
auto basic_st = spdlog::basic_logger_st("basic_st", "latency_logs/basic_st.log", true);
|
||||
benchmark::RegisterBenchmark("basic_st", bench_logger, std::move(basic_st))->UseRealTime();
|
||||
spdlog::drop("basic_st");
|
||||
auto sink =
|
||||
std::make_shared<spdlog::sinks::basic_file_sink_st>("latency_logs/basic_st.log", true);
|
||||
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
|
||||
|
||||
auto sink2 = std::make_shared<spdlog::sinks::basic_file_sink_st>(
|
||||
"latency_logs/tracing_basic_st.log", true);
|
||||
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);
|
||||
benchmark::RegisterBenchmark("basic_st/backtrace", bench_logger,
|
||||
RegisterBenchmark("basic_st/backtrace", bench_logger,
|
||||
std::move(tracing_basic_st))
|
||||
->UseRealTime();
|
||||
spdlog::drop("tracing_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))
|
||||
auto sink3 = std::make_shared<spdlog::sinks::rotating_file_sink_st>(
|
||||
"latency_logs/rotating_st.log", file_size, rotating_files);
|
||||
auto rotating_st = std::make_shared<spdlog::logger>("rotate_st", std::move(sink3));
|
||||
RegisterBenchmark("rotating_st", bench_logger, std::move(rotating_st))
|
||||
->UseRealTime();
|
||||
spdlog::drop("rotating_st");
|
||||
// with backtrace of 64
|
||||
auto tracing_rotating_st = spdlog::rotating_logger_st(
|
||||
"tracing_rotating_st", "latency_logs/tracing_rotating_st.log", file_size,
|
||||
rotating_files);
|
||||
benchmark::RegisterBenchmark("rotating_st/backtrace", bench_logger,
|
||||
std::move(tracing_rotating_st))
|
||||
->UseRealTime();
|
||||
spdlog::drop("tracing_rotating_st");
|
||||
auto sink4 = std::make_shared<spdlog::sinks::rotating_file_sink_st>(
|
||||
"latency_logs/tracing_rotating_st.log", file_size, rotating_files);
|
||||
|
||||
auto tracing_rotating_st =
|
||||
std::make_shared<spdlog::logger>("tracing_rotating_st", std::move(sink4));
|
||||
RegisterBenchmark("rotating_st/backtrace", bench_logger, std::move(tracing_rotating_st))->UseRealTime();
|
||||
|
||||
// daily st
|
||||
auto daily_st = spdlog::daily_logger_mt("daily_st", "latency_logs/daily_st.log");
|
||||
benchmark::RegisterBenchmark("daily_st", bench_logger, std::move(daily_st))->UseRealTime();
|
||||
spdlog::drop("daily_st");
|
||||
auto sink5 =
|
||||
std::make_shared<spdlog::sinks::daily_file_sink_st>("latency_logs/daily_st.log", 1, 0);
|
||||
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 =
|
||||
spdlog::daily_logger_mt("tracing_daily_st", "latency_logs/daily_st.log");
|
||||
benchmark::RegisterBenchmark("daily_st/backtrace", bench_logger,
|
||||
std::make_shared<spdlog::logger>("logger", std::move(sink6));
|
||||
RegisterBenchmark("daily_st/backtrace", bench_logger,
|
||||
std::move(tracing_daily_st))
|
||||
->UseRealTime();
|
||||
spdlog::drop("tracing_daily_st");
|
||||
|
||||
//
|
||||
// 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)
|
||||
std::make_shared<spdlog::logger>("logger", std::make_shared<null_sink_mt>());
|
||||
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))
|
||||
auto sink7 =
|
||||
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)
|
||||
->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);
|
||||
benchmark::RegisterBenchmark("rotating_mt", bench_logger, std::move(rotating_mt))
|
||||
auto sink8 = std::make_shared<spdlog::sinks::rotating_file_sink_mt>(
|
||||
"latency_logs/rotating_mt.log", file_size, rotating_files);
|
||||
|
||||
auto rotating_mt = std::make_shared<spdlog::logger>("logger", std::move(sink8));
|
||||
|
||||
RegisterBenchmark("rotating_mt", bench_logger, std::move(rotating_mt))
|
||||
->Threads(n_threads)
|
||||
->UseRealTime();
|
||||
spdlog::drop("rotating_mt");
|
||||
|
||||
// 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))
|
||||
auto sink9 =
|
||||
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)
|
||||
->UseRealTime();
|
||||
spdlog::drop("daily_mt");
|
||||
}
|
||||
|
||||
// async
|
||||
@ -203,7 +211,7 @@ int main(int argc, char *argv[]) {
|
||||
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)
|
||||
RegisterBenchmark("async_logger", bench_logger, async_logger)
|
||||
->Threads(n_threads)
|
||||
->UseRealTime();
|
||||
|
||||
@ -211,7 +219,7 @@ int main(int argc, char *argv[]) {
|
||||
"async_logger_tracing", std::make_shared<null_sink_mt>(), std::move(tp),
|
||||
spdlog::async_overflow_policy::overrun_oldest);
|
||||
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)
|
||||
->UseRealTime();
|
||||
|
||||
|
5
changes
5
changes
@ -4,8 +4,9 @@ Removed registry api
|
||||
Removed spdlog/cfg/* api
|
||||
(?) Renamed set/get_default_logger() to set/get_logger()
|
||||
Removed all factory functions. Use the logger constructor instead.
|
||||
Removed flush_every
|
||||
|
||||
TODO
|
||||
|
||||
Thread pool singleton and clean async.h
|
||||
flush_every removed() ?
|
||||
remove periodic worker files
|
||||
|
||||
|
@ -28,12 +28,11 @@ void file_events_example();
|
||||
void replace_default_logger_example();
|
||||
|
||||
#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
|
||||
|
||||
int main(int, char *[]) {
|
||||
// Log levels can be loaded from argv/env using "SPDLOG_LEVEL"
|
||||
//load_levels_example();
|
||||
// load_levels_example();
|
||||
|
||||
spdlog::info("Welcome to spdlog version {}.{}.{} !", SPDLOG_VER_MAJOR, SPDLOG_VER_MINOR,
|
||||
SPDLOG_VER_PATCH);
|
||||
@ -85,14 +84,7 @@ int main(int, char *[]) {
|
||||
file_events_example();
|
||||
replace_default_logger_example();
|
||||
|
||||
// Flush all *registered* loggers using a worker thread every 3 seconds.
|
||||
// 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.
|
||||
// Release the default logger
|
||||
// This is optional (only mandatory if using windows + async log).
|
||||
spdlog::shutdown();
|
||||
}
|
||||
@ -108,63 +100,50 @@ int main(int, char *[]) {
|
||||
// or #include "spdlog/sinks/stdout_sinks.h" if no colors needed.
|
||||
void stdout_logger_example() {
|
||||
// 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:
|
||||
// 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"
|
||||
void basic_example() {
|
||||
// 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"
|
||||
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 sink =
|
||||
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"
|
||||
void daily_example() {
|
||||
// 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"
|
||||
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 sink = std::make_shared<spdlog::sinks::callback_sink_mt>(
|
||||
[](const spdlog::details::log_msg & /*msg*/) { /* do something with the message */ });
|
||||
spdlog::logger logger("callback_logger", std::move(sink));
|
||||
}
|
||||
|
||||
#include "spdlog/cfg/env.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"
|
||||
#include "spdlog/async_logger.h"
|
||||
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");
|
||||
// alternatively:
|
||||
// auto async_file =
|
||||
// spdlog::create_async<spdlog::sinks::basic_file_sink_mt>("async_file_logger",
|
||||
// "logs/async_log.txt");
|
||||
|
||||
auto tp = std::make_shared<spdlog::details::thread_pool>(32768, 1);
|
||||
auto sink = std::make_shared<spdlog::sinks::basic_file_sink_mt>("logs/async_log.txt");
|
||||
auto logger = std::make_shared<spdlog::async_logger>(
|
||||
"async_file_logger", std::move(sink), std::move(tp), spdlog::async_overflow_policy::block);
|
||||
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
|
||||
SPDLOG_DEBUG("Some debug message.. {} ,{}", 1, 3.23);
|
||||
|
||||
// trace from logger object
|
||||
auto logger = spdlog::get("file_logger");
|
||||
SPDLOG_LOGGER_TRACE(logger, "another trace message");
|
||||
// trace from named logger
|
||||
spdlog::logger some_logger("some_logger");
|
||||
SPDLOG_LOGGER_TRACE(some_logger, "another trace message");
|
||||
}
|
||||
|
||||
// stopwatch example
|
||||
@ -239,9 +218,10 @@ void stopwatch_example() {
|
||||
#include "spdlog/sinks/udp_sink.h"
|
||||
void udp_example() {
|
||||
spdlog::sinks::udp_sink_config cfg("127.0.0.1", 11091);
|
||||
auto my_logger = spdlog::udp_logger_mt("udplog", cfg);
|
||||
my_logger->set_level(spdlog::level::debug);
|
||||
my_logger->info("hello world");
|
||||
auto sink = std::make_shared<spdlog::sinks::udp_sink_mt>(cfg);
|
||||
spdlog::logger logger("udp_logger", std::move(sink));
|
||||
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.
|
||||
@ -264,7 +244,7 @@ void multi_sink_example() {
|
||||
struct my_type {
|
||||
int i = 0;
|
||||
explicit my_type(int i)
|
||||
: i(i){}
|
||||
: i(i) {}
|
||||
};
|
||||
|
||||
#ifndef SPDLOG_USE_STD_FORMAT // when using fmtlib
|
||||
@ -299,8 +279,12 @@ void err_handler_example() {
|
||||
#include "spdlog/sinks/syslog_sink.h"
|
||||
void syslog_example() {
|
||||
std::string ident = "spdlog-example";
|
||||
auto syslog_logger = spdlog::syslog_logger_mt("syslog", ident, LOG_PID);
|
||||
syslog_logger->warn("This is warning that will end up in syslog.");
|
||||
int syslog_option = 0;
|
||||
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
|
||||
|
||||
@ -365,14 +349,12 @@ void file_events_example() {
|
||||
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 = std::make_shared<spdlog::logger>("new_default_logger");
|
||||
spdlog::set_default_logger(new_logger);
|
||||
spdlog::set_level(spdlog::level::info);
|
||||
spdlog::debug("This message should not be displayed!");
|
||||
spdlog::set_level(spdlog::level::trace);
|
||||
spdlog::debug("This message should be displayed..");
|
||||
|
||||
// restore the prev logger
|
||||
spdlog::set_default_logger(old_logger);
|
||||
}
|
@ -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
|
@ -15,6 +15,7 @@
|
||||
// destructing..
|
||||
|
||||
#include <spdlog/logger.h>
|
||||
#include <spdlog/details/thread_pool.h>
|
||||
|
||||
namespace spdlog {
|
||||
|
||||
|
@ -4,7 +4,6 @@
|
||||
#pragma once
|
||||
|
||||
#include <spdlog/details/null_mutex.h>
|
||||
#include <spdlog/details/synchronous_factory.h>
|
||||
#include <spdlog/sinks/base_sink.h>
|
||||
|
||||
#include <array>
|
||||
@ -81,24 +80,24 @@ using syslog_sink_mt = syslog_sink<std::mutex>;
|
||||
using syslog_sink_st = syslog_sink<details::null_mutex>;
|
||||
} // namespace sinks
|
||||
|
||||
// Create and register a syslog logger
|
||||
template <typename Factory = spdlog::synchronous_factory>
|
||||
inline std::shared_ptr<logger> syslog_logger_mt(const std::string &logger_name,
|
||||
const std::string &syslog_ident = "",
|
||||
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);
|
||||
}
|
||||
|
||||
template <typename Factory = spdlog::synchronous_factory>
|
||||
inline std::shared_ptr<logger> syslog_logger_st(const std::string &logger_name,
|
||||
const std::string &syslog_ident = "",
|
||||
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);
|
||||
}
|
||||
// // Create and register a syslog logger
|
||||
// template <typename Factory = spdlog::synchronous_factory>
|
||||
// inline std::shared_ptr<logger> syslog_logger_mt(const std::string &logger_name,
|
||||
// const std::string &syslog_ident = "",
|
||||
// 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);
|
||||
// }
|
||||
//
|
||||
// template <typename Factory = spdlog::synchronous_factory>
|
||||
// inline std::shared_ptr<logger> syslog_logger_st(const std::string &logger_name,
|
||||
// const std::string &syslog_ident = "",
|
||||
// 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);
|
||||
//}
|
||||
} // namespace spdlog
|
||||
|
@ -54,16 +54,5 @@ protected:
|
||||
|
||||
using udp_sink_mt = udp_sink<std::mutex>;
|
||||
using udp_sink_st = udp_sink<spdlog::details::null_mutex>;
|
||||
|
||||
} // 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
|
||||
|
@ -5,7 +5,6 @@
|
||||
#error Please define SPDLOG_COMPILED_LIB to compile this file.
|
||||
#endif
|
||||
|
||||
#include <spdlog/async.h>
|
||||
#include <spdlog/async_logger-inl.h>
|
||||
#include <spdlog/details/periodic_worker-inl.h>
|
||||
#include <spdlog/details/thread_pool-inl.h>
|
||||
|
@ -6,8 +6,6 @@
|
||||
#endif
|
||||
|
||||
#include <mutex>
|
||||
|
||||
#include <spdlog/async.h>
|
||||
#include <spdlog/details/null_mutex.h>
|
||||
//
|
||||
// color sinks
|
||||
|
@ -7,7 +7,6 @@
|
||||
|
||||
#include <mutex>
|
||||
|
||||
#include <spdlog/async.h>
|
||||
#include <spdlog/details/null_mutex.h>
|
||||
#include <spdlog/sinks/stdout_sinks-inl.h>
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user