Skip to content

Commit

Permalink
Merge branch 'gabime:v1.x' into v1.x
Browse files Browse the repository at this point in the history
  • Loading branch information
MaxwellGengYF authored Mar 7, 2024
2 parents cb4e9b4 + 5532231 commit 0374935
Show file tree
Hide file tree
Showing 10 changed files with 56 additions and 7 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ jobs:
- uses: actions/checkout@main
- name: Setup
run: |
apt-get update && apt-get install -y curl git pkg-config libsystemd-dev
apt-get update
apt-get install -y curl git pkg-config libsystemd-dev
CMAKE_VERSION="3.24.2"
curl -sSL https://github.com/Kitware/CMake/releases/download/v${CMAKE_VERSION}/cmake-${CMAKE_VERSION}-linux-x86_64.sh -o install-cmake.sh
chmod +x install-cmake.sh
Expand Down
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ endif()

set(CMAKE_CXX_EXTENSIONS OFF)

if(CMAKE_SYSTEM_NAME MATCHES "CYGWIN" OR CMAKE_SYSTEM_NAME MATCHES "MSYS")
if(CMAKE_SYSTEM_NAME MATCHES "CYGWIN" OR CMAKE_SYSTEM_NAME MATCHES "MSYS" OR CMAKE_SYSTEM_NAME MATCHES "MINGW")
set(CMAKE_CXX_EXTENSIONS ON)
endif()

Expand Down
1 change: 1 addition & 0 deletions include/spdlog/details/periodic_worker.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ class SPDLOG_API periodic_worker {
}
});
}
std::thread &get_thread() { return worker_thread_; }
periodic_worker(const periodic_worker &) = delete;
periodic_worker &operator=(const periodic_worker &) = delete;
// stop the worker thread and join it
Expand Down
16 changes: 16 additions & 0 deletions include/spdlog/details/registry-inl.h
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,22 @@ SPDLOG_INLINE std::shared_ptr<logger> registry::get(const std::string &logger_na
return found == loggers_.end() ? nullptr : found->second;
}

#if __cplusplus >= 201703L // C++17
SPDLOG_INLINE std::shared_ptr<logger> registry::get(std::string_view logger_name) {
std::lock_guard<std::mutex> lock(logger_map_mutex_);
for (const auto &[key, val] : loggers_) {
if (key == logger_name) {
return val;
}
}
return nullptr;
}

SPDLOG_INLINE std::shared_ptr<logger> registry::get(const char *logger_name) {
return get(std::string_view(logger_name));
}
#endif

