mirror of
https://github.com/esphome/esphome.git
synced 2024-11-30 10:44:13 +01:00
And yet again
This commit is contained in:
parent
779f5b6962
commit
30006e8c90
2 changed files with 14 additions and 1 deletions
|
@ -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
|
||||
|
|
|
@ -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 "<topic_prefix>/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
|
||||
|
|
Loading…
Reference in a new issue