I was wondering if anyone has come up with a clever macro that would change the console print colour based on which source file has called printf.
The best way I've been able to figure out how to do this is.
//print.h
#define PRINT_NORMAL printf("\033[0m");
#define PRINTF(style, ...) printf(style); printf(__VA_ARGS__); PRINT_NORMAL
//myfile.h
#define MYFILE_STYLE "\033[1;34m"
//myfile.c
...
PRINTF(MYFILE_STYLE, "Something with myfile style");
...
I was wondering if there is some sneaky way I could define PRINTF so that it wouldn't need the style parameter, essentially grabbing a local variable to use as the style.
EDIT:
It kind of came to me immediately after writing the last sentence.
I should be able to define a local style variable in each of my .c files and change my macro to
#define PRINTF(...) printf(style); printf(__VA_ARGS__); PRINT_NORMAL
The next question: Is there a better way to combine those 3 printf statements?