SPDLOG_INLINE std::shared_ptr<logger> registry::default_logger() {
std::lock_guard<std::mutex> lock(logger_map_mutex_);
return default_logger_;
Expand Down
13 changes: 13 additions & 0 deletions include/spdlog/details/registry.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@
#include <string>
#include <unordered_map>

#if __cplusplus >= 201703L // C++17
#include <string_view>
#endif

namespace spdlog {
class logger;

Expand All @@ -33,6 +37,10 @@ class SPDLOG_API registry {
void register_logger(std::shared_ptr<logger> new_logger);
void initialize_logger(std::shared_ptr<logger> new_logger);
std::shared_ptr<logger> get(const std::string &logger_name);
#if __cplusplus >= 201703L // C++17
std::shared_ptr<logger> get(std::string_view logger_name);
std::shared_ptr<logger> get(const char *logger_name);
#endif
std::shared_ptr<logger> default_logger();

// Return raw ptr to the default logger.
Expand Down Expand Up @@ -68,6 +76,11 @@ class SPDLOG_API registry {
periodic_flusher_ = details::make_unique<periodic_worker>(clbk, interval);
}

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);

void apply_all(const std::function<void(const std::shared_ptr<logger>)> &fun);
Expand Down
6 changes: 3 additions & 3 deletions include/spdlog/sinks/qt_sinks.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#pragma once

//
// Custom sink for QPlainTextEdit or QTextEdit and its childs(QTextBrowser...
// Custom sink for QPlainTextEdit or QTextEdit and its children (QTextBrowser...
// etc) Building and using requires Qt library.
//
// Warning: the qt_sink won't be notified if the target widget is destroyed.
Expand Down Expand Up @@ -56,7 +56,7 @@ class qt_sink : public base_sink<Mutex> {
std::string meta_method_;
};

// QT color sink to QTextEdit.
// Qt color sink to QTextEdit.
// Color location is determined by the sink log pattern like in the rest of spdlog sinks.
// Colors can be modified if needed using sink->set_color(level, qtTextCharFormat).
// max_lines is the maximum number of lines that the sink will hold before removing the oldest
Expand Down Expand Up @@ -282,7 +282,7 @@ inline std::shared_ptr<logger> qt_logger_st(const std::string &logger_name,
return Factory::template create<sinks::qt_sink_st>(logger_name, qt_object, meta_method);
}

// log to QTextEdit with colorize output
// log to QTextEdit with colorized output
template <typename Factory = spdlog::synchronous_factory>
inline std::shared_ptr<logger> qt_color_logger_mt(const std::string &logger_name,
QTextEdit *qt_text_edit,
Expand Down
10 changes: 10 additions & 0 deletions include/spdlog/spdlog-inl.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,16 @@ SPDLOG_INLINE std::shared_ptr<logger> get(const std::string &name) {
return details::registry::instance().get(name);
}

#if __cplusplus >= 201703L // C++17
SPDLOG_INLINE std::shared_ptr<logger> get(std::string_view name) {
return details::registry::instance().get(name);
}

SPDLOG_INLINE std::shared_ptr<logger> get(const char *name) {
return details::registry::instance().get(name);
}
#endif

SPDLOG_INLINE void set_formatter(std::unique_ptr<spdlog::formatter> formatter) {
details::registry::instance().set_formatter(std::move(formatter));
}
Expand Down
8 changes: 8 additions & 0 deletions include/spdlog/spdlog.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@
#include <memory>
#include <string>

#if __cplusplus >= 201703L // C++17
#include <string_view>
#endif

namespace spdlog {

using default_factory = synchronous_factory;
Expand Down Expand Up @@ -50,6 +54,10 @@ SPDLOG_API void initialize_logger(std::shared_ptr<logger> logger);
// exist.
// example: spdlog::get("my_logger")->info("hello {}", "world");
SPDLOG_API std::shared_ptr<logger> get(const std::string &name);
#if __cplusplus >= 201703L // C++17
SPDLOG_API std::shared_ptr<logger> get(std::string_view name);
SPDLOG_API std::shared_ptr<logger> get(const char *name);
#endif

// Set global formatter. Each sink in each logger will get a clone of this object
SPDLOG_API void set_formatter(std::unique_ptr<spdlog::formatter> formatter);
Expand Down
2 changes: 1 addition & 1 deletion tests/test_errors.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class failing_sink : public spdlog::sinks::base_sink<std::mutex> {
};
struct custom_ex {};

#if !defined(SPDLOG_USE_STD_FORMAT) // std formt doesn't fully support tuntime strings
#if !defined(SPDLOG_USE_STD_FORMAT) // std format doesn't fully support runtime strings
TEST_CASE("default_error_handler", "[errors]") {
prepare_logdir();
spdlog::filename_t filename = SPDLOG_FILENAME_T(SIMPLE_LOG);
Expand Down
2 changes: 1 addition & 1 deletion tests/test_file_helper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ TEST_CASE("file_event_handlers", "[file_helper]") {
helper.reopen(true);
events.clear();
}
// make sure that the file_helper destrcutor calls the close callbacks if needed
// make sure that the file_helper destructor calls the close callbacks if needed
REQUIRE(events == std::vector<flags>{flags::before_close, flags::after_close});
REQUIRE(file_contents(TEST_FILENAME) == "after_open\nbefore_close\n");
}
Expand Down

0 comments on commit 0374935

Please sign in to comment.