mirror of
https://github.com/gabime/spdlog.git
synced 2024-11-15 16:35:45 +08:00
clang-format
This commit is contained in:
parent
15829cfb84
commit
06be4409e6
@ -80,7 +80,6 @@ void bench_dev_null() {
|
||||
|
||||
#endif // __linux__
|
||||
|
||||
|
||||
// test spdlog::get() performance
|
||||
// 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
|
||||
@ -201,7 +200,6 @@ int main(int argc, char *argv[]) {
|
||||
spdlog::async_overflow_policy::overrun_oldest);
|
||||
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(std::string_view name)", bench_get_logger_sv);
|
||||
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"
|
||||
void mdc_example()
|
||||
{
|
||||
void mdc_example() {
|
||||
spdlog::mdc::put("key1", "value1");
|
||||
spdlog::mdc::put("key2", "value2");
|
||||
// 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) {
|
||||
init_thread_pool(
|
||||
q_size, thread_count, [] {}, [] {});
|
||||
init_thread_pool(q_size, thread_count, [] {}, [] {});
|
||||
}
|
||||
|
||||
// get the global thread pool.
|
||||
|
@ -69,7 +69,10 @@ public:
|
||||
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);
|
||||
|
||||
|
@ -1,18 +1,16 @@
|
||||
#pragma once
|
||||
|
||||
#include <spdlog/common.h>
|
||||
|
||||
#include <map>
|
||||
#include <string>
|
||||
|
||||
#include <spdlog/common.h>
|
||||
|
||||
namespace spdlog {
|
||||
class SPDLOG_API mdc {
|
||||
public:
|
||||
using mdc_map_t = std::map<std::string, std::string>;
|
||||
|
||||
static void put(const std::string &key, const std::string &value) {
|
||||
get_context()[key] = value;
|
||||
}
|
||||
static void put(const std::string &key, const std::string &value) { get_context()[key] = value; }
|
||||
|
||||
static std::string get(const std::string &key) {
|
||||
auto &context = get_context();
|
||||
|
@ -170,8 +170,7 @@ protected:
|
||||
color_range_start, // color range start
|
||||
color_range_end}; // color range end
|
||||
|
||||
QMetaObject::invokeMethod(
|
||||
qt_text_edit_, [params]() { invoke_method_(params); }, Qt::AutoConnection);
|
||||
QMetaObject::invokeMethod(qt_text_edit_, [params]() { invoke_method_(params); }, Qt::AutoConnection);
|
||||
}
|
||||
|
||||
void flush_() override {}
|
||||
|
@ -37,7 +37,9 @@ public:
|
||||
: start_tp_{clock::now()} {}
|
||||
|
||||
[[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]]
|
||||
std::chrono::milliseconds elapsed_ms() const {
|
||||
|
@ -80,8 +80,7 @@ namespace spdlog {
|
||||
}
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
auto found = loggers_.find(logger_name);
|
||||
return found == loggers_.end() ? nullptr : found->second;
|
||||
}
|
||||
@ -106,9 +105,7 @@ namespace spdlog {
|
||||
}
|
||||
}
|
||||
|
||||
std::shared_ptr<logger> registry::get(const char *logger_name) {
|
||||
return get(std::string_view(logger_name));
|
||||
}
|
||||
std::shared_ptr<logger> registry::get(const char *logger_name) { return get(std::string_view(logger_name)); }
|
||||
|
||||
std::shared_ptr<logger> registry::default_logger() {
|
||||
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::thread_pool(size_t q_max_items, size_t threads_n)
|
||||
: thread_pool(
|
||||
q_max_items, threads_n, [] {}, [] {}) {}
|
||||
: thread_pool(q_max_items, threads_n, [] {}, [] {}) {}
|
||||
|
||||
// message all threads to terminate gracefully join them
|
||||
thread_pool::~thread_pool() {
|
||||
|
@ -3,6 +3,8 @@
|
||||
|
||||
#include "spdlog/pattern_formatter.h"
|
||||
|
||||
#include <spdlog/mdc.h>
|
||||
|
||||
#include <algorithm>
|
||||
#include <array>
|
||||
#include <cctype>
|
||||
@ -16,7 +18,6 @@
|
||||
#include "spdlog/details/fmt_helper.h"
|
||||
#include "spdlog/details/log_msg.h"
|
||||
#include "spdlog/details/os.h"
|
||||
#include <spdlog/mdc.h>
|
||||
#include "spdlog/fmt/fmt.h"
|
||||
#include "spdlog/formatter.h"
|
||||
|
||||
@ -779,7 +780,6 @@ public:
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
// Full info formatter
|
||||
// pattern: [%Y-%m-%d %H:%M:%S.%e] [%n] [%l] [%s:%#] %v
|
||||
class full_formatter final : public flag_formatter {
|
||||
|
@ -1,7 +1,7 @@
|
||||
#include "includes.h"
|
||||
#include "spdlog/mdc.h"
|
||||
#include "spdlog/sinks/ostream_sink.h"
|
||||
#include "test_sink.h"
|
||||
#include "spdlog/mdc.h"
|
||||
|
||||
using spdlog::memory_buf_t;
|
||||
using spdlog::details::to_string_view;
|
||||
@ -467,12 +467,10 @@ TEST_CASE("mdc formatter test-1", "[pattern_formatter]") {
|
||||
formatter->set_pattern("[%n] [%l] [%&] %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);
|
||||
|
||||
auto expected = spdlog::fmt_lib::format(
|
||||
"[logger-name] [info] [mdc_key_1:mdc_value_1 mdc_key_2:mdc_value_2] some message{}",
|
||||
auto expected = spdlog::fmt_lib::format("[logger-name] [info] [mdc_key_1:mdc_value_1 mdc_key_2:mdc_value_2] some message{}",
|
||||
spdlog::details::os::default_eol);
|
||||
REQUIRE(to_string_view(formatted) == expected);
|
||||
|
||||
@ -487,12 +485,10 @@ TEST_CASE("mdc formatter value update", "[pattern_formatter]") {
|
||||
formatter->set_pattern("[%n] [%l] [%&] %v");
|
||||
|
||||
memory_buf_t formatted_1;
|
||||
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_1);
|
||||
|
||||
auto expected = spdlog::fmt_lib::format(
|
||||
"[logger-name] [info] [mdc_key_1:mdc_value_1 mdc_key_2:mdc_value_2] some message{}",
|
||||
auto expected = spdlog::fmt_lib::format("[logger-name] [info] [mdc_key_1:mdc_value_1 mdc_key_2:mdc_value_2] some message{}",
|
||||
spdlog::details::os::default_eol);
|
||||
|
||||
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");
|
||||
memory_buf_t formatted_2;
|
||||
formatter->format(msg, formatted_2);
|
||||
expected = spdlog::fmt_lib::format(
|
||||
"[logger-name] [info] [mdc_key_1:new_mdc_value_1 mdc_key_2:mdc_value_2] some message{}",
|
||||
expected = spdlog::fmt_lib::format("[logger-name] [info] [mdc_key_1:new_mdc_value_1 mdc_key_2:mdc_value_2] some message{}",
|
||||
spdlog::details::os::default_eol);
|
||||
|
||||
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]") {
|
||||
auto formatter = std::make_shared<spdlog::pattern_formatter>();
|
||||
formatter->set_pattern("[%n] [%l] [%&] %v");
|
||||
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");
|
||||
|
||||
memory_buf_t formatted_2;
|
||||
|
||||
@ -522,8 +516,7 @@ TEST_CASE("mdc different threads", "[pattern_formatter]") {
|
||||
memory_buf_t formatted;
|
||||
formatter->format(msg, formatted);
|
||||
|
||||
auto expected =
|
||||
spdlog::fmt_lib::format("[logger-name] [info] [mdc_key:thread_1_id] some message{}",
|
||||
auto expected = spdlog::fmt_lib::format("[logger-name] [info] [mdc_key:thread_1_id] some message{}",
|
||||
spdlog::details::os::default_eol);
|
||||
|
||||
REQUIRE(to_string_view(formatted) == expected);
|
||||
@ -534,8 +527,7 @@ TEST_CASE("mdc different threads", "[pattern_formatter]") {
|
||||
memory_buf_t formatted;
|
||||
formatter->format(msg, formatted);
|
||||
|
||||
auto expected =
|
||||
spdlog::fmt_lib::format("[logger-name] [info] [mdc_key:thread_2_id] some message{}",
|
||||
auto expected = spdlog::fmt_lib::format("[logger-name] [info] [mdc_key:thread_2_id] some message{}",
|
||||
spdlog::details::os::default_eol);
|
||||
|
||||
REQUIRE(to_string_view(formatted) == expected);
|
||||
@ -559,13 +551,11 @@ TEST_CASE("mdc remove key", "[pattern_formatter]") {
|
||||
formatter->set_pattern("[%n] [%l] [%&] %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);
|
||||
|
||||
auto expected =
|
||||
spdlog::fmt_lib::format("[logger-name] [info] [mdc_key_2:mdc_value_2] some message{}",
|
||||
spdlog::details::os::default_eol);
|
||||
spdlog::fmt_lib::format("[logger-name] [info] [mdc_key_2:mdc_value_2] some message{}", spdlog::details::os::default_eol);
|
||||
REQUIRE(to_string_view(formatted) == expected);
|
||||
|
||||
SECTION("Tear down") { spdlog::mdc::clear(); }
|
||||
@ -576,12 +566,10 @@ TEST_CASE("mdc empty", "[pattern_formatter]") {
|
||||
formatter->set_pattern("[%n] [%l] [%&] %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);
|
||||
|
||||
auto expected = spdlog::fmt_lib::format("[logger-name] [info] [] some message{}",
|
||||
spdlog::details::os::default_eol);
|
||||
auto expected = spdlog::fmt_lib::format("[logger-name] [info] [] some message{}", spdlog::details::os::default_eol);
|
||||
REQUIRE(to_string_view(formatted) == expected);
|
||||
|
||||
SECTION("Tear down") { spdlog::mdc::clear(); }
|
||||
|
@ -1,5 +1,6 @@
|
||||
#include "includes.h"
|
||||
#include <string_view>
|
||||
|
||||
#include "includes.h"
|
||||
#include "spdlog/sinks/daily_file_sink.h"
|
||||
#include "spdlog/sinks/rotating_file_sink.h"
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user