Skip to content

Commit

Permalink
Only copy the log string when the callback has been set
Browse files Browse the repository at this point in the history
Signed-off-by: Wilco den Besten <[email protected]>
  • Loading branch information
WilcodenBesten committed Dec 16, 2024
1 parent 0ae4ea8 commit 9f75036
Showing 1 changed file with 5 additions and 7 deletions.
12 changes: 5 additions & 7 deletions lib/ocpp/common/ocpp_logging.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -281,19 +281,17 @@ MessageLogging::~MessageLogging() {
}

void MessageLogging::charge_point(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(0, 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->charge_point(message_type, copy_json_str);
logging->charge_point(message_type, effective_json_str);
}
}
}
Expand Down

0 comments on commit 9f75036

Please sign in to comment.