ESPHome
2026.12.0-dev
Loading...
Searching...
No Matches
esphome
components
logger
task_log_message.h
Go to the documentation of this file.
1
#pragma once
2
3
#include "
esphome/core/defines.h
"
4
5
#ifdef USE_ESPHOME_TASK_LOG_BUFFER
6
#include <cstdarg>
7
#include <cstddef>
8
#include <cstdint>
9
#include <cstdio>
10
#include <cstring>
11
12
namespace
esphome::logger
{
13
14
#if defined(USE_ESP32) || defined(USE_LIBRETINY)
15
// Header of a variable-size task log message; the text follows it
16
struct
TaskLogMessage
{
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)
28
static
constexpr
int
TASK_LOG_MAX_TEXT_SIZE = 255;
29
30
inline
int
task_log_cap_length
(
int
ret
) {
return
ret
> TASK_LOG_MAX_TEXT_SIZE ? TASK_LOG_MAX_TEXT_SIZE :
ret
; }
31
#endif
32
33
template
<
typename
Message>
34
inline
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
46
inline
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
defines.h
ret
int ret
Definition
ln882h_ble.cpp:174
esphome::logger
Definition
log_buffer.h:8
esphome::logger::task_log_cap_length
int task_log_cap_length(int ret)
Definition
task_log_message.h:30
esphome::logger::fill_task_log_header
void fill_task_log_header(Message *msg, uint8_t level, const char *tag, uint16_t line, const char *thread_name)
Definition
task_log_message.h:34
esphome::logger::trim_trailing_newlines
uint16_t trim_trailing_newlines(const char *text, uint16_t length)
Definition
task_log_message.h:46
esphome::line
void const char int line
Definition
log.h:110
esphome::tag
void const char * tag
Definition
log.h:110
esphome::logger::TaskLogMessage
Definition
task_log_message.h:16
esphome::logger::TaskLogMessage::text_length
uint16_t text_length
Definition
task_log_message.h:19
esphome::logger::TaskLogMessage::text_data
char * text_data()
Definition
task_log_message.h:23
esphome::logger::TaskLogMessage::level
uint8_t level
Definition
task_log_message.h:21
esphome::logger::TaskLogMessage::thread_name
char thread_name[16]
Definition
task_log_message.h:18
esphome::logger::TaskLogMessage::tag
const char * tag
Definition
task_log_message.h:17
esphome::logger::TaskLogMessage::line
uint16_t line
Definition
task_log_message.h:20
length
uint16_t length
Definition
tt21100.cpp:0
Generated by
1.12.0