What is needed to wire in ESPHome logging into an external .c component?
I have C code that I can run outside of ESPHome and use macros for logging. I want to use an #ifdef to use the native ESPHome logging when built as a component.
Something like this:
#pragma once
#ifdef ESP_LOGI
/* ESPHome / ESP-IDF environment: macros already defined, nothing to do */
#define SECPLUS_LOGD(tag, fmt, ...) ESP_LOGD(tag, fmt, ##__VA_ARGS__)
#define SECPLUS_LOGI(tag, fmt, ...) ESP_LOGI(tag, fmt, ##__VA_ARGS__)
#define SECPLUS_LOGW(tag, fmt, ...) ESP_LOGW(tag, fmt, ##__VA_ARGS__)
#define SECPLUS_LOGE(tag, fmt, ...) ESP_LOGE(tag, fmt, ##__VA_ARGS__)
#else
#include <stdio.h>
#define SECPLUS_LOGD(tag, fmt, ...) printf("[D][%s] " fmt "\n", tag, ##__VA_ARGS__)
#define SECPLUS_LOGI(tag, fmt, ...) printf("[I][%s] " fmt "\n", tag, ##__VA_ARGS__)
#define SECPLUS_LOGW(tag, fmt, ...) printf("[W][%s] " fmt "\n", tag, ##__VA_ARGS__)
#define SECPLUS_LOGE(tag, fmt, ...) printf("[E][%s] " fmt "\n", tag, ##__VA_ARGS__)
#endif
My C++ skills are very limited (I had to get AI to assist, so unclear if it's done "right") but never could get the logging working. Is it possible to bring the macros into the C code or maybe call the underlying logger code directly by passing a logger method into my C code?