AWS IoT Device SDK C: Logging
Generate and print log messages
Return to main page ↑
Logging

Generate and print log messages.

This library allows other libraries to generate and print log messages, which can aid in debugging. Log messages are printed by passing strings to one of the logging functions. The features of this library include:

Dependencies

Dependencies of the logging library.

dot_inline_dotgraph_1.png
Logging direct dependencies

Currently, the logging library has the following dependencies:

Setup and use

How to set up and use the logging library.

The file iot_logging_setup.h should be included to configure logging for a single source file. Before including iot_logging_setup.h, the constants LIBRARY_LOG_LEVEL and LIBRARY_LOG_NAME must be defined.

For example, to configure all the "SAMPLE" library to print all messages below the info log level:

// Print log messages up to the "info" level.
#define LIBRARY_LOG_LEVEL IOT_LOG_INFO
// Print library name "SAMPLE".
#define LIBRARY_LOG_NAME "SAMPLE"
// Including this header defines the logging macros using LIBRARY_LOG_LEVEL and
// LIBRARY_LOG_NAME.
int main( void )
{
// After including iot_logging_setup.h, the logging functions can be used.
IotLogError( "Error." ); // Will be printed because IOT_LOG_ERROR <= LIBRARY_LOG_LEVEL
IotLogWarn( "Warning. " ); // Will be printed because IOT_LOG_WARN <= LIBRARY_LOG_LEVEL
IotLogInfo( "Info." ); // Will be printed because IOT_LOG_INFO <= LIBRARY_LOG_LEVEL
IotLogDebug( "Debug." ); // Will not be printed because IOT_LOG_DEBUG > LIBRARY_LOG_LEVEL
return 0;
}

The code above will print something like the following:

[ERROR][SAMPLE][2018-01-01 12:00:00] Error.
[WARN ][SAMPLE][2018-01-01 12:00:00] Warning.
[INFO ][SAMPLE][2018-01-01 12:00:00] Info.