Skip to content

Commit b445e38

Browse files
KonstantinKondrashovespressif-bot
authored andcommitted
feat(log): Move esp_log_write APIs out of esp_log.h
1 parent 5462240 commit b445e38

File tree

6 files changed

+77
-38
lines changed

6 files changed

+77
-38
lines changed

components/log/include/esp_log.h

Lines changed: 1 addition & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -15,48 +15,12 @@
1515
#include "esp_log_color.h"
1616
#include "esp_log_buffer.h"
1717
#include "esp_log_timestamp.h"
18+
#include "esp_log_write.h"
1819

1920
#ifdef __cplusplus
2021
extern "C" {
2122
#endif
2223

23-
typedef int (*vprintf_like_t)(const char *, va_list);
24-
25-
/**
26-
* @brief Set function used to output log entries
27-
*
28-
* By default, log output goes to UART0. This function can be used to redirect log
29-
* output to some other destination, such as file or network. Returns the original
30-
* log handler, which may be necessary to return output to the previous destination.
31-
*
32-
* @note Please note that function callback here must be re-entrant as it can be
33-
* invoked in parallel from multiple thread context.
34-
*
35-
* @param func new Function used for output. Must have same signature as vprintf.
36-
*
37-
* @return func old Function used for output.
38-
*/
39-
vprintf_like_t esp_log_set_vprintf(vprintf_like_t func);
40-
41-
/**
42-
* @brief Write message into the log
43-
*
44-
* This function is not intended to be used directly. Instead, use one of
45-
* ESP_LOGE, ESP_LOGW, ESP_LOGI, ESP_LOGD, ESP_LOGV macros.
46-
*
47-
* This function or these macros should not be used from an interrupt.
48-
*/
49-
void esp_log_write(esp_log_level_t level, const char* tag, const char* format, ...) __attribute__((format(printf, 3, 4)));
50-
51-
/**
52-
* @brief Write message into the log, va_list variant
53-
* @see esp_log_write()
54-
*
55-
* This function is provided to ease integration toward other logging framework,
56-
* so that esp_log can be used as a log sink.
57-
*/
58-
void esp_log_writev(esp_log_level_t level, const char* tag, const char* format, va_list args);
59-
6024
/** @cond */
6125

6226
#define LOG_FORMAT(letter, format) LOG_COLOR_ ## letter #letter " (%" PRIu32 ") %s: " format LOG_RESET_COLOR "\n"
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
/*
2+
* SPDX-FileCopyrightText: 2024 Espressif Systems (Shanghai) CO LTD
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
#pragma once
8+
9+
#include <stdint.h>
10+
#include <stdarg.h>
11+
#include "esp_log_level.h"
12+
13+
#ifdef __cplusplus
14+
extern "C" {
15+
#endif
16+
17+
typedef int (*vprintf_like_t)(const char *, va_list);
18+
19+
/**
20+
* @brief Set function used to output log entries
21+
*
22+
* By default, log output goes to UART0. This function can be used to redirect log
23+
* output to some other destination, such as file or network. Returns the original
24+
* log handler, which may be necessary to return output to the previous destination.
25+
*
26+
* @note Please note that function callback here must be re-entrant as it can be
27+
* invoked in parallel from multiple tasks context.
28+
*
29+
* @param func new Function used for output. Must have same signature as vprintf.
30+
*
31+
* @return func old Function used for output.
32+
*/
33+
vprintf_like_t esp_log_set_vprintf(vprintf_like_t func);
34+
35+
/**
36+
* @brief Write message into the log
37+
*
38+
* This function is not intended to be used directly. Instead, use one of
39+
* ESP_LOGE, ESP_LOGW, ESP_LOGI, ESP_LOGD, ESP_LOGV macros.
40+
*
41+
* This function or these macros should not be used from an interrupt.
42+
*
43+
* This function does not add any formatting elements such as color, timestamp, or tag.
44+
* It checks the level and tag level. If logging is allowed then it outputs it as is.
45+
*
46+
* @param level Log level of the message.
47+
* @param tag It is used to check whether logging is enabled for that tag (depends on CONFIG_LOG_TAG_LEVEL_IMPL).
48+
* @param format The format string for the log message. It has to be fully formatted, no additional formatting items will be added.
49+
* @param ... Optional arguments to be formatted according to the format string.
50+
*/
51+
void esp_log_write(esp_log_level_t level, const char* tag, const char* format, ...) __attribute__((format(printf, 3, 4)));
52+
53+
/**
54+
* @brief Write message into the log, va_list variant
55+
* @see esp_log_write()
56+
*
57+
* This function is provided to ease integration toward other logging framework,
58+
* so that esp_log can be used as a log sink.
59+
*
60+
* This function does not add any formatting elements such as color, timestamp, or tag.
61+
* It checks the level and tag level. If logging is allowed then it outputs it as is.
62+
*
63+
* @param level Log level of the message.
64+
* @param tag It is used to check whether logging is enabled for that tag (depends on CONFIG_LOG_TAG_LEVEL_IMPL).
65+
* @param format The format string for the log message. It has to be fully formatted, no additional formatting items will be added.
66+
* @param args List of arguments.
67+
*/
68+
void esp_log_writev(esp_log_level_t level, const char* tag, const char* format, va_list args);
69+
70+
#ifdef __cplusplus
71+
}
72+
#endif

components/log/src/os/log_write.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
#include <stddef.h>
99
#include <string.h>
1010
#include <stdio.h>
11-
#include "esp_log.h"
11+
#include "esp_log_write.h"
1212
#include "esp_private/log_lock.h"
1313
#include "esp_private/log_level.h"
1414
#include "sdkconfig.h"

docs/doxygen/Doxyfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -278,6 +278,7 @@ INPUT = \
278278
$(PROJECT_PATH)/components/log/include/esp_log_buffer.h \
279279
$(PROJECT_PATH)/components/log/include/esp_log_timestamp.h \
280280
$(PROJECT_PATH)/components/log/include/esp_log_color.h \
281+
$(PROJECT_PATH)/components/log/include/esp_log_write.h \
281282
$(PROJECT_PATH)/components/lwip/include/apps/esp_sntp.h \
282283
$(PROJECT_PATH)/components/lwip/include/apps/ping/ping_sock.h \
283284
$(PROJECT_PATH)/components/mbedtls/esp_crt_bundle/include/esp_crt_bundle.h \

docs/en/api-reference/system/log.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,3 +155,4 @@ API Reference
155155
.. include-build-file:: inc/esp_log_buffer.inc
156156
.. include-build-file:: inc/esp_log_timestamp.inc
157157
.. include-build-file:: inc/esp_log_color.inc
158+
.. include-build-file:: inc/esp_log_write.inc

docs/zh_CN/api-reference/system/log.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,3 +155,4 @@ API 参考
155155
.. include-build-file:: inc/esp_log_buffer.inc
156156
.. include-build-file:: inc/esp_log_timestamp.inc
157157
.. include-build-file:: inc/esp_log_color.inc
158+
.. include-build-file:: inc/esp_log_write.inc

0 commit comments

Comments
 (0)