Macros and logging functions for error detection and debugging