diff --git a/CHANGELOG.md b/CHANGELOG.md index 61478326..d504e325 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -85,6 +85,8 @@ - Prevented error logs from the `SignalHandler` from being output to CSV files when a `CsvWriter` is in use. ([#588](https://github.com/odygrd/quill/issues/588)) - Implemented a workaround to resolve false positive warnings from `clang-tidy` on Windows. +- Added a new `create_or_get_logger` overload that accepts a `std::vector>`, improving flexibility + by allowing a variable number of sinks to be passed at runtime when creating a logger. ## v7.2.2 diff --git a/include/quill/Frontend.h b/include/quill/Frontend.h index 3340560b..8de8d13c 100644 --- a/include/quill/Frontend.h +++ b/include/quill/Frontend.h @@ -45,7 +45,7 @@ class FrontendImpl { auto const volatile spsc_queue_capacity = detail::get_local_thread_context() ->template get_spsc_queue() - .capacity(); + .capacity(); // On windows and c++17, QUILL_MAYBE_UNUSED won't work (void)spsc_queue_capacity; @@ -88,7 +88,8 @@ class FrontendImpl */ static logger_t* create_or_get_logger(std::string const& logger_name, std::shared_ptr sink, PatternFormatterOptions const& pattern_formatter_options = PatternFormatterOptions{}, - ClockSourceType clock_source = ClockSourceType::Tsc, UserClockSource* user_clock = nullptr) + ClockSourceType clock_source = ClockSourceType::Tsc, + UserClockSource* user_clock = nullptr) { std::vector> sinks; sinks.push_back(static_cast&&>(sink)); @@ -98,6 +99,26 @@ class FrontendImpl pattern_formatter_options, clock_source, user_clock)); } + /** + * @brief Creates a new logger or retrieves an existing one with the specified name and multiple sinks. + * + * @param logger_name The name of the logger. + * @param sinks A vector of shared pointers to sinks to associate with the logger. + * @param pattern_formatter_options Contains the formatting configuration for PatternFormatter + * @param clock_source The clock source for log timestamps. + * @param user_clock A pointer to a custom user clock. + * @return Logger* A pointer to the created or retrieved logger. + */ + static logger_t* create_or_get_logger( + std::string const& logger_name, std::vector> sinks, + PatternFormatterOptions const& pattern_formatter_options = PatternFormatterOptions{}, + ClockSourceType clock_source = ClockSourceType::Tsc, UserClockSource* user_clock = nullptr) + { + return _cast_to_logger(detail::LoggerManager::instance().create_or_get_logger( + logger_name, static_cast>&&>(sinks), + pattern_formatter_options, clock_source, user_clock)); + } + /** * @brief Creates a new logger or retrieves an existing one with the specified name and multiple sinks. * @@ -113,8 +134,8 @@ class FrontendImpl PatternFormatterOptions const& pattern_formatter_options = PatternFormatterOptions{}, ClockSourceType clock_source = ClockSourceType::Tsc, UserClockSource* user_clock = nullptr) { - return _cast_to_logger(detail::LoggerManager::instance().create_or_get_logger( - logger_name, std::vector>{sinks}, pattern_formatter_options, clock_source, user_clock)); + return create_or_get_logger(logger_name, std::vector>{sinks}, + pattern_formatter_options, clock_source, user_clock); } /** diff --git a/test/integration_tests/JsonMultilineMetadataTest.cpp b/test/integration_tests/JsonMultilineMetadataTest.cpp index c540426c..e2c705c7 100644 --- a/test/integration_tests/JsonMultilineMetadataTest.cpp +++ b/test/integration_tests/JsonMultilineMetadataTest.cpp @@ -54,8 +54,9 @@ TEST_CASE("json_multi_line_metadata") "%(message) %(caller_function)", "%H:%M:%S.%Qns", Timezone::LocalTime, true}); + std::vector> sinks_vec{json_file_sink, file_sink}; Logger* logger_b = Frontend::create_or_get_logger( - logger_name_b, std::initializer_list>{json_file_sink, file_sink}, + logger_name_b, std::move(sinks_vec), PatternFormatterOptions{ "%(time) [%(thread_id)] %(short_source_location:<28) LOG_%(log_level:<9) %(logger:<12) " "%(message) %(caller_function)",