We divide the SDK code into different module or library for specific function, and Hierarchical software design also is useful for the code maintenance. This blog is to show the log setting for different module. Please see below architecture from SDK release document. Our aim is to print useful logs when issue happens, upload one module picture from SDK release .
- HOW TO Print LOGS：
- To use “printf” directly, this is very convenient for the debug, but not easy to make a good management for the logs added. Some basic knowledge of print is in this link：
char ch = 'A';
char str = "fresh2refresh.com";
float flt = 10.234;
int no = 150;
double dbl = 20.123456;
printf("Character is %c \n", ch);
printf("String is %s \n" , str);
printf("Float value is %f \n", flt);
printf("Integer value is %d\n" , no);
printf("Double value is %lf \n", dbl);
printf("Octal value is %o \n", no);
printf("Hexadecimal value is %x \n", no);
· %d got replaced by value of an integer variable (no),
· %c got replaced by value of a character variable (ch),
· %f got replaced by value of a float variable (flt),
· %lf got replaced by value of a double variable (dbl),
· %s got replaced by value of a string variable (str),
· %o got replaced by a octal value corresponding to integer variable (no),
· %x got replaced by a hexadecimal value corresponding to integer variable
· \n got replaced by a newline.
2. In wwd_debug.h, wwd_debug.c , wiced_defaults.h
We defined Macros to control the log output for different MODULE.
Modules are Application, library, Webserver , Network, RTOS,
Security , WPS, Supplicant, Wiced , WWD(Wiced wi-fi Driver) .
We have good instructions and warnings for the log setting:
* ** WARNING for PRINTING **
* If printing is enabled, the stack of each thread that uses printing
* must be increased to at least 4 kBytes since the printf function uses
* a lot of memory (including dynamic memory)
/* Select which group of functions are allowed to print */
/* WPRINT_ENABLE_<MODULE>_ERROR - Enable print messages in the respective <MODULE> that are present
* as WPRINT_<MODULE>_ERROR.
* For instance, if WPRINT_ENABLE_WWD_ERROR is enabled, then trace messages that are under
* WPRINT_WWD_ERROR will be printed. This directive shall also result in an ASSERT if the target is built in DEBUG mode.
* WPRINT_ENABLE_<MODULE>_DEBUG - Enable print messages in the respective module that are present as
* For instance, if WPRINT_ENABLE_WWD_DEBUG is enabled, then trace messages that are under
* WPRINT_WWD_DEBUG will be printed.
* WPRINT_ENABLE_<MODULE>_INFO - Enable print messages in the respective module that are present as
* For instance, if WPRINT_ENABLE_WWD_INFO is enabled, then trace messages that are under
* WPRINT_WWD_INFO will be printed.
If you disable all the logs, there will have a compiled error, so please keep this one at least:
#define WPRINT_ENABLE_APP_INFO /* Application prints */
So general debug sequence for log enable:
- Enable WPRINT_ENABLE_MODULE_INFO to track the process.
- If found an error was printed out, check which module , then enable DEBUG and ERROR mode also. Be noted, Debug compile will go to an assert if enable ERROR layer .
- Find the bug position , add more debug info by using the same level log print.
I think if you want to manage the log clearly , you can define one MACRO to just add your debug info ,like #define WPRINT_ENABLE_BUG_DEBUG_INFO , after issue is fixed you can disable it .Another log print mode :
3. Wiced_log_setting, it is often used on application area.
If you want to close the log , please change the log to WICED_LOG_OFF, the logs added in the application will be disabled. And strongly suggest to use this debug info in application debug stage.
Log initialize at application_start and enum structure.
wiced_log_init(WICED_LOG_INFO, render_log_output, wiced_time_get_time);
wiced_log_msg(WLF_DEF, WICED_LOG_NOTICE, "wiced logging system is initialized\n");
WICED_LOG_OFF = 0,
WICED_LOG_PRINTF, /* Identifies log messages generated by wiced_log_printf calls */
b: How to write to STDOUT .
use this function:
Enable time output with log together.