11static constexpr uint8_t LOG_LEVEL_TO_SYSLOG_SEVERITY[] PROGMEM = {
22static constexpr char SECRET_BEGIN[] = ESPHOME_LOG_SECRET_BEGIN;
23static constexpr char SECRET_END[] = ESPHOME_LOG_SECRET_END;
24static constexpr size_t SECRET_BEGIN_LEN =
sizeof(SECRET_BEGIN) - 1;
25static constexpr size_t SECRET_END_LEN =
sizeof(SECRET_END) - 1;
27static bool starts_with_marker(
const char *
message,
size_t remaining,
const char *marker,
size_t marker_len) {
28 return message[0] ==
'\033' && remaining >= marker_len && memcmp(
message, marker, marker_len) == 0;
31static size_t append_bytes(
char *buf,
size_t size,
size_t pos,
const char *data,
size_t len) {
36 memcpy(buf +
pos, data, n);
48 if (starts_with_marker(
message + i,
len - i, SECRET_BEGIN, SECRET_BEGIN_LEN)) {
50 i += SECRET_BEGIN_LEN;
51 while (i <
len && !starts_with_marker(
message + i,
len - i, SECRET_END, SECRET_END_LEN)) {
60 while (i <
len && !starts_with_marker(
message + i,
len - i, SECRET_BEGIN, SECRET_BEGIN_LEN)) {
70 this, [](
void *self, uint8_t level,
const char *tag,
const char *
message,
size_t message_len) {
84 if ((
unsigned) level <= 7) {
89 size_t len = message_len;
91 if (this->
strip_ && message[0] == 0x1B &&
len > 11) {
100 offset = buf_append_printf(packet,
sizeof(packet), 0,
"<%d>", pri);
109 size_t timestamp_len = now.is_valid() ? now.strftime(
timestamp,
sizeof(
timestamp),
"%Y-%m-%dT%H:%M:%S%z") : 0;
110 if (timestamp_len == 24) {
116 offset = buf_append_printf(packet,
sizeof(packet), offset,
"%s",
timestamp);
120 offset = buf_append_printf(packet,
sizeof(packet), offset,
" %s %s - - - ",
App.
get_name().
c_str(), tag);
123 if (now.is_valid()) {
124 offset += now.strftime(packet + offset,
sizeof(packet) - offset,
"%b %e %H:%M:%S ");
126 offset = buf_append_printf(packet,
sizeof(packet), offset,
"%s %s: ",
App.
get_name().
c_str(), tag);
130 if (offset >=
sizeof(packet)) {
131 offset =
sizeof(packet) - 1;
const StringRef & get_name() const
Get the name of this Application set by pre_setup().
udp::UDPComponent * parent_
constexpr const char * c_str() const
void add_log_callback(void *instance, void(*fn)(void *, uint8_t, const char *, const char *, size_t))
Register a log callback to receive log messages.
time::RealTimeClock * time_
void log_(int level, const char *tag, const char *message, size_t message_len) const
void on_log(uint8_t level, const char *tag, const char *message, size_t message_len)
ESPTime now()
Get the time in the currently defined timezone.
bool send_packet(const uint8_t *data, size_t size)
Returns false if the packet could not be sent to every destination.
const LogString * message
size_t append_redacted_message(char *buf, size_t size, size_t pos, const char *message, size_t len)
Append len bytes of message to buf at pos, replacing every LOG_SECRET() region with "[redacted]".
size_t buf_append_str(char *buf, size_t size, size_t pos, const char *str)
Safely append a string to buffer, returning new position (capped at size).
Application App
Global storage of Application pointer - only one Application can exist.
uint8_t progmem_read_byte(const uint8_t *addr)