Public Access
Add logger checks before logging in ProtocolFactory
This commit is contained in:
1 parent
a71b90cf3e
commit
e70c936813
1 file changed
+4
-1
@@ -1,6 +1,7 @@
|
|||||||
#include "protocol_factory.h"
|
#include "protocol_factory.h"
|
||||||
#include "ups_hid.h"
|
#include "ups_hid.h"
|
||||||
#include "esphome/core/log.h"
|
#include "esphome/core/log.h"
|
||||||
|
#include "esphome/components/logger/logger.h"
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
|
|
||||||
namespace esphome {
|
namespace esphome {
|
||||||
@@ -25,7 +26,7 @@ void ProtocolFactory::ensure_initialized() {
|
|||||||
// Registries are initialized on first access due to static storage
|
// Registries are initialized on first access due to static storage
|
||||||
// This function exists for explicit initialization if needed
|
// This function exists for explicit initialization if needed
|
||||||
static bool initialized = false;
|
static bool initialized = false;
|
||||||
if (!initialized) {
|
if (esphome::logger::global_logger != nullptr)
|
||||||
ESP_LOGD(FACTORY_TAG, "Protocol factory registries initialized");
|
ESP_LOGD(FACTORY_TAG, "Protocol factory registries initialized");
|
||||||
initialized = true;
|
initialized = true;
|
||||||
}
|
}
|
||||||
@@ -44,6 +45,7 @@ void ProtocolFactory::register_protocol_for_vendor(uint16_t vendor_id,
|
|||||||
return a.priority > b.priority;
|
return a.priority > b.priority;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
if (esphome::logger::global_logger != nullptr)
|
||||||
ESP_LOGI(FACTORY_TAG, "Registered protocol '%s' for vendor 0x%04X (priority %d)",
|
ESP_LOGI(FACTORY_TAG, "Registered protocol '%s' for vendor 0x%04X (priority %d)",
|
||||||
info.name.c_str(), vendor_id, info.priority);
|
info.name.c_str(), vendor_id, info.priority);
|
||||||
}
|
}
|
||||||
@@ -60,6 +62,7 @@ void ProtocolFactory::register_fallback_protocol(const ProtocolInfo& info) {
|
|||||||
return a.priority > b.priority;
|
return a.priority > b.priority;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
if (esphome::logger::global_logger != nullptr)
|
||||||
ESP_LOGI(FACTORY_TAG, "Registered fallback protocol '%s' (priority %d)",
|
ESP_LOGI(FACTORY_TAG, "Registered fallback protocol '%s' (priority %d)",
|
||||||
info.name.c_str(), info.priority);
|
info.name.c_str(), info.priority);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user