using C macros to print line number and function name
Posted on 2013-12-24
I am using log4c library and have been using the following macro for my logging purposes.
#define mylog(A,B, ...) log4c_category_log(A, B, __VA_ARGS__)
It works fine, but I want to also use __LINE__, __FUNC__ directives so I can have the line number and function name printed.
For example, if I am using the mylog( ) in my_function() in line 25.
mylog(MYCATEGORY, LOG4C_PRIORITY_ERROR, "some message");
I want the log to be printed like :
>>>>>>some message, my_function, 25
I don't want to edit the logging but rather using the macro definition be able to print these details. Is it possible?
I tried the following, but it does not work when the log is something like:
mylog(MYCATEGORY, LOG4C_PRIORITY_ERROR, "some message %s %s", "value1", "value2");
#define mylog(A,B, ...) log4c_category_log(A, B,"%s %s %d ", __VA_ARGS__, __FUNCTION__, __LINE__)