AWS IoT for ESP32 v1.0.0
An ESP-IDF based solution
Logging

Logging system

The library defines a logging system and uses it to print log messages. User application can also utilize it to pritn log messages. To use this logging system, the user application is required to provide default log level configuration while initializing the system.

The logging system works at a file level. To uniquely identify the files you have to define the module name for a file. While printing the log messages on the serial terminal the name of the module appears first followed by the log message. The APIs for printing log messages follow the printf syntax.

Example API call:

#define thisModule APP_MODULE_MAIN
print_info("hello world, counter = %d", counter);

Example output:

[APP_MODULE_MAIN] hello world, counter = 1

In order to print the log messages of various levels you need to call corresponing API. In the table below we have defined log levels along with its respective API for youre reference.

Log level APIs
PRINT_LEVEL_ERROR print_error
PRINT_LEVEL_VERBOSE print_verbose
PRINT_LEVEL_INFO print_info
PRINT_LEVEL_DEBUG print_debug

Logging levels

Following log levels are defined.

Logging level Description
PRINT_LEVEL_NONE Does not print any log messages.
PRINT_LEVEL_ERROR Prints Error level log messages alone.
PRINT_LEVEL_VERBOSE Prints log messages of both Error & Verbose level.
PRINT_LEVEL_INFO Prints log messages of Error, Verbose & Info level.
PRINT_LEVEL_DEBUG Prints log messages of all levels.

Defining default log levels

Refer the app_config.h file from examples, you should see that the default log levels has been defined. Below is a sample of DEFAULT_LOG_LEVELS taken from awsPubSub example.

#define DEFAULT_LOG_LEVELS { \
PRINT_LEVEL_ERROR, /* LIB_MODULE_MAIN_MENU */ \
PRINT_LEVEL_ERROR, /* LIB_MODULE_SYSTEM */ \
PRINT_LEVEL_ERROR, /* LIB_MODULE_BLE */ \
PRINT_LEVEL_ERROR, /* LIB_MODULE_WIFI */ \
PRINT_LEVEL_ERROR, /* LIB_MODULE_MQTT */ \
PRINT_LEVEL_INFO, /* LIB_MODULE_AWS */ \
PRINT_LEVEL_INFO, /* LIB_MODULE_JOBS */ \
PRINT_LEVEL_ERROR, /* LIB_MODULE_GPIO */ \
PRINT_LEVEL_ERROR, /* LIB_MODULE_FLASH */ \
PRINT_LEVEL_ERROR, /* DRV_MODULE_BLE */ \
PRINT_LEVEL_ERROR, /* LIB_MODULE_JSON */ \
PRINT_LEVEL_ERROR, /* LIB_MODULE_HTTP */ \
PRINT_LEVEL_ERROR, /* LIB_MODULE_OTA */ \
PRINT_LEVEL_DEBUG, /* APP_MODULE_MAIN **Add application modules from here */ \
};

Below is the sample code that initliazes the system configuration with default log levels.

Sample application:

#include "lib_system.h"
#include "app_config.h"
#define thisModule APP_MODULE_MAIN
static logLevels_et defaultLogLevels[MODULES_MAX] = DEFAULT_LOG_LEVELS;
void app_main()
{
systemInitConfig_st s_sysConfig = {
.pLogLevels_e = defaultLogLevels,
.logModulesCount_u8 = MODULES_MAX,
.pWifiSsidStr = TEST_WIFI_SSID,
.pWifiPwdStr = TEST_WIFI_PASSWORD,
.s_awsConfig = {
.pThingNameStr = MY_THING_NAME,
.pHostNameStr = AWS_IOT_MQTT_HOST,
.port_u16 = 8883,
.pRootCaStr = (char *)aws_root_ca_pem_start,
.pThingCertStr = (char *)thing_certificate_pem_crt_start,
.pThingPrivateKeyStr = (char *)thing_private_pem_key_start
}
};
print_info("Initializing system ...\r\n");
bool initSuccess = SYSTEM_init(&s_sysConfig);
if (initSuccess)
{
print_info("System initialized successfully.\r\n");
}
else
{
print_error("System initilaization failed.\r\n");
}
// ...
}
logLevels_et
Levels of debug messages for printing.
Definition: lib_config.h:33
System library header file.
bool SYSTEM_init(systemInitConfig_st *s_pConfig)
Initiliaze the system with given configuration.
System configuration structure. The application should define the system configuration variable and c...
Definition: lib_system.h:72
logLevels_et * pLogLevels_e
Definition: lib_system.h:73