Originally published on Maker.io (DigiKey).

Adding severity levels to debug output

A bare printf("here\n") tells you almost nothing once your codebase has more than a handful of print statements. Two additions change that substantially. The first wraps printf in a macro that automatically prepends the file, line number, and function name using __FILE__, __LINE__, and __func__ — turning every message into something immediately locatable and searchable without manual annotation.

The second adds severity levels (INFO, WARNING, ERROR) and a global logging threshold, so you can dial back output to just warnings and errors in the field while keeping verbose info logs available during development. A compile-time #if DEBUG guard lets the assembler emit zero debug code in production builds.

Both additions together fit in about 20 lines of C.

Read the full article →