Skip to content

LOG


1. Summary

The LOG 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

Configure CONFIG_ CI_ LOG_ If EN is 1, the module is enabled. If it is configured as 0, no print information will be output. All print codes are not compiled because they are implemented by Hongshi. Configure CONFIG_ CI_ LOG_ UART_ PORT can select which serial port outputs the 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. A LOG can be customized in h_* 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_ The 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.