DEBUG Logger
Overview
The DEBUG.h library is a lightweight debugging utility for Arduino/ESP32 projects that provides
conditional compilation of debug output. It allows developers to easily add debug logging throughout
their code that can be globally enabled or disabled without removing debug statements from the
source code.
Features
- Global Debug Toggle: Enable or disable all debug output with a single macro
- Zero Runtime Overhead: When disabled, debug statements are completely removed during compilation
- Multiple Output Formats: Support for simple prints, line prints, and formatted printf-style output
- Arduino Compatible: Designed specifically for Arduino/ESP32 Serial output
Configuration
Debug Toggle
The library uses a global DEBUG macro to control whether debug output is enabled:
1 2 | |
When DEBUG is set to 1, all debug macros will output to the Serial port. When set to 0, all
debug macros become empty and are removed during compilation, resulting in no performance overhead.
Usage
Macros
DEBUG_LOG(x)
1 | |
Prints the specified value or string without adding a newline character.
Parameters:
x- The value, variable, or string to print
Example:
1 2 3 4 | |
DEBUG_LOG_LN(x)
1 | |
Prints the specified value or string and adds a newline character at the end.
Parameters:
x- The value, variable, or string to print
Example:
1 2 3 4 5 | |
DEBUG_PRINTF(fmt, ...)
1 | |
Prints formatted output using printf-style formatting.
Parameters:
fmt- Format string with placeholders...- Variable arguments to fill the placeholders
Example:
1 2 3 4 5 6 | |
Production vs Development
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | |