mirror of
https://github.com/gabime/spdlog.git
synced 2025-09-30 02:19:35 +08:00
clang format
This commit is contained in:
@@ -48,8 +48,7 @@ struct async_factory_impl {
|
||||
}
|
||||
|
||||
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);
|
||||
auto new_logger = std::make_shared<async_logger>(std::move(logger_name), std::move(sink), std::move(tp), OverflowPolicy);
|
||||
registry_inst.initialize_logger(new_logger);
|
||||
return new_logger;
|
||||
}
|
||||
|
@@ -23,9 +23,9 @@ SPDLOG_API std::tm gmtime() noexcept;
|
||||
|
||||
// eol definition
|
||||
#ifdef _WIN32
|
||||
constexpr static const char *default_eol = "\r\n";
|
||||
constexpr static const char *default_eol = "\r\n";
|
||||
#else
|
||||
constexpr static const char *default_eol = "\n";
|
||||
constexpr static const char *default_eol = "\n";
|
||||
#endif
|
||||
|
||||
// folder separator
|
||||
|
@@ -75,8 +75,8 @@ public:
|
||||
}
|
||||
|
||||
int option_value = TX_BUFFER_SIZE;
|
||||
if (::setsockopt(socket_, SOL_SOCKET, SO_SNDBUF, reinterpret_cast<const char *>(&option_value),
|
||||
sizeof(option_value)) < 0) {
|
||||
if (::setsockopt(socket_, SOL_SOCKET, SO_SNDBUF, reinterpret_cast<const char *>(&option_value), sizeof(option_value)) <
|
||||
0) {
|
||||
int last_error = ::WSAGetLastError();
|
||||
cleanup_();
|
||||
throw_winsock_error_("error: setsockopt(SO_SNDBUF) Failed!", last_error);
|
||||
|
@@ -46,8 +46,8 @@ public:
|
||||
}
|
||||
|
||||
int option_value = TX_BUFFER_SIZE;
|
||||
if (::setsockopt(socket_, SOL_SOCKET, SO_SNDBUF, reinterpret_cast<const char *>(&option_value),
|
||||
sizeof(option_value)) < 0) {
|
||||
if (::setsockopt(socket_, SOL_SOCKET, SO_SNDBUF, reinterpret_cast<const char *>(&option_value), sizeof(option_value)) <
|
||||
0) {
|
||||
cleanup_();
|
||||
throw_spdlog_ex("error: setsockopt(SO_SNDBUF) Failed!");
|
||||
}
|
||||
|
@@ -61,8 +61,7 @@ private:
|
||||
|
||||
// create a dump_info that wraps the given container
|
||||
template <typename Container>
|
||||
inline details::dump_info<typename Container::const_iterator> to_hex(const Container &container,
|
||||
size_t size_per_line = 32) {
|
||||
inline details::dump_info<typename Container::const_iterator> to_hex(const Container &container, size_t size_per_line = 32) {
|
||||
static_assert(sizeof(typename Container::value_type) == 1, "sizeof(Container::value_type) != 1");
|
||||
using Iter = typename Container::const_iterator;
|
||||
return details::dump_info<Iter>(std::begin(container), std::end(container), size_per_line);
|
||||
@@ -139,8 +138,7 @@ struct formatter<spdlog::details::dump_info<T>, char> {
|
||||
|
||||
// format the given bytes range as hex
|
||||
template <typename FormatContext, typename Container>
|
||||
auto format(const spdlog::details::dump_info<Container> &the_range, FormatContext &ctx) const
|
||||
-> decltype(ctx.out()) {
|
||||
auto format(const spdlog::details::dump_info<Container> &the_range, FormatContext &ctx) const -> decltype(ctx.out()) {
|
||||
constexpr const char *hex_upper = "0123456789ABCDEF";
|
||||
constexpr const char *hex_lower = "0123456789abcdef";
|
||||
const char *hex_chars = use_uppercase ? hex_upper : hex_lower;
|
||||
|
@@ -19,9 +19,7 @@ namespace sinks {
|
||||
template <typename Mutex>
|
||||
class basic_file_sink final : public base_sink<Mutex> {
|
||||
public:
|
||||
explicit basic_file_sink(const filename_t &filename,
|
||||
bool truncate = false,
|
||||
const file_event_handlers &event_handlers = {});
|
||||
explicit basic_file_sink(const filename_t &filename, bool truncate = false, const file_event_handlers &event_handlers = {});
|
||||
const filename_t &filename() const;
|
||||
|
||||
protected:
|
||||
|
@@ -29,8 +29,8 @@ struct daily_filename_calculator {
|
||||
static filename_t calc_filename(const filename_t &filename, const tm &now_tm) {
|
||||
filename_t basename, ext;
|
||||
std::tie(basename, ext) = details::file_helper::split_by_extension(filename);
|
||||
return fmt_lib::format(SPDLOG_FILENAME_T("{}_{:04d}-{:02d}-{:02d}{}"), basename, now_tm.tm_year + 1900,
|
||||
now_tm.tm_mon + 1, now_tm.tm_mday, ext);
|
||||
return fmt_lib::format(SPDLOG_FILENAME_T("{}_{:04d}-{:02d}-{:02d}{}"), basename, now_tm.tm_year + 1900, now_tm.tm_mon + 1,
|
||||
now_tm.tm_mday, ext);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -214,8 +214,8 @@ inline std::shared_ptr<logger> daily_logger_format_mt(const std::string &logger_
|
||||
bool truncate = false,
|
||||
uint16_t max_files = 0,
|
||||
const file_event_handlers &event_handlers = {}) {
|
||||
return Factory::template create<sinks::daily_file_format_sink_mt>(logger_name, filename, hour, minute, truncate,
|
||||
max_files, event_handlers);
|
||||
return Factory::template create<sinks::daily_file_format_sink_mt>(logger_name, filename, hour, minute, truncate, max_files,
|
||||
event_handlers);
|
||||
}
|
||||
|
||||
template <typename Factory = spdlog::synchronous_factory>
|
||||
@@ -238,7 +238,7 @@ inline std::shared_ptr<logger> daily_logger_format_st(const std::string &logger_
|
||||
bool truncate = false,
|
||||
uint16_t max_files = 0,
|
||||
const file_event_handlers &event_handlers = {}) {
|
||||
return Factory::template create<sinks::daily_file_format_sink_st>(logger_name, filename, hour, minute, truncate,
|
||||
max_files, event_handlers);
|
||||
return Factory::template create<sinks::daily_file_format_sink_st>(logger_name, filename, hour, minute, truncate, max_files,
|
||||
event_handlers);
|
||||
}
|
||||
} // namespace spdlog
|
||||
|
@@ -40,8 +40,7 @@ template <typename Mutex>
|
||||
class dup_filter_sink : public dist_sink<Mutex> {
|
||||
public:
|
||||
template <class Rep, class Period>
|
||||
explicit dup_filter_sink(std::chrono::duration<Rep, Period> max_skip_duration,
|
||||
level notification_level = level::info)
|
||||
explicit dup_filter_sink(std::chrono::duration<Rep, Period> max_skip_duration, level notification_level = level::info)
|
||||
: max_skip_duration_{max_skip_duration},
|
||||
log_level_{notification_level} {}
|
||||
|
||||
@@ -62,8 +61,7 @@ protected:
|
||||
// log the "skipped.." message
|
||||
if (skip_counter_ > 0) {
|
||||
char buf[64];
|
||||
auto msg_size =
|
||||
::snprintf(buf, sizeof(buf), "Skipped %u duplicate messages..", static_cast<unsigned>(skip_counter_));
|
||||
auto msg_size = ::snprintf(buf, sizeof(buf), "Skipped %u duplicate messages..", static_cast<unsigned>(skip_counter_));
|
||||
if (msg_size > 0 && static_cast<size_t>(msg_size) < sizeof(buf)) {
|
||||
details::log_msg skipped_msg{msg.source, msg.logger_name, log_level_,
|
||||
string_view_t{buf, static_cast<size_t>(msg_size)}};
|
||||
|
@@ -173,8 +173,7 @@ inline std::shared_ptr<logger> hourly_logger_mt(const std::string &logger_name,
|
||||
bool truncate = false,
|
||||
uint16_t max_files = 0,
|
||||
const file_event_handlers &event_handlers = {}) {
|
||||
return Factory::template create<sinks::hourly_file_sink_mt>(logger_name, filename, truncate, max_files,
|
||||
event_handlers);
|
||||
return Factory::template create<sinks::hourly_file_sink_mt>(logger_name, filename, truncate, max_files, event_handlers);
|
||||
}
|
||||
|
||||
template <typename Factory = spdlog::synchronous_factory>
|
||||
@@ -183,7 +182,6 @@ inline std::shared_ptr<logger> hourly_logger_st(const std::string &logger_name,
|
||||
bool truncate = false,
|
||||
uint16_t max_files = 0,
|
||||
const file_event_handlers &event_handlers = {}) {
|
||||
return Factory::template create<sinks::hourly_file_sink_st>(logger_name, filename, truncate, max_files,
|
||||
event_handlers);
|
||||
return Factory::template create<sinks::hourly_file_sink_st>(logger_name, filename, truncate, max_files, event_handlers);
|
||||
}
|
||||
} // namespace spdlog
|
||||
|
@@ -71,8 +71,8 @@ public:
|
||||
|
||||
protected:
|
||||
void sink_it_(const details::log_msg &msg) override {
|
||||
producer_->produce(topic_.get(), 0, RdKafka::Producer::RK_MSG_COPY, (void *)msg.payload.data(),
|
||||
msg.payload.size(), NULL, NULL);
|
||||
producer_->produce(topic_.get(), 0, RdKafka::Producer::RK_MSG_COPY, (void *)msg.payload.data(), msg.payload.size(), NULL,
|
||||
NULL);
|
||||
}
|
||||
|
||||
void flush_() override { producer_->flush(config_.flush_timeout_ms); }
|
||||
@@ -91,26 +91,22 @@ using kafka_sink_st = kafka_sink<spdlog::details::null_mutex>;
|
||||
} // namespace sinks
|
||||
|
||||
template <typename Factory = spdlog::synchronous_factory>
|
||||
inline std::shared_ptr<logger> kafka_logger_mt(const std::string &logger_name,
|
||||
spdlog::sinks::kafka_sink_config config) {
|
||||
inline std::shared_ptr<logger> kafka_logger_mt(const std::string &logger_name, spdlog::sinks::kafka_sink_config config) {
|
||||
return Factory::template create<sinks::kafka_sink_mt>(logger_name, config);
|
||||
}
|
||||
|
||||
template <typename Factory = spdlog::synchronous_factory>
|
||||
inline std::shared_ptr<logger> kafka_logger_st(const std::string &logger_name,
|
||||
spdlog::sinks::kafka_sink_config config) {
|
||||
inline std::shared_ptr<logger> kafka_logger_st(const std::string &logger_name, spdlog::sinks::kafka_sink_config config) {
|
||||
return Factory::template create<sinks::kafka_sink_st>(logger_name, config);
|
||||
}
|
||||
|
||||
template <typename Factory = spdlog::async_factory>
|
||||
inline std::shared_ptr<spdlog::logger> kafka_logger_async_mt(std::string logger_name,
|
||||
spdlog::sinks::kafka_sink_config config) {
|
||||
inline std::shared_ptr<spdlog::logger> kafka_logger_async_mt(std::string logger_name, spdlog::sinks::kafka_sink_config config) {
|
||||
return Factory::template create<sinks::kafka_sink_mt>(logger_name, config);
|
||||
}
|
||||
|
||||
template <typename Factory = spdlog::async_factory>
|
||||
inline std::shared_ptr<spdlog::logger> kafka_logger_async_st(std::string logger_name,
|
||||
spdlog::sinks::kafka_sink_config config) {
|
||||
inline std::shared_ptr<spdlog::logger> kafka_logger_async_st(std::string logger_name, spdlog::sinks::kafka_sink_config config) {
|
||||
return Factory::template create<sinks::kafka_sink_st>(logger_name, config);
|
||||
}
|
||||
|
||||
|
@@ -58,8 +58,8 @@ protected:
|
||||
|
||||
if (client_ != nullptr) {
|
||||
auto doc = document{} << "timestamp" << bsoncxx::types::b_date(msg.time) << "level"
|
||||
<< level::to_string_view(msg.log_level).data() << "level_num" << msg.log_level
|
||||
<< "message" << std::string(msg.payload.begin(), msg.payload.end()) << "logger_name"
|
||||
<< level::to_string_view(msg.log_level).data() << "level_num" << msg.log_level << "message"
|
||||
<< std::string(msg.payload.begin(), msg.payload.end()) << "logger_name"
|
||||
<< std::string(msg.logger_name.begin(), msg.logger_name.end()) << "thread_id"
|
||||
<< static_cast<int>(msg.thread_id) << finalize;
|
||||
client_->database(db_name_).collection(coll_name_).insert_one(doc.view());
|
||||
|
@@ -43,9 +43,8 @@ protected:
|
||||
memory_buf_t formatted;
|
||||
base_sink<Mutex>::formatter_->format(msg, formatted);
|
||||
const string_view_t str = string_view_t(formatted.data(), formatted.size());
|
||||
QMetaObject::invokeMethod(
|
||||
qt_object_, meta_method_.c_str(), Qt::AutoConnection,
|
||||
Q_ARG(QString, QString::fromUtf8(str.data(), static_cast<int>(str.size())).trimmed()));
|
||||
QMetaObject::invokeMethod(qt_object_, meta_method_.c_str(), Qt::AutoConnection,
|
||||
Q_ARG(QString, QString::fromUtf8(str.data(), static_cast<int>(str.size())).trimmed()));
|
||||
}
|
||||
|
||||
void flush_() override {}
|
||||
@@ -206,8 +205,7 @@ protected:
|
||||
|
||||
// insert the colorized text
|
||||
cursor.setCharFormat(params.level_color);
|
||||
cursor.insertText(
|
||||
params.payload.mid(params.color_range_start, params.color_range_end - params.color_range_start));
|
||||
cursor.insertText(params.payload.mid(params.color_range_start, params.color_range_end - params.color_range_start));
|
||||
|
||||
// insert the text after the color range with default format
|
||||
cursor.setCharFormat(params.default_color);
|
||||
@@ -266,16 +264,12 @@ inline std::shared_ptr<logger> qt_logger_st(const std::string &logger_name,
|
||||
}
|
||||
// log to QObject
|
||||
template <typename Factory = spdlog::synchronous_factory>
|
||||
inline std::shared_ptr<logger> qt_logger_mt(const std::string &logger_name,
|
||||
QObject *qt_object,
|
||||
const std::string &meta_method) {
|
||||
inline std::shared_ptr<logger> qt_logger_mt(const std::string &logger_name, QObject *qt_object, const std::string &meta_method) {
|
||||
return Factory::template create<sinks::qt_sink_mt>(logger_name, qt_object, meta_method);
|
||||
}
|
||||
|
||||
template <typename Factory = spdlog::synchronous_factory>
|
||||
inline std::shared_ptr<logger> qt_logger_st(const std::string &logger_name,
|
||||
QObject *qt_object,
|
||||
const std::string &meta_method) {
|
||||
inline std::shared_ptr<logger> qt_logger_st(const std::string &logger_name, QObject *qt_object, const std::string &meta_method) {
|
||||
return Factory::template create<sinks::qt_sink_st>(logger_name, qt_object, meta_method);
|
||||
}
|
||||
|
||||
|
@@ -68,8 +68,8 @@ inline std::shared_ptr<logger> rotating_logger_mt(const std::string &logger_name
|
||||
size_t max_files,
|
||||
bool rotate_on_open = false,
|
||||
const file_event_handlers &event_handlers = {}) {
|
||||
return Factory::template create<sinks::rotating_file_sink_mt>(logger_name, filename, max_file_size, max_files,
|
||||
rotate_on_open, event_handlers);
|
||||
return Factory::template create<sinks::rotating_file_sink_mt>(logger_name, filename, max_file_size, max_files, rotate_on_open,
|
||||
event_handlers);
|
||||
}
|
||||
|
||||
template <typename Factory = spdlog::synchronous_factory>
|
||||
@@ -79,7 +79,7 @@ inline std::shared_ptr<logger> rotating_logger_st(const std::string &logger_name
|
||||
size_t max_files,
|
||||
bool rotate_on_open = false,
|
||||
const file_event_handlers &event_handlers = {}) {
|
||||
return Factory::template create<sinks::rotating_file_sink_st>(logger_name, filename, max_file_size, max_files,
|
||||
rotate_on_open, event_handlers);
|
||||
return Factory::template create<sinks::rotating_file_sink_st>(logger_name, filename, max_file_size, max_files, rotate_on_open,
|
||||
event_handlers);
|
||||
}
|
||||
} // namespace spdlog
|
||||
|
@@ -75,8 +75,8 @@ struct win32_error : public spdlog_ex {
|
||||
|
||||
local_alloc_t format_message_result{};
|
||||
auto format_message_succeeded = ::FormatMessageA(
|
||||
FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, nullptr,
|
||||
error_code, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), (LPSTR)&format_message_result.hlocal_, 0, nullptr);
|
||||
FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, nullptr, error_code,
|
||||
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), (LPSTR)&format_message_result.hlocal_, 0, nullptr);
|
||||
|
||||
if (format_message_succeeded && format_message_result.hlocal_) {
|
||||
system_message = fmt_lib::format(" ({})", (LPSTR)format_message_result.hlocal_);
|
||||
@@ -140,8 +140,7 @@ public:
|
||||
|
||||
// get user token
|
||||
std::vector<unsigned char> buffer(static_cast<size_t>(tusize));
|
||||
if (!::GetTokenInformation(current_process_token.token_handle_, TokenUser, (LPVOID)buffer.data(), tusize,
|
||||
&tusize)) {
|
||||
if (!::GetTokenInformation(current_process_token.token_handle_, TokenUser, (LPVOID)buffer.data(), tusize, &tusize)) {
|
||||
SPDLOG_THROW(win32_error("GetTokenInformation"));
|
||||
}
|
||||
|
||||
@@ -210,9 +209,9 @@ protected:
|
||||
formatted.push_back('\0');
|
||||
|
||||
LPCSTR lp_str = formatted.data();
|
||||
succeeded = static_cast<bool>(::ReportEventA(event_log_handle(), eventlog::get_event_type(msg),
|
||||
eventlog::get_event_category(msg), event_id_,
|
||||
current_user_sid_.as_sid(), 1, 0, &lp_str, nullptr));
|
||||
succeeded =
|
||||
static_cast<bool>(::ReportEventA(event_log_handle(), eventlog::get_event_type(msg), eventlog::get_event_category(msg),
|
||||
event_id_, current_user_sid_.as_sid(), 1, 0, &lp_str, nullptr));
|
||||
|
||||
if (!succeeded) {
|
||||
SPDLOG_THROW(win32_error("ReportEvent"));
|
||||
|
@@ -40,9 +40,7 @@ struct source_loc {
|
||||
static constexpr source_loc current() { return source_loc{}; }
|
||||
#endif
|
||||
|
||||
[[nodiscard]] constexpr bool empty() const noexcept {
|
||||
return line == 0 || filename == nullptr || short_filename == nullptr;
|
||||
}
|
||||
[[nodiscard]] constexpr bool empty() const noexcept { return line == 0 || filename == nullptr || short_filename == nullptr; }
|
||||
|
||||
const char *filename{nullptr};
|
||||
const char *short_filename{nullptr};
|
||||
|
Reference in New Issue
Block a user