I have been doing a task to change the current logging mechanism in my CPP codebase.
The current one is something like a printf in which we can write
MYLOGGING(("Example Log :%s, Example Num: %d", String, Number));
Now as part of modifying it to the new logging mechanism, I want to get this complete output to a string using the snprintf(). For that I used a variable list for this.
The code was like
#define MYLOGGING(log_string,...) do { \
char buff[1024]; \
memset(buff, 0, sizeof(buff)); \
snprintf(buff, sizeof(buff), log_string, ##__VA_ARGS__); \
MYNEW_LOG(NewlogParams, buff); \
} while(0)
Now, I am facing an issue. The existing logging had many instances in which some enum values are printed using simple %d. In such cases, with this new code, it is throwing the following error.
error: cannot convert ‘enumType’ to ‘const char*’ for argument ‘3’ to ‘int snprintf(char*, size_t, const char*, ...)’
One obvious option to get rid of this is to give integer type casting for enum prints.
As that could be a tedious process, i am curious to know whether I can fix this in some other way?
Please share your views.
Thanks in advance.