AWS IoT Device SDK C: Logging
Generate and print log messages
Return to main page ↑
iot_logging_setup.h File Reference

Defines the logging macro IotLog. More...

#include "iot_config.h"
#include "iot_logging.h"

Go to the source code of this file.

Macros

#define IotLog(messageLevel, pLogConfig, ...)
 Logging function for a specific library. In most cases, this is the logging function to call. More...
 
#define IotLogError(...)   IotLog( IOT_LOG_ERROR, NULL, __VA_ARGS__ )
 Abbreviated logging macro for level IOT_LOG_ERROR. More...
 
#define IotLogWarn(...)   IotLog( IOT_LOG_WARN, NULL, __VA_ARGS__ )
 Abbreviated logging macro for level IOT_LOG_WARN. More...
 
#define IotLogInfo(...)   IotLog( IOT_LOG_INFO, NULL, __VA_ARGS__ )
 Abbreviated logging macro for level IOT_LOG_INFO. More...
 
#define IotLogDebug(...)   IotLog( IOT_LOG_DEBUG, NULL, __VA_ARGS__ )
 Abbreviated logging macro for level IOT_LOG_DEBUG. More...
 
#define IotLog_PrintBuffer(pHeader, pBuffer, bufferSize)
 Log the contents of buffer as bytes. Only available when LIBRARY_LOG_LEVEL is IOT_LOG_DEBUG. More...
 

Detailed Description

Defines the logging macro IotLog.

Macro Definition Documentation

◆ IotLog

#define IotLog (   messageLevel,
  pLogConfig,
  ... 
)
Value:
IotLog_Generic( LIBRARY_LOG_LEVEL, \
LIBRARY_LOG_NAME, \
messageLevel, \
pLogConfig, \
__VA_ARGS__ )
void IotLog_Generic(int32_t libraryLogSetting, const char *const pLibraryName, int32_t messageLevel, const IotLogConfig_t *const pLogConfig, const char *const pFormat,...)
Generic logging function that prints a single message.
Definition: iot_logging.c:188

Logging function for a specific library. In most cases, this is the logging function to call.

This function prints a single log message. It is available when LIBRARY_LOG_LEVEL is not IOT_LOG_NONE. Log messages automatically include the log level, library name, and time. An optional IotLogConfig_t may be passed to this function to hide information for a single log message.

The logging library must be set up before this function may be called. See Setup and use for more information.

This logging function also has the following abbreviated forms that can be used when an IotLogConfig_t isn't needed.

Name Equivalent to
IotLogError
IotLog( IOT_LOG_ERROR, NULL, ... )
IotLogWarn
IotLog( IOT_LOG_WARN, NULL, ... )
IotLogInfo
IotLog( IOT_LOG_INFO, NULL, ... )
IotLogDebug
IotLog( IOT_LOG_DEBUG, NULL, ... )
Parameters
[in]messageLevelLog level of this message. Must be one of the Log levels.
[in]pLogConfigPointer to an IotLogConfig_t. Optional; pass NULL to ignore.
[in]...Message and format specification.
Returns
No return value. On errors, it prints nothing.
Note
This function may be implemented as a macro.
See also
IotLog_Generic for the generic (not library-specific) logging function.

◆ IotLogError

#define IotLogError (   ...)    IotLog( IOT_LOG_ERROR, NULL, __VA_ARGS__ )

Abbreviated logging macro for level IOT_LOG_ERROR.

Equivalent to:

IotLog( IOT_LOG_ERROR, NULL, ... )

◆ IotLogWarn

#define IotLogWarn (   ...)    IotLog( IOT_LOG_WARN, NULL, __VA_ARGS__ )

Abbreviated logging macro for level IOT_LOG_WARN.

Equivalent to:

IotLog( IOT_LOG_WARN, NULL, ... )

◆ IotLogInfo

#define IotLogInfo (   ...)    IotLog( IOT_LOG_INFO, NULL, __VA_ARGS__ )

Abbreviated logging macro for level IOT_LOG_INFO.

Equivalent to:

IotLog( IOT_LOG_INFO, NULL, ... )

◆ IotLogDebug

#define IotLogDebug (   ...)    IotLog( IOT_LOG_DEBUG, NULL, __VA_ARGS__ )

Abbreviated logging macro for level IOT_LOG_DEBUG.

Equivalent to:

IotLog( IOT_LOG_DEBUG, NULL, ... )

◆ IotLog_PrintBuffer

#define IotLog_PrintBuffer (   pHeader,
  pBuffer,
  bufferSize 
)
Value:
IotLog_GenericPrintBuffer( LIBRARY_LOG_NAME, \
pHeader, \
pBuffer, \
bufferSize )
void IotLog_GenericPrintBuffer(const char *const pLibraryName, const char *const pHeader, const uint8_t *const pBuffer, size_t bufferSize)
Generic function to log the contents of a buffer as bytes.
Definition: iot_logging.c:396

Log the contents of buffer as bytes. Only available when LIBRARY_LOG_LEVEL is IOT_LOG_DEBUG.

This function prints the bytes located at a given memory address. It is intended for debugging only, and is therefore only available when LIBRARY_LOG_LEVEL is IOT_LOG_DEBUG.

Log messages printed by this function always include the log level, library name, and time. In addition, this function may print an optional header pHeader before it prints the contents of the buffer. This function does not have an IotLogConfig_t parameter.

The logging library must be set up before this function may be called. See Setup and use for more information.

Parameters
[in]pHeaderA message to log before the buffer. Optional; pass NULL to ignore.
[in]pBufferPointer to start of buffer.
[in]bufferSizeSize of pBuffer.
Returns
No return value. On errors, it prints nothing.
Note
This function may be implemented as a macro.
To conserve memory, IotLog_PrintBuffer (the underlying implementation) only allocates enough memory for a single line of output. Therefore, in multithreaded systems, its output may appear "fragmented" if other threads are logging simultaneously.
See also
IotLog_PrintBuffer for the generic (not library-specific) buffer logging function.

Example

const uint8_t pBuffer[] = { 0x00, 0x01, 0x02, 0x03 };
IotLog_PrintBuffer( "This buffer contains:",
pBuffer,
4 );

The code above prints something like the following:

[DEBUG][LIB_NAME][2018-01-01 12:00:00] This buffer contains:
00 01 02 03