AWS IoT Device SDK C: Logging
Generate and print log messages
Return to main page ↑
iot_logging_setup.h
Go to the documentation of this file.
1 /*
2  * IoT Common V1.1.0
3  * Copyright (C) 2018 Amazon.com, Inc. or its affiliates. All Rights Reserved.
4  *
5  * Permission is hereby granted, free of charge, to any person obtaining a copy of
6  * this software and associated documentation files (the "Software"), to deal in
7  * the Software without restriction, including without limitation the rights to
8  * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
9  * the Software, and to permit persons to whom the Software is furnished to do so,
10  * subject to the following conditions:
11  *
12  * The above copyright notice and this permission notice shall be included in all
13  * copies or substantial portions of the Software.
14  *
15  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
17  * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
18  * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
19  * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21  */
22 
28 #ifndef IOT_LOGGING_SETUP_H_
29 #define IOT_LOGGING_SETUP_H_
30 
31 /* The config header is always included first. */
32 #include "iot_config.h"
33 
34 /* Logging include. Because it's included here, iot_logging.h never needs
35  * to be included in source. */
36 #include "iot_logging.h"
37 
168 /* Check that LIBRARY_LOG_LEVEL is defined and has a valid value. */
169 #if !defined( LIBRARY_LOG_LEVEL ) || \
170  ( ( LIBRARY_LOG_LEVEL != IOT_LOG_NONE ) && \
171  ( LIBRARY_LOG_LEVEL != IOT_LOG_ERROR ) && \
172  ( LIBRARY_LOG_LEVEL != IOT_LOG_WARN ) && \
173  ( LIBRARY_LOG_LEVEL != IOT_LOG_INFO ) && \
174  ( LIBRARY_LOG_LEVEL != IOT_LOG_DEBUG ) )
175  #error "Please define LIBRARY_LOG_LEVEL as either IOT_LOG_NONE, IOT_LOG_ERROR, IOT_LOG_WARN, IOT_LOG_INFO, or IOT_LOG_DEBUG."
176 /* Check that LIBRARY_LOG_NAME is defined and has a valid value. */
177 #elif !defined( LIBRARY_LOG_NAME )
178  #error "Please define LIBRARY_LOG_NAME."
179 #else
180  /* Define IotLog if the log level is greater than "none". */
181  #if LIBRARY_LOG_LEVEL > IOT_LOG_NONE
182  #define IotLog( messageLevel, pLogConfig, ... ) \
183  IotLog_Generic( LIBRARY_LOG_LEVEL, \
184  LIBRARY_LOG_NAME, \
185  messageLevel, \
186  pLogConfig, \
187  __VA_ARGS__ )
189  /* Define the abbreviated logging macros. */
190  #define IotLogError( ... ) IotLog( IOT_LOG_ERROR, NULL, __VA_ARGS__ )
191  #define IotLogWarn( ... ) IotLog( IOT_LOG_WARN, NULL, __VA_ARGS__ )
192  #define IotLogInfo( ... ) IotLog( IOT_LOG_INFO, NULL, __VA_ARGS__ )
193  #define IotLogDebug( ... ) IotLog( IOT_LOG_DEBUG, NULL, __VA_ARGS__ )
194 
195  /* If log level is DEBUG, enable the function to print buffers. */
196  #if LIBRARY_LOG_LEVEL >= IOT_LOG_DEBUG
197  #define IotLog_PrintBuffer( pHeader, pBuffer, bufferSize ) \
198  IotLog_GenericPrintBuffer( LIBRARY_LOG_NAME, \
199  pHeader, \
200  pBuffer, \
201  bufferSize )
202  #else
203  #define IotLog_PrintBuffer( pHeader, pBuffer, bufferSize )
204  #endif
205  /* Remove references to IotLog from the source code if logging is disabled. */
206  #else
207  /* @[declare_logging_log] */
208  #define IotLog( messageLevel, pLogConfig, ... )
209  /* @[declare_logging_log] */
210  /* @[declare_logging_printbuffer] */
211  #define IotLog_PrintBuffer( pHeader, pBuffer, bufferSize )
212  /* @[declare_logging_printbuffer] */
213  #define IotLogError( ... )
214  #define IotLogWarn( ... )
215  #define IotLogInfo( ... )
216  #define IotLogDebug( ... )
217  #endif
218 #endif
219 
220 #endif /* ifndef IOT_LOGGING_SETUP_H_ */
Generic logging function header file.