code format

This commit is contained in:
gabime
2025-01-17 20:59:46 +02:00
parent b9f0243405
commit 47fe6ef92a
23 changed files with 68 additions and 76 deletions

View File

@@ -6,7 +6,6 @@
namespace spdlog {
namespace details {
async_log_msg::async_log_msg(const type type)
: msg_type_{type} {}
@@ -15,21 +14,25 @@ async_log_msg::async_log_msg(const type type)
// are compiler generated const chars* (__FILE__, __LINE__, __FUNCTION__)
// if you pass custom strings to source location, make sure they outlive the async_log_msg
async_log_msg::async_log_msg(const type type, const log_msg &orig_msg)
: log_msg{orig_msg}, msg_type_(type) {
: log_msg{orig_msg},
msg_type_(type) {
buffer_.append(logger_name);
buffer_.append(payload);
update_string_views();
}
async_log_msg::async_log_msg(const async_log_msg &other)
: log_msg{other}, msg_type_{other.msg_type_} {
: log_msg{other},
msg_type_{other.msg_type_} {
buffer_.append(logger_name);
buffer_.append(payload);
update_string_views();
}
async_log_msg::async_log_msg(async_log_msg &&other) noexcept
: log_msg{other}, msg_type_{other.msg_type_}, buffer_{std::move(other.buffer_)} {
: log_msg{other},
msg_type_{other.msg_type_},
buffer_{std::move(other.buffer_)} {
update_string_views();
}

View File

@@ -109,7 +109,6 @@ template <typename Mutex>
ansicolor_stderr_sink<Mutex>::ansicolor_stderr_sink(color_mode mode)
: ansicolor_sink<Mutex>(stderr, mode) {}
} // namespace sinks
} // namespace spdlog

View File

@@ -33,26 +33,21 @@ async_sink::async_sink(config async_config)
});
}
async_sink::~async_sink() {
try {
q_->enqueue(async_log_msg(async_log_msg::type::terminate));
worker_thread_.join();
} catch (...) {
terminate_worker_ = true; // as last resort, stop the worker thread using terminate_worker_ flag.
#ifndef NDEBUG
printf("Exception in ~async_sink()\n");
#endif
terminate_worker_ = true; // as last resort, stop the worker thread using terminate_worker_ flag.
#ifndef NDEBUG
printf("Exception in ~async_sink()\n");
#endif
}
}
void async_sink::log(const details::log_msg &msg) {
enqueue_message_(async_log_msg(async_log_msg::type::log, msg));
}
void async_sink::log(const details::log_msg &msg) { enqueue_message_(async_log_msg(async_log_msg::type::log, msg)); }
void async_sink::flush() {
enqueue_message_(details::async_log_msg(async_log_msg::type::flush));
}
void async_sink::flush() { enqueue_message_(details::async_log_msg(async_log_msg::type::flush)); }
void async_sink::set_pattern(const std::string &pattern) { set_formatter(std::make_unique<pattern_formatter>(pattern)); }
@@ -83,7 +78,8 @@ bool async_sink::wait_all(const std::chrono::milliseconds timeout) const {
}
void async_sink::wait_all() const {
while (!wait_all(std::chrono::milliseconds(10))) { /* empty */ }
while (!wait_all(std::chrono::milliseconds(10))) { /* empty */
}
}
size_t async_sink::get_overrun_counter() const { return q_->overrun_counter(); }

View File

@@ -5,6 +5,7 @@
#include <memory>
#include <mutex>
#include "spdlog/common.h"
#include "spdlog/pattern_formatter.h"
@@ -53,8 +54,8 @@ void base_sink<Mutex>::set_formatter_(std::unique_ptr<formatter> sink_formatter)
formatter_ = std::move(sink_formatter);
}
} // namespace sinks
} // namespace spdlog
} // namespace sinks
} // namespace spdlog
// template instantiations
#include "spdlog/details/null_mutex.h"

View File

@@ -2,9 +2,11 @@
// Distributed under the MIT License (http://opensource.org/licenses/MIT)
#include "spdlog/sinks/basic_file_sink.h"
#include "spdlog/common.h"
#include <mutex>
#include "spdlog/common.h"
namespace spdlog {
namespace sinks {
@@ -34,7 +36,6 @@ void basic_file_sink<Mutex>::flush_() {
} // namespace sinks
} // namespace spdlog
// template instantiations
#include "spdlog/details/null_mutex.h"
template class SPDLOG_API spdlog::sinks::basic_file_sink<std::mutex>;

View File

@@ -8,6 +8,7 @@
// clang-format on
#include "spdlog/sinks/wincolor_sink.h"
#include "spdlog/common.h"
namespace spdlog {
@@ -131,7 +132,6 @@ template <typename Mutex>
wincolor_stderr_sink<Mutex>::wincolor_stderr_sink(color_mode mode)
: wincolor_sink<Mutex>(::GetStdHandle(STD_ERROR_HANDLE), mode) {}
} // namespace sinks
} // namespace spdlog

View File

@@ -13,21 +13,17 @@
namespace spdlog {
#ifndef SPDLOG_DISABLE_GLOBAL_LOGGER
static std::shared_ptr<logger> s_logger = std::make_shared<logger>("", std::make_shared<sinks::stdout_color_sink_mt>());
static std::shared_ptr<logger> s_logger = std::make_shared<logger>("", std::make_shared<sinks::stdout_color_sink_mt>());
#else
static std::short_ptr<logger> s_logger = nullptr;
static std::short_ptr<logger> s_logger = nullptr;
#endif
std::shared_ptr<logger> global_logger() { return s_logger; }
void set_global_logger(std::shared_ptr<logger> global_logger) { s_logger = std::move(global_logger); }
logger *global_logger_raw() noexcept {
return s_logger.get();
}
logger *global_logger_raw() noexcept { return s_logger.get(); }
void set_formatter(std::unique_ptr<formatter> formatter) { global_logger()->set_formatter(std::move(formatter)); }