1
0
mirror of https://github.com/esphome/esphome.git synced 2025-09-25 06:32:22 +01:00

Logger on_message trigger (#729)

* on_message

* Lint fix

* Lint fix (2)

* Lint fix (<3)

* Replace cg.int_ with int

* Revert

* Removed strdup


Co-authored-by: Otto Winter <otto@otto-winter.com>
This commit is contained in:
Nikolay Vasilchuk
2019-10-24 15:19:33 +03:00
committed by Otto Winter
parent 4c49beb3c7
commit e4f055597c
4 changed files with 33 additions and 2 deletions

View File

@@ -1,5 +1,6 @@
#pragma once
#include "esphome/core/automation.h"
#include "esphome/core/component.h"
#include "esphome/core/log.h"
#include "esphome/core/helpers.h"
@@ -114,6 +115,21 @@ class Logger : public Component {
extern Logger *global_logger;
class LoggerMessageTrigger : public Trigger<int, const char *, const char *> {
public:
explicit LoggerMessageTrigger(Logger *parent, int level) {
this->level_ = level;
parent->add_on_log_callback([this](int level, const char *tag, const char *message) {
if (level <= this->level_) {
this->trigger(level, tag, message);
}
});
}
protected:
int level_;
};
} // namespace logger
} // namespace esphome