From e70c936813257a685afe4b1cf0dd69de6a404abb Mon Sep 17 00:00:00 2001 From: rwalker777 <49888088+rwalker777@users.noreply.github.com> Date: Wed, 8 Apr 2026 15:55:01 -0500 Subject: [PATCH] Add logger checks before logging in ProtocolFactory --- components/ups_hid/protocol_factory.cpp | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/components/ups_hid/protocol_factory.cpp b/components/ups_hid/protocol_factory.cpp index 6031018..f512b44 100644 --- a/components/ups_hid/protocol_factory.cpp +++ b/components/ups_hid/protocol_factory.cpp @@ -1,6 +1,7 @@ #include "protocol_factory.h" #include "ups_hid.h" #include "esphome/core/log.h" +#include "esphome/components/logger/logger.h" #include namespace esphome { @@ -25,8 +26,8 @@ void ProtocolFactory::ensure_initialized() { // Registries are initialized on first access due to static storage // This function exists for explicit initialization if needed static bool initialized = false; - if (!initialized) { - ESP_LOGD(FACTORY_TAG, "Protocol factory registries initialized"); + if (esphome::logger::global_logger != nullptr) + ESP_LOGD(FACTORY_TAG, "Protocol factory registries initialized"); initialized = true; } } @@ -44,8 +45,9 @@ void ProtocolFactory::register_protocol_for_vendor(uint16_t vendor_id, return a.priority > b.priority; }); - ESP_LOGI(FACTORY_TAG, "Registered protocol '%s' for vendor 0x%04X (priority %d)", - info.name.c_str(), vendor_id, info.priority); + if (esphome::logger::global_logger != nullptr) + ESP_LOGI(FACTORY_TAG, "Registered protocol '%s' for vendor 0x%04X (priority %d)", + info.name.c_str(), vendor_id, info.priority); } void ProtocolFactory::register_fallback_protocol(const ProtocolInfo& info) { @@ -60,8 +62,9 @@ void ProtocolFactory::register_fallback_protocol(const ProtocolInfo& info) { return a.priority > b.priority; }); - ESP_LOGI(FACTORY_TAG, "Registered fallback protocol '%s' (priority %d)", - info.name.c_str(), info.priority); + if (esphome::logger::global_logger != nullptr) + ESP_LOGI(FACTORY_TAG, "Registered fallback protocol '%s' (priority %d)", + info.name.c_str(), info.priority); } std::unique_ptr @@ -236,4 +239,4 @@ ProtocolFactory::create_by_name(const std::string& protocol_name, UpsHidComponen } } // namespace ups_hid -} // namespace esphome \ No newline at end of file +} // namespace esphome