I need a logging function or macro in C language, which should works in Linux, that can accept a format string and a list of arguments, and can append the caller's function name to the output string.
Here is an example. Suppose the logging function (macro) is called smart_log. It looks like:
smart_log(const char *fmt, ...)
The first argument fmt is a format string, just like the format string in printf. Following fmt is a list of additional arguments to feed fmt.
Suppose a function called example_function calls smart_log in this way:
void example_function() {
smart_log("try to output number %d\n", 1);
}
Then the logging string looks like:
[example_function]: try to output number 1
So the key point is that smart_log append the caller's function to the format string.
I am not sure how to achieve this in C. I think it may be possible to use macro to achieve this.