From 30006e8c90ca5e34ac6675b7b251f461991e6db3 Mon Sep 17 00:00:00 2001 From: Jordan Zucker Date: Mon, 28 Oct 2024 10:35:47 -0700 Subject: [PATCH] And yet again --- esphome/components/loki/loki.cpp | 7 ++++++- esphome/components/loki/loki.h | 8 ++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/esphome/components/loki/loki.cpp b/esphome/components/loki/loki.cpp index dc8fcf039c..df301d50e2 100644 --- a/esphome/components/loki/loki.cpp +++ b/esphome/components/loki/loki.cpp @@ -11,7 +11,7 @@ static const char *TAG = "loki.component"; void LokiComponent::setup() { if (this->is_log_message_enabled() && logger::global_logger != nullptr) { logger::global_logger->add_on_log_callback([this](int level, const char *tag, const char *message) { - if (level <= this->log_level_ && this->is_connected()) { + if (level <= this->log_level_) { // this->publish({.topic = this->log_message_.topic, // .payload = message, // .qos = this->log_message_.qos, @@ -27,6 +27,11 @@ void LokiComponent::dump_config() { ESP_LOGCONFIG(TAG, "Loki component"); } float LokiComponent::get_setup_priority() const { return setup_priority::AFTER_WIFI; } +// Setters +void LokiComponent::disable_log_message() { this->log_message_ = ""; } +bool LokiComponent::is_log_message_enabled() const { return !this->log_message_.empty(); } +void LokiComponent::set_log_level(int level) { this->log_level_ = level; } + } // namespace loki } // namespace esphome #endif diff --git a/esphome/components/loki/loki.h b/esphome/components/loki/loki.h index d39bf15f3f..5b509e3479 100644 --- a/esphome/components/loki/loki.h +++ b/esphome/components/loki/loki.h @@ -14,6 +14,14 @@ class LokiComponent : public Component { void dump_config() override; /// Loki client setup priority float get_setup_priority() const override; + /// Logging specific + void set_log_level(int level); + /// Get the topic used for logging. Defaults to "/debug" and the value is cached for speed. + void disable_log_message(); + bool is_log_message_enabled() const; + std::string log_message_; + std::string payload_buffer_; + int log_level_{ESPHOME_LOG_LEVEL}; }; } // namespace loki