mirror of
https://github.com/esphome/esphome.git
synced 2024-11-30 18:54:14 +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() {
|
void LokiComponent::setup() {
|
||||||
if (this->is_log_message_enabled() && logger::global_logger != nullptr) {
|
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) {
|
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,
|
// this->publish({.topic = this->log_message_.topic,
|
||||||
// .payload = message,
|
// .payload = message,
|
||||||
// .qos = this->log_message_.qos,
|
// .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; }
|
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 loki
|
||||||
} // namespace esphome
|
} // namespace esphome
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -14,6 +14,14 @@ class LokiComponent : public Component {
|
||||||
void dump_config() override;
|
void dump_config() override;
|
||||||
/// Loki client setup priority
|
/// Loki client setup priority
|
||||||
float get_setup_priority() const override;
|
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
|
} // namespace loki
|
||||||
|
|
Loading…
Reference in a new issue