mirror of
https://github.com/esphome/esphome.git
synced 2025-08-03 08:57:47 +00:00
Merge branch 'logger_strlen' into integration
This commit is contained in:
commit
67e1a92cce
@ -1459,7 +1459,7 @@ void APIConnection::update_command(const UpdateCommandRequest &msg) {
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
bool APIConnection::try_send_log_message(int level, const char *tag, const char *line, size_t line_length) {
|
bool APIConnection::try_send_log_message(int level, const char *tag, const char *line, size_t message_len) {
|
||||||
if (this->flags_.log_subscription < level)
|
if (this->flags_.log_subscription < level)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
@ -1472,14 +1472,14 @@ bool APIConnection::try_send_log_message(int level, const char *tag, const char
|
|||||||
|
|
||||||
// Add size for string field (field ID 3, string type)
|
// Add size for string field (field ID 3, string type)
|
||||||
// 1 byte for field tag + size of length varint + string length
|
// 1 byte for field tag + size of length varint + string length
|
||||||
msg_size += 1 + api::ProtoSize::varint(static_cast<uint32_t>(line_length)) + line_length;
|
msg_size += 1 + api::ProtoSize::varint(static_cast<uint32_t>(message_len)) + message_len;
|
||||||
|
|
||||||
// Create a pre-sized buffer
|
// Create a pre-sized buffer
|
||||||
auto buffer = this->create_buffer(msg_size);
|
auto buffer = this->create_buffer(msg_size);
|
||||||
|
|
||||||
// Encode the message (SubscribeLogsResponse)
|
// Encode the message (SubscribeLogsResponse)
|
||||||
buffer.encode_uint32(1, static_cast<uint32_t>(level)); // LogLevel level = 1
|
buffer.encode_uint32(1, static_cast<uint32_t>(level)); // LogLevel level = 1
|
||||||
buffer.encode_string(3, line, line_length); // string message = 3
|
buffer.encode_string(3, line, message_len); // string message = 3
|
||||||
|
|
||||||
// SubscribeLogsResponse - 29
|
// SubscribeLogsResponse - 29
|
||||||
return this->send_buffer(buffer, SubscribeLogsResponse::MESSAGE_TYPE);
|
return this->send_buffer(buffer, SubscribeLogsResponse::MESSAGE_TYPE);
|
||||||
|
@ -107,7 +107,7 @@ class APIConnection : public APIServerConnection {
|
|||||||
bool send_media_player_state(media_player::MediaPlayer *media_player);
|
bool send_media_player_state(media_player::MediaPlayer *media_player);
|
||||||
void media_player_command(const MediaPlayerCommandRequest &msg) override;
|
void media_player_command(const MediaPlayerCommandRequest &msg) override;
|
||||||
#endif
|
#endif
|
||||||
bool try_send_log_message(int level, const char *tag, const char *line, size_t line_length);
|
bool try_send_log_message(int level, const char *tag, const char *line, size_t message_len);
|
||||||
void send_homeassistant_service_call(const HomeassistantServiceResponse &call) {
|
void send_homeassistant_service_call(const HomeassistantServiceResponse &call) {
|
||||||
if (!this->flags_.service_call_subscription)
|
if (!this->flags_.service_call_subscription)
|
||||||
return;
|
return;
|
||||||
|
@ -186,7 +186,7 @@ void Logger::loop() {
|
|||||||
this->tx_buffer_size_);
|
this->tx_buffer_size_);
|
||||||
this->write_footer_to_buffer_(this->tx_buffer_, &this->tx_buffer_at_, this->tx_buffer_size_);
|
this->write_footer_to_buffer_(this->tx_buffer_, &this->tx_buffer_at_, this->tx_buffer_size_);
|
||||||
this->tx_buffer_[this->tx_buffer_at_] = '\0';
|
this->tx_buffer_[this->tx_buffer_at_] = '\0';
|
||||||
size_t msg_len = strlen(this->tx_buffer_); // Need strlen here since we don't store length in queued messages
|
size_t msg_len = this->tx_buffer_at_; // We already know the length from tx_buffer_at_
|
||||||
this->log_callback_.call(message->level, message->tag, this->tx_buffer_, msg_len);
|
this->log_callback_.call(message->level, message->tag, this->tx_buffer_, msg_len);
|
||||||
// At this point all the data we need from message has been transferred to the tx_buffer
|
// At this point all the data we need from message has been transferred to the tx_buffer
|
||||||
// so we can release the message to allow other tasks to use it as soon as possible.
|
// so we can release the message to allow other tasks to use it as soon as possible.
|
||||||
|
@ -36,7 +36,7 @@ void Syslog::log_(const int level, const char *tag, const char *message, size_t
|
|||||||
}
|
}
|
||||||
int pri = this->facility_ * 8 + severity;
|
int pri = this->facility_ * 8 + severity;
|
||||||
auto timestamp = this->time_->now().strftime("%b %d %H:%M:%S");
|
auto timestamp = this->time_->now().strftime("%b %d %H:%M:%S");
|
||||||
unsigned len = message_len;
|
size_t len = message_len;
|
||||||
// remove color formatting
|
// remove color formatting
|
||||||
if (this->strip_ && message[0] == 0x1B && len > 11) {
|
if (this->strip_ && message[0] == 0x1B && len > 11) {
|
||||||
message += 7;
|
message += 7;
|
||||||
|
@ -288,6 +288,7 @@ void WebServer::setup() {
|
|||||||
logger::global_logger->add_on_log_callback(
|
logger::global_logger->add_on_log_callback(
|
||||||
// logs are not deferred, the memory overhead would be too large
|
// logs are not deferred, the memory overhead would be too large
|
||||||
[this](int level, const char *tag, const char *message, size_t message_len) {
|
[this](int level, const char *tag, const char *message, size_t message_len) {
|
||||||
|
(void)message_len;
|
||||||
this->events_.try_send_nodefer(message, "log", millis());
|
this->events_.try_send_nodefer(message, "log", millis());
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user