Skip to content

Commit

Permalink
Clang format
Browse files Browse the repository at this point in the history
  • Loading branch information
gabime committed Apr 30, 2024
1 parent 37b8476 commit 22b0f4f
Show file tree
Hide file tree
Showing 12 changed files with 54 additions and 62 deletions.
2 changes: 1 addition & 1 deletion include/spdlog/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@
#if FMT_USE_CONSTEXPR
#define SPDLOG_CONSTEXPR_FUNC FMT_CONSTEXPR
#else
#define SPDLOG_CONSTEXPR_FUNC inline
#define SPDLOG_CONSTEXPR_FUNC inline
#endif
#endif

Expand Down
2 changes: 1 addition & 1 deletion include/spdlog/details/file_helper-inl.h
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ SPDLOG_INLINE void file_helper::close() {
}

SPDLOG_INLINE void file_helper::write(const memory_buf_t &buf) {
if(fd_ == nullptr) return;
if (fd_ == nullptr) return;
size_t msg_size = buf.size();
auto data = buf.data();
if (std::fwrite(data, 1, msg_size, fd_) != msg_size) {
Expand Down
2 changes: 1 addition & 1 deletion include/spdlog/details/os-inl.h
Original file line number Diff line number Diff line change
Expand Up @@ -535,7 +535,7 @@ SPDLOG_INLINE bool create_dir(const filename_t &path) {

auto subdir = path.substr(0, token_pos);
#ifdef _WIN32
// if subdir is just a drive letter, add a slash e.g. "c:"=>"c:\",
// if subdir is just a drive letter, add a slash e.g. "c:"=>"c:\",
// otherwise path_exists(subdir) returns false (issue #3079)
const bool is_drive = subdir.length() == 2 && subdir[1] == ':';
if (is_drive) {
Expand Down
3 changes: 1 addition & 2 deletions include/spdlog/details/registry-inl.h
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,6 @@ SPDLOG_INLINE std::shared_ptr<logger> registry::get(const std::string &logger_na
return found == loggers_.end() ? nullptr : found->second;
}


SPDLOG_INLINE std::shared_ptr<logger> registry::default_logger() {
std::lock_guard<std::mutex> lock(logger_map_mutex_);
return default_logger_;
Expand All @@ -99,7 +98,7 @@ SPDLOG_INLINE logger *registry::get_default_raw() { return default_logger_.get()
// set default logger.
// default logger is stored in default_logger_ (for faster retrieval) and in the loggers_ map.
SPDLOG_INLINE void registry::set_default_logger(std::shared_ptr<logger> new_default_logger) {
std::lock_guard<std::mutex> lock(logger_map_mutex_);
std::lock_guard<std::mutex> lock(logger_map_mutex_);
if (new_default_logger != nullptr) {
loggers_[new_default_logger->name()] = new_default_logger;
}
Expand Down
7 changes: 4 additions & 3 deletions include/spdlog/details/registry.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ class SPDLOG_API registry {

// set default logger and add it to the registry if not registered already.
// default logger is stored in default_logger_ (for faster retrieval) and in the loggers_ map.
// Note: Make sure to unregister it when no longer needed or before calling again with a new logger.
// Note: Make sure to unregister it when no longer needed or before calling again with a new
// logger.
void set_default_logger(std::shared_ptr<logger> new_default_logger);

void set_tp(std::shared_ptr<thread_pool> tp);
Expand All @@ -70,8 +71,8 @@ class SPDLOG_API registry {
}

std::unique_ptr<periodic_worker> &get_flusher() {
std::lock_guard<std::mutex> lock(flusher_mutex_);
return periodic_flusher_;
std::lock_guard<std::mutex> lock(flusher_mutex_);
return periodic_flusher_;
}

void set_error_handler(err_handler handler);
Expand Down
4 changes: 1 addition & 3 deletions include/spdlog/details/thread_pool.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,7 @@ struct async_msg : log_msg_buffer {
worker_ptr{std::move(worker)},
flush_promise{} {}

async_msg(async_logger_ptr &&worker,
async_msg_type the_type,
std::promise<void> &&promise)
async_msg(async_logger_ptr &&worker, async_msg_type the_type, std::promise<void> &&promise)
: log_msg_buffer{},
msg_type{the_type},
worker_ptr{std::move(worker)},
Expand Down
2 changes: 1 addition & 1 deletion include/spdlog/fmt/fmt.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
#ifndef FMT_USE_WINDOWS_H
#define FMT_USE_WINDOWS_H 0
#endif

#include <spdlog/fmt/bundled/core.h>
#include <spdlog/fmt/bundled/format.h>

Expand Down
44 changes: 22 additions & 22 deletions include/spdlog/mdc.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,31 +6,31 @@
#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 std::string get(const std::string &key) {
auto &context = get_context();
auto it = context.find(key);
if (it != context.end()) {
return it->second;
}
return "";
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 std::string get(const std::string &key) {
auto &context = get_context();
auto it = context.find(key);
if (it != context.end()) {
return it->second;
}
return "";
}

static void remove(const std::string &key) { get_context().erase(key); }
static void remove(const std::string &key) { get_context().erase(key); }

static void clear() { get_context().clear(); }
static void clear() { get_context().clear(); }

static mdc_map_t &get_context() {
static thread_local mdc_map_t context;
return context;
}
};
static mdc_map_t &get_context() {
static thread_local mdc_map_t context;
return context;
}
};

} // namespace spdlog
8 changes: 2 additions & 6 deletions include/spdlog/pattern_formatter-inl.h
Original file line number Diff line number Diff line change
Expand Up @@ -790,7 +790,7 @@ template <typename ScopedPadder>
class mdc_formatter : public flag_formatter {
public:
explicit mdc_formatter(padding_info padinfo)
: flag_formatter(padinfo) {}
: flag_formatter(padinfo) {}

void format(const details::log_msg &, const std::tm &, memory_buf_t &dest) override {
auto &mdc_map = mdc::get_context();
Expand All @@ -802,7 +802,7 @@ class mdc_formatter : public flag_formatter {
}
}

void format_mdc(const mdc::mdc_map_t &mdc_map, memory_buf_t &dest){
void format_mdc(const mdc::mdc_map_t &mdc_map, memory_buf_t &dest) {
auto last_element = --mdc_map.end();
for (auto it = mdc_map.begin(); it != mdc_map.end(); ++it) {
auto &pair = *it;
Expand All @@ -825,8 +825,6 @@ class mdc_formatter : public flag_formatter {
}
};



// Full info formatter
// pattern: [%Y-%m-%d %H:%M:%S.%e] [%n] [%l] [%s:%#] %v
class full_formatter final : public flag_formatter {
Expand Down Expand Up @@ -921,8 +919,6 @@ class full_formatter final : public flag_formatter {
mdc_formatter<null_scoped_padder> mdc_formatter_{padding_info{}};
};



} // namespace details

SPDLOG_INLINE pattern_formatter::pattern_formatter(std::string pattern,
Expand Down
1 change: 0 additions & 1 deletion include/spdlog/spdlog-inl.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ SPDLOG_INLINE std::shared_ptr<logger> get(const std::string &name) {
return details::registry::instance().get(name);
}


SPDLOG_INLINE void set_formatter(std::unique_ptr<spdlog::formatter> formatter) {
details::registry::instance().set_formatter(std::move(formatter));
}
Expand Down
4 changes: 2 additions & 2 deletions tests/test_async.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -132,8 +132,8 @@ TEST_CASE("multithread flush", "[async]") {
}
REQUIRE(test_sink->flush_counter() >= 1);
REQUIRE(test_sink->flush_counter() + errmsgs.size() == n_threads * flush_count);
if (errmsgs.size() > 0) {
REQUIRE(errmsgs[0] == "Broken promise");
if (errmsgs.size() > 0) {
REQUIRE(errmsgs[0] == "Broken promise");
}
}

Expand Down
37 changes: 18 additions & 19 deletions tests/test_create_dir.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,23 +84,23 @@ TEST_CASE("dir_name", "[create_dir]") {

#ifdef _WIN32

//
// test windows cases when drive letter is given e.g. C:\\some-folder
//
#include <windows.h>
#include <fileapi.h>
//
// test windows cases when drive letter is given e.g. C:\\some-folder
//
#include <windows.h>
#include <fileapi.h>

std::string get_full_path(const std::string &relative_folder_path) {
char full_path[MAX_PATH];

DWORD result = ::GetFullPathNameA(relative_folder_path.c_str(), MAX_PATH, full_path, nullptr);
// Return an empty string if failed to get full path
return result > 0 && result < MAX_PATH ? std::string(full_path) : std::string();
return result > 0 && result < MAX_PATH ? std::string(full_path) : std::string();
}

std::wstring get_full_path(const std::wstring &relative_folder_path) {
wchar_t full_path[MAX_PATH];
DWORD result = ::GetFullPathNameW(relative_folder_path.c_str(), MAX_PATH, full_path, nullptr);
DWORD result = ::GetFullPathNameW(relative_folder_path.c_str(), MAX_PATH, full_path, nullptr);
return result > 0 && result < MAX_PATH ? std::wstring(full_path) : std::wstring();
}

Expand All @@ -109,37 +109,36 @@ spdlog::filename_t::value_type find_non_existing_drive() {
std::string root_path = std::string(1, drive) + ":\\";
UINT drive_type = GetDriveTypeA(root_path.c_str());
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
}

TEST_CASE("create_abs_path1", "[create_dir]") {
prepare_logdir();
prepare_logdir();
auto abs_path = get_full_path(SPDLOG_FILENAME_T("test_logs\\logdir1"));
REQUIRE(!abs_path.empty());
REQUIRE(!abs_path.empty());
REQUIRE(create_dir(abs_path) == true);
}

TEST_CASE("create_abs_path2", "[create_dir]") {
prepare_logdir();
auto abs_path = get_full_path(SPDLOG_FILENAME_T("test_logs/logdir2"));
REQUIRE(!abs_path.empty());
REQUIRE(create_dir(abs_path) == true);
REQUIRE(create_dir(abs_path) == true);
}

TEST_CASE("non_existing_drive", "[create_dir]") {
prepare_logdir();
TEST_CASE("non_existing_drive", "[create_dir]") {
prepare_logdir();
spdlog::filename_t path;

auto non_existing_drive = find_non_existing_drive();
path += non_existing_drive ;
path += SPDLOG_FILENAME_T(":\\");
REQUIRE(create_dir(path) == false);
path += non_existing_drive;
path += SPDLOG_FILENAME_T(":\\");
REQUIRE(create_dir(path) == false);
path += SPDLOG_FILENAME_T("subdir");
REQUIRE(create_dir(path) == false);

}
//#endif // SPDLOG_WCHAR_FILENAMES
// #endif // SPDLOG_WCHAR_FILENAMES
#endif // _WIN32

0 comments on commit 22b0f4f

Please sign in to comment.