LOG¶
1. Summary¶
The LOG output component can only print debugging information through the serial port at present, so it is only used for debugging at present. There are six levels of printing information set by referring to Andriod Logcat. The description is as follows:
| Print Level | Description |
|---|---|
| CI_LOG_VERBOSE | Detailed log, the highest print level, used to output all log information |
| CI_LOG_DEBUG | Debug log. This type of log is commonly used in the product development stage to output debugging information |
| CI_LOG_INFO | Information log, which is used to output key information to confirm system status |
| CI_LOG_WARN | Warning information. This type of log is used to print warning information, indicating that the system may encounter problems and try to repair them |
| CI_LOG_ERROR | Error information. This type of log is used to print error information and report problems encountered by the system |
| CI_LOG_ASSERT | Assertion information. This type of log is used to print serious errors, that is, the system cannot run completely when encountering serious problems |
Using this component to add output information to the program response location can better detect the running state of the system, which is of great help in locating debugging problems in the product development stage.
2. Instructions¶
The component source code includes ci_log.cãci_log.hãci_log_Config.h consists of three files, of which ci_log.cãci_log.h We have implemented the relevant serial port output print code, which generally does not need to be modified. Users only use ci_log_Config.h, and the related macro configuration is described as follows:
2.1. Configuration¶
Setting CONFIG_CI_LOG_EN to 1 enables the module. If it is configured as 0, no print information will be output. Since all print code is implemented via macros, it will not be compiled in. CONFIG_CI_LOG_UART_PORT can be configured to select which UART port is used for the output of print information.
/*LOG module switch*/
#define CONFIG_CI_LOG_EN 1
/*LOG module output serial port*/
#define CONFIG_CI_LOG_UART_PORT ((UART_TypeDef*)CONFIG_CI_LOG_UART)
2.2. Add module unified print level¶
At ci_log_config.h, a LOG can be customized in LOG_* As shown below, you can select different print levels for different modules by filling in the macro level of the module in the same module.
/*Print Level*/
#define LOG_WIFI_EVENT CI_LOG_DEBUG
#define LOG_DUERAPP CI_LOG_DEBUG
#define LOG_AUDIO_PLAY CI_LOG_INFO
#define LOG_AUDIO_GET_DATA CI_LOG_INFO
#define LOG_USER CI_LOG_DEBUG
#define LOG_COM_UART CI_LOG_DEBUG
2.3. Print Function¶
As described in the API manual, print functions include the following (implemented with macro parameters):
/**@ brief log printing -- detailed*/
#define ci_logverbose(comlevel, message, args...)
/**@ brief log printing -- debugging*/
#define ci_logdebug(comlevel, message, args...)
/**@ brief log printing -- information*/
#define ci_loginfo(comlevel, message, args...)
/**@ brief log printing -- warning*/
#define ci_logwarn(comlevel, message, args...)
/**@ brief log printing -- error*/
#define ci_logerr(comlevel, message, args...)
/**@ brief log printing -- assertion*/
#define ci_logassert(comlevel, message, args...)
Examples are as follows:
#define LOG_TEST_APP CI_LOG_DEBUG
int test_log(void)
{
int test_index = 0;
ci_logverbose(LOG_TEST_APP, "logverbose %d", test_index++);
ci_logdebug(LOG_TEST_APP, "logdebug %d", test_index++);
ci_loginfo(LOG_TEST_APP, "loginfo %d", test_index++);
ci_logwarn(LOG_TEST_APP, "logwarn %d", test_index++);
ci_logerr(LOG_TEST_APP, "logerr %d", test_index++);
ci_logassert(LOG_TEST_APP, "logassert %d", test_index++);
}
Note
ci_logxxx series is implemented through macros. Do not use the function to be used as a parameter to print the return value of the function. This will result in that the function cannot be called when the macro is closed.
3. Frequently Asked Questions¶
- Because the log output component needs to use a serial port, you must initialize the corresponding serial port when the system is initialized.