|
| 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 |
0 commit comments