clang format

This commit is contained in:
gabime 2024-11-29 13:40:40 +02:00
parent eacd4d6b2a
commit 62534f2e4e
13 changed files with 41 additions and 43 deletions

View File

@ -247,7 +247,7 @@ void multi_sink_example() {
struct my_type { struct my_type {
int i = 0; int i = 0;
explicit my_type(int i) explicit my_type(int i)
: i(i){} : i(i) {}
}; };
#ifndef SPDLOG_USE_STD_FORMAT // when using fmtlib #ifndef SPDLOG_USE_STD_FORMAT // when using fmtlib

View File

@ -159,7 +159,7 @@ using atomic_level_t = std::atomic<level>;
constexpr auto levels_count = level_to_number(level::n_levels); constexpr auto levels_count = level_to_number(level::n_levels);
constexpr std::array<std::string_view, levels_count> level_string_views{"trace", "debug", "info", "warning", constexpr std::array<std::string_view, levels_count> level_string_views{"trace", "debug", "info", "warning",
"error", "critical", "off"}; "error", "critical", "off"};
constexpr std::array<std::string_view, levels_count> short_level_names{"T", "D", "I", "W", "E", "C", "O"}; constexpr std::array<std::string_view, levels_count> short_level_names{"T", "D", "I", "W", "E", "C", "O"};
[[nodiscard]] constexpr std::string_view to_string_view(spdlog::level lvl) noexcept { [[nodiscard]] constexpr std::string_view to_string_view(spdlog::level lvl) noexcept {

View File

@ -15,25 +15,25 @@
// formatted data, and support for different format per sink. // formatted data, and support for different format per sink.
#include <cassert> #include <cassert>
#include <vector>
#include <iterator> #include <iterator>
#include <vector>
#include "./common.h" #include "./common.h"
#include "./details/log_msg.h" #include "./details/log_msg.h"
#include "./sinks/sink.h" #include "./sinks/sink.h"
#ifndef SPDLOG_NO_EXCEPTIONS #ifndef SPDLOG_NO_EXCEPTIONS
#define SPDLOG_LOGGER_CATCH(location) \ #define SPDLOG_LOGGER_CATCH(location) \
catch (const std::exception &ex) { \ catch (const std::exception &ex) { \
if (!location.empty()) { \ if (!location.empty()) { \
err_handler_(fmt_lib::format(SPDLOG_FMT_STRING("{} [{}({})]"), ex.what(), location.filename, location.line)); \ err_handler_(fmt_lib::format(SPDLOG_FMT_STRING("{} [{}({})]"), ex.what(), location.filename, location.line)); \
} else { \ } else { \
err_handler_(ex.what()); \ err_handler_(ex.what()); \
} \ } \
} \ } \
catch (...) { \ catch (...) { \
err_handler_("Rethrowing unknown exception in logger"); \ err_handler_("Rethrowing unknown exception in logger"); \
throw; \ throw; \
} }
#else #else
#define SPDLOG_LOGGER_CATCH(location) #define SPDLOG_LOGGER_CATCH(location)

View File

@ -15,9 +15,9 @@
#include "../details/fmt_helper.h" #include "../details/fmt_helper.h"
#include "../details/null_mutex.h" #include "../details/null_mutex.h"
#include "../details/os.h"
#include "../details/synchronous_factory.h" #include "../details/synchronous_factory.h"
#include "./base_sink.h" #include "./base_sink.h"
#include "../details/os.h"
#if !defined(SPDLOG_ANDROID_RETRIES) #if !defined(SPDLOG_ANDROID_RETRIES)
#define SPDLOG_ANDROID_RETRIES 2 #define SPDLOG_ANDROID_RETRIES 2

View File

@ -40,17 +40,17 @@ using basic_file_sink_st = basic_file_sink<details::null_mutex>;
// //
template <typename Factory = spdlog::synchronous_factory> template <typename Factory = spdlog::synchronous_factory>
std::shared_ptr<logger> basic_logger_mt(const std::string &logger_name, std::shared_ptr<logger> basic_logger_mt(const std::string &logger_name,
const filename_t &filename, const filename_t &filename,
bool truncate = false, bool truncate = false,
const file_event_handlers &event_handlers = {}) { const file_event_handlers &event_handlers = {}) {
return Factory::template create<sinks::basic_file_sink_mt>(logger_name, filename, truncate, event_handlers); return Factory::template create<sinks::basic_file_sink_mt>(logger_name, filename, truncate, event_handlers);
} }
template <typename Factory = spdlog::synchronous_factory> template <typename Factory = spdlog::synchronous_factory>
std::shared_ptr<logger> basic_logger_st(const std::string &logger_name, std::shared_ptr<logger> basic_logger_st(const std::string &logger_name,
const filename_t &filename, const filename_t &filename,
bool truncate = false, bool truncate = false,
const file_event_handlers &event_handlers = {}) { const file_event_handlers &event_handlers = {}) {
return Factory::template create<sinks::basic_file_sink_st>(logger_name, filename, truncate, event_handlers); return Factory::template create<sinks::basic_file_sink_st>(logger_name, filename, truncate, event_handlers);
} }

View File

@ -27,7 +27,7 @@ public:
protected: protected:
void sink_it_(const details::log_msg &msg) override { callback_(msg); } void sink_it_(const details::log_msg &msg) override { callback_(msg); }
void flush_() override{} void flush_() override {}
private: private:
custom_log_callback callback_; custom_log_callback callback_;

View File

@ -29,8 +29,8 @@ struct daily_filename_calculator {
static filename_t calc_filename(const filename_t &filename, const tm &now_tm) { static filename_t calc_filename(const filename_t &filename, const tm &now_tm) {
filename_t basename, ext; filename_t basename, ext;
std::tie(basename, ext) = details::file_helper::split_by_extension(filename); std::tie(basename, ext) = details::file_helper::split_by_extension(filename);
return fmt_lib::format(SPDLOG_FMT_STRING(SPDLOG_FILENAME_T("{}_{:04d}-{:02d}-{:02d}{}")), basename, now_tm.tm_year + 1900, now_tm.tm_mon + 1, return fmt_lib::format(SPDLOG_FMT_STRING(SPDLOG_FILENAME_T("{}_{:04d}-{:02d}-{:02d}{}")), basename, now_tm.tm_year + 1900,
now_tm.tm_mday, ext); now_tm.tm_mon + 1, now_tm.tm_mday, ext);
} }
}; };

View File

@ -6,10 +6,10 @@
#include <spdlog/details/null_mutex.h> #include <spdlog/details/null_mutex.h>
#include <spdlog/details/synchronous_factory.h> #include <spdlog/details/synchronous_factory.h>
#include <spdlog/sinks/base_sink.h> #include <spdlog/sinks/base_sink.h>
#include <syslog.h>
#include <array> #include <array>
#include <string> #include <string>
#include <syslog.h>
namespace spdlog { namespace spdlog {
namespace sinks { namespace sinks {
@ -88,8 +88,8 @@ inline std::shared_ptr<logger> syslog_logger_mt(const std::string &logger_name,
int syslog_option = 0, int syslog_option = 0,
int syslog_facility = LOG_USER, int syslog_facility = LOG_USER,
bool enable_formatting = false) { bool enable_formatting = false) {
return Factory::template create<sinks::syslog_sink_mt>(logger_name, syslog_ident, syslog_option, return Factory::template create<sinks::syslog_sink_mt>(logger_name, syslog_ident, syslog_option, syslog_facility,
syslog_facility, enable_formatting); enable_formatting);
} }
template <typename Factory = spdlog::synchronous_factory> template <typename Factory = spdlog::synchronous_factory>
@ -98,7 +98,7 @@ inline std::shared_ptr<logger> syslog_logger_st(const std::string &logger_name,
int syslog_option = 0, int syslog_option = 0,
int syslog_facility = LOG_USER, int syslog_facility = LOG_USER,
bool enable_formatting = false) { bool enable_formatting = false) {
return Factory::template create<sinks::syslog_sink_st>(logger_name, syslog_ident, syslog_option, return Factory::template create<sinks::syslog_sink_st>(logger_name, syslog_ident, syslog_option, syslog_facility,
syslog_facility, enable_formatting); enable_formatting);
} }
} // namespace spdlog } // namespace spdlog

View File

@ -206,9 +206,8 @@ inline void critical(std::string_view msg) { log(level::critical, msg); }
#ifndef SPDLOG_NO_SOURCE_LOC #ifndef SPDLOG_NO_SOURCE_LOC
#define SPDLOG_LOGGER_CALL(logger, level, ...) \ #define SPDLOG_LOGGER_CALL(logger, level, ...) \
(logger)->log(spdlog::source_loc{__FILE__, __LINE__, SPDLOG_FUNCTION}, level, __VA_ARGS__) (logger)->log(spdlog::source_loc{__FILE__, __LINE__, SPDLOG_FUNCTION}, level, __VA_ARGS__)
#else #else
#define SPDLOG_LOGGER_CALL(logger, level, ...) \ #define SPDLOG_LOGGER_CALL(logger, level, ...) (logger)->log(spdlog::source_loc{}, level, __VA_ARGS__)
(logger)->log(spdlog::source_loc{}, level, __VA_ARGS__)
#endif #endif
#if SPDLOG_ACTIVE_LEVEL <= SPDLOG_LEVEL_TRACE #if SPDLOG_ACTIVE_LEVEL <= SPDLOG_LEVEL_TRACE

View File

@ -75,11 +75,11 @@ TEST_CASE("dir_name", "[create_dir]") {
#ifdef _WIN32 #ifdef _WIN32
// //
// test windows cases when drive letter is given e.g. C:\\some-folder // test windows cases when drive letter is given e.g. C:\\some-folder
// //
#include <windows.h> #include <fileapi.h>
#include <fileapi.h> #include <windows.h>
std::string get_full_path(const std::string &relative_folder_path) { std::string get_full_path(const std::string &relative_folder_path) {
char full_path[MAX_PATH]; char full_path[MAX_PATH];
@ -100,7 +100,7 @@ spdlog::filename_t::value_type find_non_existing_drive() {
std::string root_path = std::string(1, drive) + ":\\"; std::string root_path = std::string(1, drive) + ":\\";
UINT drive_type = GetDriveTypeA(root_path.c_str()); UINT drive_type = GetDriveTypeA(root_path.c_str());
if (drive_type == DRIVE_NO_ROOT_DIR) { if (drive_type == DRIVE_NO_ROOT_DIR) {
return static_cast <spdlog::filename_t::value_type>(drive); return static_cast<spdlog::filename_t::value_type>(drive);
} }
} }
return '\0'; // No available drive found return '\0'; // No available drive found
@ -125,11 +125,10 @@ TEST_CASE("non_existing_drive", "[create_dir]") {
spdlog::filename_t path; spdlog::filename_t path;
auto non_existing_drive = find_non_existing_drive(); auto non_existing_drive = find_non_existing_drive();
path += non_existing_drive ; path += non_existing_drive;
path += SPDLOG_FILENAME_T(":\\"); path += SPDLOG_FILENAME_T(":\\");
REQUIRE(create_dir(path) == false); REQUIRE(create_dir(path) == false);
path += SPDLOG_FILENAME_T("subdir"); path += SPDLOG_FILENAME_T("subdir");
REQUIRE(create_dir(path) == false); REQUIRE(create_dir(path) == false);
} }
#endif // _WIN32 #endif // _WIN32

View File

@ -1,5 +1,5 @@
#ifndef SPDLOG_NO_SOURCE_LOC #ifndef SPDLOG_NO_SOURCE_LOC
#define SPDLOG_NO_SOURCE_LOC #define SPDLOG_NO_SOURCE_LOC
#endif #endif
#include "includes.h" #include "includes.h"

View File

@ -10,9 +10,9 @@
#include <thread> #include <thread>
#include "spdlog/details/null_mutex.h" #include "spdlog/details/null_mutex.h"
#include "spdlog/details/os.h"
#include "spdlog/fmt/fmt.h" #include "spdlog/fmt/fmt.h"
#include "spdlog/sinks/base_sink.h" #include "spdlog/sinks/base_sink.h"
#include "spdlog/details/os.h"
namespace spdlog { namespace spdlog {
namespace sinks { namespace sinks {

View File

@ -1,5 +1,5 @@
#ifdef SPDLOG_NO_SOURCE_LOC #ifdef SPDLOG_NO_SOURCE_LOC
#undef SPDLOG_NO_SOURCE_LOC #undef SPDLOG_NO_SOURCE_LOC
#endif #endif
#include "includes.h" #include "includes.h"