Skip to the content.

MycilaLogger

License: MIT Continuous Integration PlatformIO Registry

A simple and efficient logging library for Arduino / ESP32.

Basic Usage

First setup the outputs where to forward the logs in the setup() method:

Serial.begin(115200);
logger.forwardTo(&Serial);

WebSerial.begin(...);
logger.forwardTo(&Serial);

Then use the logger:

logger.debug(TAG, "Published in %u ms", (millis() - start));
logger.info(TAG, "Published in %u ms", (millis() - start));
logger.warn(TAG, "Published in %u ms", (millis() - start));
logger.error(TAG, "Published in %u ms", (millis() - start));

if(logger.isDebugEnabled()) {
  // some expensive debug code
}

will output something like this:

D      8102600 loopTask   (1)  WEBSITE Published in 38 ms

Note: the logging level can be controlled with the standard Arduino flag: -D CORE_DEBUG_LEVEL=ARDUHAL_LOG_LEVEL_DEBUG for example.

Tips

Thread safety

The logging code itself is thread-safe and can be called from multiple tasks and cores.

There is no locking strategy in place: the logging methods are delegating to the underlying Print implementations.