martinzink commented on code in PR #1670: URL: https://github.com/apache/nifi-minifi-cpp/pull/1670#discussion_r1342392944
########## libminifi/include/core/logging/Logger.h: ########## @@ -234,33 +196,46 @@ class Logger : public BaseLogger { std::mutex mutex_; private: - template<typename ...Args> - inline void log(spdlog::level::level_enum level, const char* const format, Args&& ...args) { + std::string trimToMaxSizeAndAddId(std::string&& my_string) { + auto max_log_size = max_log_size_.load(); + if (max_log_size >= 0 && my_string.size() > gsl::narrow<size_t>(max_log_size)) + my_string = my_string.substr(0, max_log_size); + if (auto id = get_id()) { + my_string += *id; + } + return my_string; + } + + template<typename ...T> + std::string stringify(fmt::format_string<T...> fmt, T&&... args) { + auto log_message = fmt::format(fmt, std::forward<T>(args)...); + return trimToMaxSizeAndAddId(std::move(log_message)); + } + + template<typename ...T> + inline void log(spdlog::level::level_enum level, fmt::format_string<std::invoke_result_t<decltype(map_args), T>...> fmt, T&& ...args) { if (controller_ && !controller_->is_enabled()) - return; + return; std::lock_guard<std::mutex> lock(mutex_); if (!delegate_->should_log(level)) { return; } - auto str = format_string(max_log_size_.load(), format, conditional_stringify(std::forward<Args>(args))...); - if (const auto id = get_id()) { - str = str + *id; - } - delegate_->log(level, str); + delegate_->log(level, stringify(fmt, map_args(std::forward<T>(args))...)); } std::atomic<int> max_log_size_{LOG_BUFFER_SIZE}; }; +#define LOG_TRACE(x) LogBuilder((x).get(), org::apache::nifi::minifi::core::logging::LOG_LEVEL::trace) Review Comment: Good idea, I went ahead and removed them one by one in https://github.com/apache/nifi-minifi-cpp/pull/1670/commits/01496422e8b268ae92b80885c0b8920356b2e1fe https://github.com/apache/nifi-minifi-cpp/pull/1670/commits/6543335f37fa4181b1ac1fb7c509efe1f4601b9e https://github.com/apache/nifi-minifi-cpp/pull/1670/commits/71f7a0d0b88caee0980adbb58650c99580bf96c8 https://github.com/apache/nifi-minifi-cpp/pull/1670/commits/c09010115bc3e03d621a94527defde4a397a10c0 (some build and linter fixes followed these) -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: issues-unsubscr...@nifi.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org