diff --git a/examples/example_custom_tags.cpp b/examples/example_custom_tags.cpp index 2d687d71..f07a5f1a 100644 --- a/examples/example_custom_tags.cpp +++ b/examples/example_custom_tags.cpp @@ -43,6 +43,9 @@ static constexpr MyCustomTagsB custom_tags_b{"CUSTOM_TAG_B", 23}; static constexpr quill::utility::CombinedCustomTags custom_tags_ab{ custom_tags_a, custom_tags_b}; +static constexpr quill::utility::CombinedCustomTags custom_tags_ab_custom_format_delimiter{ + custom_tags_a, custom_tags_b, " -- "}; + int main() { // Set a custom formatter for stdout that prints the tags @@ -73,5 +76,6 @@ int main() LOG_WARNING_WITH_TAGS(logger, custom_tags_b, "Warning with custom tags"); LOG_ERROR_WITH_TAGS(logger, custom_tags_a, "Error with custom tags"); LOG_CRITICAL_WITH_TAGS(logger, custom_tags_ab, "Critical with combined custom tags"); + LOG_CRITICAL_WITH_TAGS(logger, custom_tags_ab_custom_format_delimiter, "Critical with combined custom tags custom delimiter"); LOG_CRITICAL(logger, "Critical without custom tags"); } diff --git a/quill/include/quill/Utility.h b/quill/include/quill/Utility.h index 11e3afac..1b588dab 100644 --- a/quill/include/quill/Utility.h +++ b/quill/include/quill/Utility.h @@ -7,11 +7,12 @@ #include #include +#include #include #include "quill/Fmt.h" -#include "quill/detail/misc/Common.h" #include "quill/detail/misc/Attributes.h" +#include "quill/detail/misc/Common.h" /** * Contains useful utilities to assist with logging @@ -64,14 +65,25 @@ template class CombinedCustomTags : public CustomTags { public: - constexpr CombinedCustomTags(TCustomTags... custom_tags) : _tags(std::move(custom_tags)...) {} + constexpr CombinedCustomTags(TCustomTags... custom_tags, std::string_view delim = ", ") + : _tags(std::move(custom_tags)...), _delim(delim) + { + } void format(std::string& out) const override { - std::apply([&out](const auto&... tags) { (((tags.format(out)), out.append(", ")), ...); }, _tags); + std::apply([&out, this](const auto&... tags) + { (((tags.format(out)), out.append(_delim.data())), ...); }, _tags); + + if (!out.empty()) + { + // erase last delim + out.erase(out.length() - _delim.length(), _delim.length()); + } } private: std::tuple _tags; + std::string_view _delim; }; } // namespace quill::utility \ No newline at end of file