mirror of
https://github.com/gabime/spdlog.git
synced 2025-04-30 12:23:53 +00:00
clang-format
This commit is contained in:
parent
15829cfb84
commit
06be4409e6
@ -80,7 +80,6 @@ void bench_dev_null() {
|
|||||||
|
|
||||||
#endif // __linux__
|
#endif // __linux__
|
||||||
|
|
||||||
|
|
||||||
// test spdlog::get() performance
|
// test spdlog::get() performance
|
||||||
// for this test we create multiple null loggers and then call spdlog::get() on one of them multiple times
|
// for this test we create multiple null loggers and then call spdlog::get() on one of them multiple times
|
||||||
// create multiple null loggers and return name of the one to test
|
// create multiple null loggers and return name of the one to test
|
||||||
@ -201,7 +200,6 @@ int main(int argc, char *argv[]) {
|
|||||||
spdlog::async_overflow_policy::overrun_oldest);
|
spdlog::async_overflow_policy::overrun_oldest);
|
||||||
benchmark::RegisterBenchmark("async_logger", bench_logger, async_logger)->Threads(n_threads)->UseRealTime();
|
benchmark::RegisterBenchmark("async_logger", bench_logger, async_logger)->Threads(n_threads)->UseRealTime();
|
||||||
|
|
||||||
|
|
||||||
benchmark::RegisterBenchmark("spdlog::get(const char* name)", bench_get_logger_const_char);
|
benchmark::RegisterBenchmark("spdlog::get(const char* name)", bench_get_logger_const_char);
|
||||||
benchmark::RegisterBenchmark("spdlog::get(std::string_view name)", bench_get_logger_sv);
|
benchmark::RegisterBenchmark("spdlog::get(std::string_view name)", bench_get_logger_sv);
|
||||||
benchmark::RegisterBenchmark("spdlog::get(const std::string &name)", bench_get_logger_string);
|
benchmark::RegisterBenchmark("spdlog::get(const std::string &name)", bench_get_logger_string);
|
||||||
|
@ -353,8 +353,7 @@ void replace_default_logger_example() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#include "spdlog/mdc.h"
|
#include "spdlog/mdc.h"
|
||||||
void mdc_example()
|
void mdc_example() {
|
||||||
{
|
|
||||||
spdlog::mdc::put("key1", "value1");
|
spdlog::mdc::put("key1", "value1");
|
||||||
spdlog::mdc::put("key2", "value2");
|
spdlog::mdc::put("key2", "value2");
|
||||||
// use the %& formatter flag to print all MDC values
|
// use the %& formatter flag to print all MDC values
|
||||||
|
@ -80,8 +80,7 @@ inline void init_thread_pool(size_t q_size, size_t thread_count, std::function<v
|
|||||||
}
|
}
|
||||||
|
|
||||||
inline void init_thread_pool(size_t q_size, size_t thread_count) {
|
inline void init_thread_pool(size_t q_size, size_t thread_count) {
|
||||||
init_thread_pool(
|
init_thread_pool(q_size, thread_count, [] {}, [] {});
|
||||||
q_size, thread_count, [] {}, [] {});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// get the global thread pool.
|
// get the global thread pool.
|
||||||
|
@ -69,7 +69,10 @@ public:
|
|||||||
periodic_flusher_ = std::make_unique<periodic_worker>(clbk, interval);
|
periodic_flusher_ = std::make_unique<periodic_worker>(clbk, interval);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::unique_ptr<periodic_worker> &get_flusher() { std::lock_guard<std::mutex> lock(flusher_mutex_); return periodic_flusher_; }
|
std::unique_ptr<periodic_worker> &get_flusher() {
|
||||||
|
std::lock_guard<std::mutex> lock(flusher_mutex_);
|
||||||
|
return periodic_flusher_;
|
||||||
|
}
|
||||||
|
|
||||||
void set_error_handler(err_handler handler);
|
void set_error_handler(err_handler handler);
|
||||||
|
|
||||||
|
@ -1,18 +1,16 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include <spdlog/common.h>
|
||||||
|
|
||||||
#include <map>
|
#include <map>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
#include <spdlog/common.h>
|
|
||||||
|
|
||||||
namespace spdlog {
|
namespace spdlog {
|
||||||
class SPDLOG_API mdc {
|
class SPDLOG_API mdc {
|
||||||
public:
|
public:
|
||||||
using mdc_map_t = std::map<std::string, std::string>;
|
using mdc_map_t = std::map<std::string, std::string>;
|
||||||
|
|
||||||
static void put(const std::string &key, const std::string &value) {
|
static void put(const std::string &key, const std::string &value) { get_context()[key] = value; }
|
||||||
get_context()[key] = value;
|
|
||||||
}
|
|
||||||
|
|
||||||
static std::string get(const std::string &key) {
|
static std::string get(const std::string &key) {
|
||||||
auto &context = get_context();
|
auto &context = get_context();
|
||||||
|
@ -170,8 +170,7 @@ protected:
|
|||||||
color_range_start, // color range start
|
color_range_start, // color range start
|
||||||
color_range_end}; // color range end
|
color_range_end}; // color range end
|
||||||
|
|
||||||
QMetaObject::invokeMethod(
|
QMetaObject::invokeMethod(qt_text_edit_, [params]() { invoke_method_(params); }, Qt::AutoConnection);
|
||||||
qt_text_edit_, [params]() { invoke_method_(params); }, Qt::AutoConnection);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void flush_() override {}
|
void flush_() override {}
|
||||||
|
@ -37,7 +37,9 @@ public:
|
|||||||
: start_tp_{clock::now()} {}
|
: start_tp_{clock::now()} {}
|
||||||
|
|
||||||
[[nodiscard]]
|
[[nodiscard]]
|
||||||
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_);
|
||||||
|
}
|
||||||
|
|
||||||
[[nodiscard]]
|
[[nodiscard]]
|
||||||
std::chrono::milliseconds elapsed_ms() const {
|
std::chrono::milliseconds elapsed_ms() const {
|
||||||
|
@ -80,8 +80,7 @@ namespace spdlog {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
auto found = loggers_.find(logger_name);
|
auto found = loggers_.find(logger_name);
|
||||||
return found == loggers_.end() ? nullptr : found->second;
|
return found == loggers_.end() ? nullptr : found->second;
|
||||||
}
|
}
|
||||||
@ -106,9 +105,7 @@ namespace spdlog {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
std::shared_ptr<logger> registry::get(const char *logger_name) {
|
std::shared_ptr<logger> registry::get(const char *logger_name) { return get(std::string_view(logger_name)); }
|
||||||
return get(std::string_view(logger_name));
|
|
||||||
}
|
|
||||||
|
|
||||||
std::shared_ptr<logger> registry::default_logger() {
|
std::shared_ptr<logger> registry::default_logger() {
|
||||||
std::lock_guard<std::mutex> lock(logger_map_mutex_);
|
std::lock_guard<std::mutex> lock(logger_map_mutex_);
|
||||||
|
@ -33,8 +33,7 @@ thread_pool::thread_pool(size_t q_max_items, size_t threads_n, std::function<voi
|
|||||||
: thread_pool(q_max_items, threads_n, 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)
|
thread_pool::thread_pool(size_t q_max_items, size_t threads_n)
|
||||||
: thread_pool(
|
: thread_pool(q_max_items, threads_n, [] {}, [] {}) {}
|
||||||
q_max_items, threads_n, [] {}, [] {}) {}
|
|
||||||
|
|
||||||
// message all threads to terminate gracefully join them
|
// message all threads to terminate gracefully join them
|
||||||
thread_pool::~thread_pool() {
|
thread_pool::~thread_pool() {
|
||||||
|
@ -3,6 +3,8 @@
|
|||||||
|
|
||||||
#include "spdlog/pattern_formatter.h"
|
#include "spdlog/pattern_formatter.h"
|
||||||
|
|
||||||
|
#include <spdlog/mdc.h>
|
||||||
|
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <array>
|
#include <array>
|
||||||
#include <cctype>
|
#include <cctype>
|
||||||
@ -16,7 +18,6 @@
|
|||||||
#include "spdlog/details/fmt_helper.h"
|
#include "spdlog/details/fmt_helper.h"
|
||||||
#include "spdlog/details/log_msg.h"
|
#include "spdlog/details/log_msg.h"
|
||||||
#include "spdlog/details/os.h"
|
#include "spdlog/details/os.h"
|
||||||
#include <spdlog/mdc.h>
|
|
||||||
#include "spdlog/fmt/fmt.h"
|
#include "spdlog/fmt/fmt.h"
|
||||||
#include "spdlog/formatter.h"
|
#include "spdlog/formatter.h"
|
||||||
|
|
||||||
@ -779,7 +780,6 @@ public:
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
// Full info formatter
|
// Full info formatter
|
||||||
// pattern: [%Y-%m-%d %H:%M:%S.%e] [%n] [%l] [%s:%#] %v
|
// pattern: [%Y-%m-%d %H:%M:%S.%e] [%n] [%l] [%s:%#] %v
|
||||||
class full_formatter final : public flag_formatter {
|
class full_formatter final : public flag_formatter {
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
#include "includes.h"
|
#include "includes.h"
|
||||||
|
#include "spdlog/mdc.h"
|
||||||
#include "spdlog/sinks/ostream_sink.h"
|
#include "spdlog/sinks/ostream_sink.h"
|
||||||
#include "test_sink.h"
|
#include "test_sink.h"
|
||||||
#include "spdlog/mdc.h"
|
|
||||||
|
|
||||||
using spdlog::memory_buf_t;
|
using spdlog::memory_buf_t;
|
||||||
using spdlog::details::to_string_view;
|
using spdlog::details::to_string_view;
|
||||||
@ -467,12 +467,10 @@ TEST_CASE("mdc formatter test-1", "[pattern_formatter]") {
|
|||||||
formatter->set_pattern("[%n] [%l] [%&] %v");
|
formatter->set_pattern("[%n] [%l] [%&] %v");
|
||||||
|
|
||||||
memory_buf_t formatted;
|
memory_buf_t formatted;
|
||||||
spdlog::details::log_msg msg(spdlog::source_loc{}, "logger-name", spdlog::level::info,
|
spdlog::details::log_msg msg(spdlog::source_loc{}, "logger-name", spdlog::level::info, "some message");
|
||||||
"some message");
|
|
||||||
formatter->format(msg, formatted);
|
formatter->format(msg, formatted);
|
||||||
|
|
||||||
auto expected = spdlog::fmt_lib::format(
|
auto expected = spdlog::fmt_lib::format("[logger-name] [info] [mdc_key_1:mdc_value_1 mdc_key_2:mdc_value_2] some message{}",
|
||||||
"[logger-name] [info] [mdc_key_1:mdc_value_1 mdc_key_2:mdc_value_2] some message{}",
|
|
||||||
spdlog::details::os::default_eol);
|
spdlog::details::os::default_eol);
|
||||||
REQUIRE(to_string_view(formatted) == expected);
|
REQUIRE(to_string_view(formatted) == expected);
|
||||||
|
|
||||||
@ -487,12 +485,10 @@ TEST_CASE("mdc formatter value update", "[pattern_formatter]") {
|
|||||||
formatter->set_pattern("[%n] [%l] [%&] %v");
|
formatter->set_pattern("[%n] [%l] [%&] %v");
|
||||||
|
|
||||||
memory_buf_t formatted_1;
|
memory_buf_t formatted_1;
|
||||||
spdlog::details::log_msg msg(spdlog::source_loc{}, "logger-name", spdlog::level::info,
|
spdlog::details::log_msg msg(spdlog::source_loc{}, "logger-name", spdlog::level::info, "some message");
|
||||||
"some message");
|
|
||||||
formatter->format(msg, formatted_1);
|
formatter->format(msg, formatted_1);
|
||||||
|
|
||||||
auto expected = spdlog::fmt_lib::format(
|
auto expected = spdlog::fmt_lib::format("[logger-name] [info] [mdc_key_1:mdc_value_1 mdc_key_2:mdc_value_2] some message{}",
|
||||||
"[logger-name] [info] [mdc_key_1:mdc_value_1 mdc_key_2:mdc_value_2] some message{}",
|
|
||||||
spdlog::details::os::default_eol);
|
spdlog::details::os::default_eol);
|
||||||
|
|
||||||
REQUIRE(to_string_view(formatted_1) == expected);
|
REQUIRE(to_string_view(formatted_1) == expected);
|
||||||
@ -500,8 +496,7 @@ TEST_CASE("mdc formatter value update", "[pattern_formatter]") {
|
|||||||
spdlog::mdc::put("mdc_key_1", "new_mdc_value_1");
|
spdlog::mdc::put("mdc_key_1", "new_mdc_value_1");
|
||||||
memory_buf_t formatted_2;
|
memory_buf_t formatted_2;
|
||||||
formatter->format(msg, formatted_2);
|
formatter->format(msg, formatted_2);
|
||||||
expected = spdlog::fmt_lib::format(
|
expected = spdlog::fmt_lib::format("[logger-name] [info] [mdc_key_1:new_mdc_value_1 mdc_key_2:mdc_value_2] some message{}",
|
||||||
"[logger-name] [info] [mdc_key_1:new_mdc_value_1 mdc_key_2:mdc_value_2] some message{}",
|
|
||||||
spdlog::details::os::default_eol);
|
spdlog::details::os::default_eol);
|
||||||
|
|
||||||
REQUIRE(to_string_view(formatted_2) == expected);
|
REQUIRE(to_string_view(formatted_2) == expected);
|
||||||
@ -512,8 +507,7 @@ TEST_CASE("mdc formatter value update", "[pattern_formatter]") {
|
|||||||
TEST_CASE("mdc different threads", "[pattern_formatter]") {
|
TEST_CASE("mdc different threads", "[pattern_formatter]") {
|
||||||
auto formatter = std::make_shared<spdlog::pattern_formatter>();
|
auto formatter = std::make_shared<spdlog::pattern_formatter>();
|
||||||
formatter->set_pattern("[%n] [%l] [%&] %v");
|
formatter->set_pattern("[%n] [%l] [%&] %v");
|
||||||
spdlog::details::log_msg msg(spdlog::source_loc{}, "logger-name", spdlog::level::info,
|
spdlog::details::log_msg msg(spdlog::source_loc{}, "logger-name", spdlog::level::info, "some message");
|
||||||
"some message");
|
|
||||||
|
|
||||||
memory_buf_t formatted_2;
|
memory_buf_t formatted_2;
|
||||||
|
|
||||||
@ -522,8 +516,7 @@ TEST_CASE("mdc different threads", "[pattern_formatter]") {
|
|||||||
memory_buf_t formatted;
|
memory_buf_t formatted;
|
||||||
formatter->format(msg, formatted);
|
formatter->format(msg, formatted);
|
||||||
|
|
||||||
auto expected =
|
auto expected = spdlog::fmt_lib::format("[logger-name] [info] [mdc_key:thread_1_id] some message{}",
|
||||||
spdlog::fmt_lib::format("[logger-name] [info] [mdc_key:thread_1_id] some message{}",
|
|
||||||
spdlog::details::os::default_eol);
|
spdlog::details::os::default_eol);
|
||||||
|
|
||||||
REQUIRE(to_string_view(formatted) == expected);
|
REQUIRE(to_string_view(formatted) == expected);
|
||||||
@ -534,8 +527,7 @@ TEST_CASE("mdc different threads", "[pattern_formatter]") {
|
|||||||
memory_buf_t formatted;
|
memory_buf_t formatted;
|
||||||
formatter->format(msg, formatted);
|
formatter->format(msg, formatted);
|
||||||
|
|
||||||
auto expected =
|
auto expected = spdlog::fmt_lib::format("[logger-name] [info] [mdc_key:thread_2_id] some message{}",
|
||||||
spdlog::fmt_lib::format("[logger-name] [info] [mdc_key:thread_2_id] some message{}",
|
|
||||||
spdlog::details::os::default_eol);
|
spdlog::details::os::default_eol);
|
||||||
|
|
||||||
REQUIRE(to_string_view(formatted) == expected);
|
REQUIRE(to_string_view(formatted) == expected);
|
||||||
@ -559,13 +551,11 @@ TEST_CASE("mdc remove key", "[pattern_formatter]") {
|
|||||||
formatter->set_pattern("[%n] [%l] [%&] %v");
|
formatter->set_pattern("[%n] [%l] [%&] %v");
|
||||||
|
|
||||||
memory_buf_t formatted;
|
memory_buf_t formatted;
|
||||||
spdlog::details::log_msg msg(spdlog::source_loc{}, "logger-name", spdlog::level::info,
|
spdlog::details::log_msg msg(spdlog::source_loc{}, "logger-name", spdlog::level::info, "some message");
|
||||||
"some message");
|
|
||||||
formatter->format(msg, formatted);
|
formatter->format(msg, formatted);
|
||||||
|
|
||||||
auto expected =
|
auto expected =
|
||||||
spdlog::fmt_lib::format("[logger-name] [info] [mdc_key_2:mdc_value_2] some message{}",
|
spdlog::fmt_lib::format("[logger-name] [info] [mdc_key_2:mdc_value_2] some message{}", spdlog::details::os::default_eol);
|
||||||
spdlog::details::os::default_eol);
|
|
||||||
REQUIRE(to_string_view(formatted) == expected);
|
REQUIRE(to_string_view(formatted) == expected);
|
||||||
|
|
||||||
SECTION("Tear down") { spdlog::mdc::clear(); }
|
SECTION("Tear down") { spdlog::mdc::clear(); }
|
||||||
@ -576,12 +566,10 @@ TEST_CASE("mdc empty", "[pattern_formatter]") {
|
|||||||
formatter->set_pattern("[%n] [%l] [%&] %v");
|
formatter->set_pattern("[%n] [%l] [%&] %v");
|
||||||
|
|
||||||
memory_buf_t formatted;
|
memory_buf_t formatted;
|
||||||
spdlog::details::log_msg msg(spdlog::source_loc{}, "logger-name", spdlog::level::info,
|
spdlog::details::log_msg msg(spdlog::source_loc{}, "logger-name", spdlog::level::info, "some message");
|
||||||
"some message");
|
|
||||||
formatter->format(msg, formatted);
|
formatter->format(msg, formatted);
|
||||||
|
|
||||||
auto expected = spdlog::fmt_lib::format("[logger-name] [info] [] some message{}",
|
auto expected = spdlog::fmt_lib::format("[logger-name] [info] [] some message{}", spdlog::details::os::default_eol);
|
||||||
spdlog::details::os::default_eol);
|
|
||||||
REQUIRE(to_string_view(formatted) == expected);
|
REQUIRE(to_string_view(formatted) == expected);
|
||||||
|
|
||||||
SECTION("Tear down") { spdlog::mdc::clear(); }
|
SECTION("Tear down") { spdlog::mdc::clear(); }
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
#include "includes.h"
|
|
||||||
#include <string_view>
|
#include <string_view>
|
||||||
|
|
||||||
|
#include "includes.h"
|
||||||
#include "spdlog/sinks/daily_file_sink.h"
|
#include "spdlog/sinks/daily_file_sink.h"
|
||||||
#include "spdlog/sinks/rotating_file_sink.h"
|
#include "spdlog/sinks/rotating_file_sink.h"
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user