ThingWorx Edge C SDK > Porting to Another Platform > Logging Functions
  
Logging Functions
The C SDK has a pluggable logging provider that defaults to simple printf statements. The function definition is in the utils/twLogger.c file. Your platform/OS specific header file also defines some macros for logging, as shown below.
/* Logging */
#ifdef _DEBUG
#ifndef DBG_LOGGING
#define DBG_LOGGING
#endif
#endif
#ifdef DBG_LOGGING
#define TW_LOGGER_BUF_SIZE 4096 /* Max size of log buffer */
#define TW_LOG(level, fmt, ...) twLog(level, fmt, ##__VA_ARGS__)
#define TW_LOG_HEX(msg, preamble, length) twLogHexString(msg, preamble, length)
#define TW_LOG_MSG(msg, preamble) twLogMessage(msg, preamble)
#else
#define TW_LOGGER_BUF_SIZE 1
#define TW_LOG(level, fmt, ...)
#define TW_LOG_HEX(msg, preamble, length)
#define TW_LOG_MSG(msg, preamble)
#endif
To minimize the code footprint of a released application, the default for logging is that it is enabled for debug builds and entirely disabled for release builds. Both the logging functions and buffer size need to be defined if logging is enabled. The macros TW_LOG_HEX and TW_LOG_MSG are used to display the hex bytes moving over the wire and the actual message content, respectively. These functions tend to have a serious impact on performance and are not recommended for use in a released system.
The logging system also provides a convenient way for you to define you own logging function without changing these macros. This function is
int twLogger_SetFunction(log_function f);
For details about this function, refer to the Doxygen documentation provided with the SDK bundle.