AWS IoT Device SDK C  202108.00
SDK for connecting to AWS IoT from a device using embedded C.
logging_stack.h File Reference

Reference implementation of Logging stack as a header-only library. More...

#include "logging_levels.h"
#include <stdio.h>
#include <stdint.h>
#include <string.h>

Go to the source code of this file.

Macros

#define LIBRARY_LOG_NAME   "<LIBRARY_NAME>"
 The name of the library or demo to add as metadata in log messages from the library or demo. More...
 
#define FILENAME   ( strrchr( __FILE__, '/' ) ? strrchr( __FILE__, '/' ) + 1 : __FILE__ )
 Macro to extract only the file name from file path to use for metadata in log messages.
 
#define LOG_METADATA_FORMAT   "[%s] [%s:%d] "
 Format of metadata prefix in log messages as [<Logging-Level>] [<Library-Name>] [<File-Name>:<Line-Number>]
 
#define LOG_METADATA_ARGS   LIBRARY_LOG_NAME, FILENAME, __LINE__
 Arguments into the metadata logging prefix format.
 
#define SdkLog(string)   printf string
 Common macro that maps all the logging interfaces, (LogDebug, LogInfo, LogWarn, LogError) to the platform-specific logging function. More...
 
#define LogDebug(message)   SdkLog( ( "[DEBUG] " LOG_METADATA_FORMAT, LOG_METADATA_ARGS ) ); SdkLog( message ); SdkLog( ( "\r\n" ) )
 Definition of logging interface macro that logs messages at the "Debug" level, when debug level logging is enabled. More...
 
#define LogInfo(message)   SdkLog( ( "[INFO] " LOG_METADATA_FORMAT, LOG_METADATA_ARGS ) ); SdkLog( message ); SdkLog( ( "\r\n" ) )
 Definition of logging interface macro that logs messages at the "Info" level, when info level logging is enabled. More...
 
#define LogWarn(message)   SdkLog( ( "[WARN] " LOG_METADATA_FORMAT, LOG_METADATA_ARGS ) ); SdkLog( message ); SdkLog( ( "\r\n" ) )
 Definition of logging interface macro that logs messages at the "Warning" level, when warning level logging is enabled. More...
 
#define LogError(message)   SdkLog( ( "[ERROR] " LOG_METADATA_FORMAT, LOG_METADATA_ARGS ) ); SdkLog( message ); SdkLog( ( "\r\n" ) )
 Definition of logging interface macro that logs messages at the "Error" level, when error level logging is enabled. More...
 

Detailed Description

Reference implementation of Logging stack as a header-only library.

Macro Definition Documentation

◆ LIBRARY_LOG_NAME

#define LIBRARY_LOG_NAME   "<LIBRARY_NAME>"

The name of the library or demo to add as metadata in log messages from the library or demo.

This metadata aids in identifying the module source of log messages. The metadata is logged in the format [ <LIBRARY-NAME> ] as a prefix to the log messages. Refer to LOG_METADATA_FORMAT for the complete format of the metadata prefix in log messages.

◆ SdkLog

#define SdkLog (   string)    printf string

Common macro that maps all the logging interfaces, (LogDebug, LogInfo, LogWarn, LogError) to the platform-specific logging function.

printf from the standard C library is the POSIX platform implementation used for logging functionality.

◆ LogDebug

#define LogDebug (   message)    SdkLog( ( "[DEBUG] " LOG_METADATA_FORMAT, LOG_METADATA_ARGS ) ); SdkLog( message ); SdkLog( ( "\r\n" ) )

Definition of logging interface macro that logs messages at the "Debug" level, when debug level logging is enabled.

Disable definition of logging interface macros when generating doxygen output, to avoid conflict with documentation of macros at the end of the file.

This macro is only enabled for LOG_DEBUG level configuration in this logging stack implementation.

◆ LogInfo

#define LogInfo (   message)    SdkLog( ( "[INFO] " LOG_METADATA_FORMAT, LOG_METADATA_ARGS ) ); SdkLog( message ); SdkLog( ( "\r\n" ) )

Definition of logging interface macro that logs messages at the "Info" level, when info level logging is enabled.

This macro is only enabled for LOG_DEBUG and LOG_INFO level configurations in this logging stack implementation.

◆ LogWarn

#define LogWarn (   message)    SdkLog( ( "[WARN] " LOG_METADATA_FORMAT, LOG_METADATA_ARGS ) ); SdkLog( message ); SdkLog( ( "\r\n" ) )

Definition of logging interface macro that logs messages at the "Warning" level, when warning level logging is enabled.

This macro is only enabled for LOG_DEBUG, LOG_INFO and LOG_WARN level configurations in this logging stack implementation.

◆ LogError

#define LogError (   message)    SdkLog( ( "[ERROR] " LOG_METADATA_FORMAT, LOG_METADATA_ARGS ) ); SdkLog( message ); SdkLog( ( "\r\n" ) )

Definition of logging interface macro that logs messages at the "Error" level, when error level logging is enabled.

This macro is only enabled for all logging level configurations unless except the LOG_NONE configuration.