I'm working on embedded system, where I use printf to create log on UART.
I would like to create a debug source file where I can set the type of debug I need.
I defined this constant:
- DEBUG_LOG_0 for system log
- DEBUG_LOG_1 for system debugging
- DEBUG_LOG_2 for system advanced debugging
Starting from this constant I defined this macro to wrap the standard printf:
/* Define for debugging level 0 - System Logs */ #ifdef DEBUG_LEVEL_0 #define edi_Print_L0(...) printf(__VA_ARGS__) #endif #ifndef DEBUG_LEVEL_0 #define edi_Print_L0(...) printf(...) #endif /* Define for debugging level 1 - Debug */ #ifdef DEBUG_LEVEL_1 #define edi_Print_L0(...) printf(__VA_ARGS__) #define edi_Print_L1(...) printf(__VA_ARGS__) #endif #ifndef DEBUG_LEVEL_1 #define edi_Print_L0(...) printf(...) #define edi_Print_L1(...) printf(...) #endif /* Define for debugging level 2 - Advanced Debug */ #ifdef DEBUG_LEVEL_2 #define edi_Print_L0(...) printf(__VA_ARGS__) #define edi_Print_L1(...) printf(__VA_ARGS__) #define edi_Print_L2(...) printf(__VA_ARGS__) #endif #ifndef DEBUG_LEVEL_2 #define edi_Print_L0(...) printf(...) #define edi_Print_L1(...) printf(...) #define edi_Print_L2(...) printf(...) #endif Next I would import the debug constant from a Header file in order to enable the selected level of debug.
Any suggestion about the macro definition? Is there a smart way to achieve my scope?
Thanks!
printfis not really debugging. In addition to what @Lundin wrote: use a debugger for debugging. However that UART is handled, it will eventually either loose text or block. Not to talk about how toprintffrom interrupt handlers.