diff --git a/lib/ocpp/common/ocpp_logging.cpp b/lib/ocpp/common/ocpp_logging.cpp index 14905fe59..1c4b48d4d 100644 --- a/lib/ocpp/common/ocpp_logging.cpp +++ b/lib/ocpp/common/ocpp_logging.cpp @@ -297,19 +297,17 @@ void MessageLogging::charge_point(const std::string& message_type, const std::st } void MessageLogging::central_system(const std::string& message_type, const std::string& json_str) { - std::string copy_json_str = json_str; - if (this->sanitize_message_callback != nullptr) { - copy_json_str = this->sanitize_message_callback(copy_json_str); - } + const std::string& effective_json_str = + (this->sanitize_message_callback != nullptr) ? this->sanitize_message_callback(json_str) : json_str; if (this->message_callback != nullptr) { - this->message_callback(copy_json_str, MessageDirection::ChargingStationToCSMS); + this->message_callback(effective_json_str, MessageDirection::ChargingStationToCSMS); } - auto formatted = format_message(message_type, copy_json_str); + auto formatted = format_message(message_type, effective_json_str); log_output(1, formatted.message_type, formatted.message); if (this->session_logging) { std::scoped_lock lock(this->session_id_logging_mutex); for (auto const& [session_id, logging] : this->session_id_logging) { - logging->central_system(message_type, copy_json_str); + logging->central_system(message_type, effective_json_str); } } }