First of all, do not use identifier starting with underscore! They are usually reserved for use by the people writing the library.
Secondly, why do you need the
logger() function, when you could do everything in
my_logger() instead? You are only making things harder for yourself.
As for your current code, you cannot just pass a variadic function's arguments to another variadic function.
In a function that is variadic (a function that has ellipsis
...
as parameter) you construct the
va_list and pass it to a function such as
vprintf() which is not variadic.
So my suggestion is: use a single function
my_logger() in which you construct the
va_list and feed it to
vprintf() just as you do in
logger().
There is another approach which is ugly and is for the modern C language: variadic macros.
Transform
my_logger() into a macro such as:
1 2 3 4
|
#define MY_LOGGER(format, ...) do { \
/* my business logic here */ \
logger(format, __VA_ARGS__); \
} while (0)
|
Another approach, reserved for modern C++: variadic function template, which I personally consider to be horrible.
http://www.cplusplus.com/articles/EhvU7k9E/