This is an automated email from the ASF dual-hosted git repository. lordgamez pushed a commit to branch MINIFICPP-2502 in repository https://gitbox.apache.org/repos/asf/nifi-minifi-cpp.git
commit 37b3f3f3488e86678d108fe0c77efb3b782d5578 Author: Gabor Gyimesi <[email protected]> AuthorDate: Thu Feb 20 11:04:11 2025 +0100 Review update --- extensions/python/ExecutePythonProcessor.cpp | 4 ++-- libminifi/include/core/logging/LoggerBase.h | 4 ++-- libminifi/src/core/logging/LoggerBase.cpp | 8 ++++---- minifi-api/include/minifi-cpp/core/logging/Logger.h | 5 ++--- utils/src/core/Processor.cpp | 2 +- 5 files changed, 11 insertions(+), 12 deletions(-) diff --git a/extensions/python/ExecutePythonProcessor.cpp b/extensions/python/ExecutePythonProcessor.cpp index 29ae001db..836c6583b 100644 --- a/extensions/python/ExecutePythonProcessor.cpp +++ b/extensions/python/ExecutePythonProcessor.cpp @@ -282,8 +282,8 @@ std::vector<core::Relationship> ExecutePythonProcessor::getPythonRelationships() void ExecutePythonProcessor::setLoggerCallback(const std::function<void(core::logging::LOG_LEVEL level, const std::string& message)>& callback) { gsl_Expects(logger_ && python_logger_); - logger_->addLogCallback(callback); - python_logger_->addLogCallback(callback); + logger_->setLogCallback(callback); + python_logger_->setLogCallback(callback); } REGISTER_RESOURCE(ExecutePythonProcessor, Processor); diff --git a/libminifi/include/core/logging/LoggerBase.h b/libminifi/include/core/logging/LoggerBase.h index 29cd40ed5..ea0b10d6b 100644 --- a/libminifi/include/core/logging/LoggerBase.h +++ b/libminifi/include/core/logging/LoggerBase.h @@ -122,7 +122,7 @@ class LoggerBase : public Logger { bool should_log(LOG_LEVEL level) override; void log_string(LOG_LEVEL level, std::string str) override; LOG_LEVEL level() const override; - void addLogCallback(const std::function<void(LOG_LEVEL level, const std::string&)>& callback) override; + void setLogCallback(const std::function<void(LOG_LEVEL level, const std::string&)>& callback) override; protected: LoggerBase(std::shared_ptr<spdlog::logger> delegate, std::shared_ptr<LoggerControl> controller); @@ -140,7 +140,7 @@ class LoggerBase : public Logger { private: std::atomic<int> max_log_size_{LOG_BUFFER_SIZE}; - std::vector<std::function<void(LOG_LEVEL level, const std::string&)>> log_callbacks_; + std::function<void(LOG_LEVEL level, const std::string&)> log_callback_; }; } // namespace org::apache::nifi::minifi::core::logging diff --git a/libminifi/src/core/logging/LoggerBase.cpp b/libminifi/src/core/logging/LoggerBase.cpp index 9df1a890a..e90149b43 100644 --- a/libminifi/src/core/logging/LoggerBase.cpp +++ b/libminifi/src/core/logging/LoggerBase.cpp @@ -36,9 +36,9 @@ void LoggerControl::setEnabled(bool status) { is_enabled_ = status; } -void LoggerBase::addLogCallback(const std::function<void(LOG_LEVEL level, const std::string&)>& callback) { +void LoggerBase::setLogCallback(const std::function<void(LOG_LEVEL level, const std::string&)>& callback) { std::lock_guard<std::mutex> lock(mutex_); - log_callbacks_.push_back(callback); + log_callback_ = callback; } bool LoggerBase::should_log(LOG_LEVEL level) { @@ -50,8 +50,8 @@ bool LoggerBase::should_log(LOG_LEVEL level) { } void LoggerBase::log_string(LOG_LEVEL level, std::string str) { - for (const auto& callback : log_callbacks_) { - callback(level, str); + if (log_callback_) { + log_callback_(level, str); } delegate_->log(mapToSpdLogLevel(level), str.c_str()); } diff --git a/minifi-api/include/minifi-cpp/core/logging/Logger.h b/minifi-api/include/minifi-cpp/core/logging/Logger.h index d73681a91..e87f630d3 100644 --- a/minifi-api/include/minifi-cpp/core/logging/Logger.h +++ b/minifi-api/include/minifi-cpp/core/logging/Logger.h @@ -99,7 +99,7 @@ class Logger { virtual ~Logger() = default; - virtual void addLogCallback(const std::function<void(LOG_LEVEL level, const std::string&)>& callback) = 0; + virtual void setLogCallback(const std::function<void(LOG_LEVEL level, const std::string&)>& callback) = 0; protected: virtual int getMaxLogSize() = 0; @@ -126,8 +126,7 @@ class Logger { if (!should_log(level)) { return; } - auto message = stringify(std::move(fmt), map_args(std::forward<Args>(args))...); - log_string(level, message); + log_string(level, stringify(std::move(fmt), map_args(std::forward<Args>(args))...)); } }; diff --git a/utils/src/core/Processor.cpp b/utils/src/core/Processor.cpp index 41d665686..95feac9f8 100644 --- a/utils/src/core/Processor.cpp +++ b/utils/src/core/Processor.cpp @@ -370,7 +370,7 @@ std::chrono::steady_clock::duration ProcessorImpl::getYieldTime() const { } void ProcessorImpl::setLoggerCallback(const std::function<void(logging::LOG_LEVEL level, const std::string& message)>& callback) { - logger_->addLogCallback(callback); + logger_->setLogCallback(callback); } } // namespace org::apache::nifi::minifi::core
