Logging for Mbed SDK
How to enable logging
C-core
has a simple and efficient, yet flexible logging system. There are several levels from which to choose. Also, the user can set the function that will do the actual writing of data to an output.
Log Level | Preprocessor Symbol | Description |
---|---|---|
none | PUBNUB_LOG_LEVEL_NONE | all checks disabled |
errors | PUBNUB_LOG_LEVEL_ERROR | only errors reported |
warnings | PUBNUB_LOG_LEVEL_WARNING | ignored invalid conditions are reported, too |
regular | PUBNUB_LOG_LEVEL_INFO | significant events reported, too |
debug | PUBNUB_LOG_LEVEL_DEBUG | various reports useful in debugging reported, too |
detail | PUBNUB_LOG_LEVEL_TRACE | all logs enabled (compiled in) |
Related documentation
For details on initializing the SDK with custom logging output and other configuration options, see the Configuration document.
To choose a level, define preprocessor symbol PUBNUB_LOG_LEVEL
to one of the symbols from the table above. If you don't define it, the default used is PUBNUB_LOG_LEVEL_INFO
.
You will see that some of our samples Makefiles
define this symbol and some don't, depending on their purpose.
Keep in mind that debug and detail levels produce a lot of output that is hard to decypher by the uninitiated. So, it's best to use them only when looking for causes of some bugs - for example, if you report a suspected issue to Pubnub support.
Even though C-core
logging system is designed for its own purpose, you're free to use it in your code too, if it suits your needs. The interface is in the pubnub_log.h header
.
The actual writing of the log reports to an output is done by using the preprocessor macro PUBNUB_LOG_PRINTF
- define it to have printf-like semantics. If you don't define this symbol, the default used is printf
. For example, here's a simple way to use a serial port for debug/logging - in pubnub_config.h
add this:
#include <MODSERIAL.h>
extern MODSERIAL pc; /* or some other serial port handler per your choice */
#define PUBNUB_LOG_PRINTF(...) pc.printf(__VA_ARGS__)