ESPHome 2026.12.0-dev
Loading...
Searching...
No Matches
task_log_message.h
Go to the documentation of this file.
1#pragma once
2
4
5#ifdef USE_ESPHOME_TASK_LOG_BUFFER
6#include <cstdarg>
7#include <cstddef>
8#include <cstdint>
9#include <cstdio>
10#include <cstring>
11
12namespace esphome::logger {
13
14#if defined(USE_ESP32) || defined(USE_LIBRETINY)
15// Header of a variable-size task log message; the text follows it
17 const char *tag; // We store the pointer, assuming tags are static
18 char thread_name[16]; // Copied, the task may be gone before the main loop reads it
19 uint16_t text_length;
20 uint16_t line;
21 uint8_t level;
22
23 inline char *text_data() { return reinterpret_cast<char *>(this) + sizeof(TaskLogMessage); }
24};
25#endif
26
27#if defined(USE_ESP32) || defined(USE_LIBRETINY) || defined(USE_ZEPHYR)
28static constexpr int TASK_LOG_MAX_TEXT_SIZE = 255;
29
30inline int task_log_cap_length(int ret) { return ret > TASK_LOG_MAX_TEXT_SIZE ? TASK_LOG_MAX_TEXT_SIZE : ret; }
31#endif
32
33template<typename Message>
34inline void fill_task_log_header(Message *msg, uint8_t level, const char *tag, uint16_t line, const char *thread_name) {
35 msg->level = level;
36 msg->tag = tag;
37 msg->line = line;
38 if (thread_name != nullptr) {
39 strncpy(msg->thread_name, thread_name, sizeof(msg->thread_name) - 1);
40 msg->thread_name[sizeof(msg->thread_name) - 1] = '\0';
41 } else {
42 msg->thread_name[0] = '\0';
43 }
44}
45
46inline uint16_t trim_trailing_newlines(const char *text, uint16_t length) {
47 while (length > 0 && text[length - 1] == '\n')
48 length--;
49 return length;
50}
51
52} // namespace esphome::logger
53
54#endif // USE_ESPHOME_TASK_LOG_BUFFER
int ret
int task_log_cap_length(int ret)
void fill_task_log_header(Message *msg, uint8_t level, const char *tag, uint16_t line, const char *thread_name)
uint16_t trim_trailing_newlines(const char *text, uint16_t length)
void const char int line
Definition log.h:110
void const char * tag
Definition log.h:110
uint16_t length
Definition tt21100.cpp:0