Last Updated on : 2023-12-19 08:36:58download
Device logs record the runtime process and exception information of a device. They are helpful for identifying the source of problems.
Open tuya_iot_config.h
and check if the following macro is defined.
#define ENABLE_LOG 1
tal_log.h
The log output API should be called after system service initialization.
Macro function | Description |
---|---|
TAL_PR_TRACE (fmt, …) | The trace log. |
TAL_PR_DEBUG (fmt, …) | The debug log, output during firmware development or troubleshooting. |
TAL_PR_INFO (fmt, …) | The info log. |
TAL_PR_NOTICE (fmt, …) | The notable event. |
TAL_PR_WARN (fmt, …) | The warning log, output when a recoverable error is thrown. |
TAL_PR_ERR (fmt, …) | The error log, output when a severe and unrecoverable error is thrown. |
Parameter | Description |
---|---|
fmt | Formatted parameter |
… | Variadic |
Macro function | Description |
---|---|
TAL_PR_HEXDUMP_TRACE (title, buf, size) | The trace log. |
TAL_PR_HEXDUMP_DEBUG (title, buf, size) | The debug log, output during firmware development or troubleshooting. |
TAL_PR_HEXDUMP_INFO (title, buf, size) | The info log. |
TAL_PR_HEXDUMP_NOTICE (title, buf, size) | The notable event. |
TAL_PR_HEXDUMP_WARN (title, buf, size) | The warning log, output when a recoverable error is thrown. |
TAL_PR_HEXDUMP_ERR (title, buf, size) | The error log, output when a severe and unrecoverable error is thrown. |
Parameter | Description |
---|---|
title | Custom label |
buf | Buffer to print |
size | Buffer size |
Once you set the log level, any logs below this level will not be printed.
TAL_LOG_LEVEL_ERR
TAL_LOG_LEVEL_TRACE
This API is intended for the default log output, not for custom log output. That is, the setting only applies to TAL_PR_XXX
and TAL_PR_HEXDUMP_XXX
.
typedef enum {
TAL_LOG_LEVEL_ERR, //! Error
TAL_LOG_LEVEL_WARN, //! Warning
TAL_LOG_LEVEL_NOTICE, //! Notice
TAL_LOG_LEVEL_INFO, //! Info
TAL_LOG_LEVEL_DEBUG, //! Debug
TAL_LOG_LEVEL_TRACE, //! Trace
} TAL_LOG_LEVEL_E;
/**
* @brief set the global log level.
*
* @param[in] curLogLevel , log level
*
* @note This API is used to set the global log level.
*
* @return OPRT_OK on success. Others on error, please refer to tuya_error_code.h
*/
OPERATE_RET tal_log_set_manage_attr(CONST TAL_LOG_LEVEL_E level);
After the log is formatted, it will invoke the callback you registered. You can implement the callback as needed. This API allows you to output logs to the required destination, such as network and file.
typedef VOID (*TAL_LOG_OUTPUT_CB)(IN CONST CHAR_T *str);
/**
* @brief add one output terminal.
*
* @param[in] name, terminal name
* @param[in] term, output function pointer
*
* @note This API is used for adding one output terminal.
*
* @return OPRT_OK on success. Others on error, please refer to tuya_error_code.h
*/
OPERATE_RET tal_log_add_output_term(CONST CHAR_T *name, CONST TAL_LOG_OUTPUT_CB term);
/**
* @brief delete one output terminal.
*
* @param[in] name , terminal name
*
* @note This API is used to delete one output terminal.
*
* @return NONE
*/
VOID tal_log_del_output_term(CONST CHAR_T *name);
You can add a module for log print and set its log level. TAL_PR_XXX
is the default log print module.
/**
* @brief add one module's log level
*
* @param[in] module_name, module name
* @param[in] logLevel, this module's log level
*
* @note This API is used for adding one module's log level.
*
* @return OPRT_OK on success. Others on error, please refer to tuya_error_code.h
*/
OPERATE_RET tal_log_add_module_level(CONST PCHAR_T module_name, CONST TAL_LOG_LEVEL_E level);
/**
* @brief add one module's log level
*
* @param[in] pModuleName, module name
* @param[in] logLevel, this module's log level
*
* @note This API is used for adding one module's log level.
*
* @return OPRT_OK on success. Others on error, please refer to tuya_error_code.h
*/
OPERATE_RET tal_log_set_module_level(CONST PCHAR_T module_name, TAL_LOG_LEVEL_E level);
/**
* @brief delete one module's log level
*
* @param[in] pModuleName, module name
*
* @note This API is used for deleting one module's log level.
*
* @return OPRT_OK on success. Others on error, please refer to tuya_error_code.h
*/
OPERATE_RET tal_log_delete_module_level(CONST PCHAR_T module_name);
Macro | Description |
---|---|
TAL_MPR_TRACE (module, fmt, …) | The trace log. |
TAL_MPR_DEBUG (module, fmt, …) | The debug log, output during firmware development or troubleshooting. |
TAL_MPR_INFO (module, fmt, …) | The info log. |
TAL_MPR_NOTICE (module, fmt, …) | The notable event. |
TAL_MPR_WARN (module, fmt, …) | The warning log, output when a recoverable error is thrown. |
TAL_MPR_ERR (module, fmt, …) | The error log, output when a severe and unrecoverable error is thrown. |
The default buffer size for log printing is 1,024 bytes. Any excess will not be printed.
The log output API has a program lock, so do not use this API in an interrupt function.
When deleting a thread asynchronously, make sure the log output call is finished.
Is this page helpful?
YesFeedbackIs this page helpful?
YesFeedback