flux-core
flux-core copied to clipboard
cleanup: use __func__ not __FUNCTION__
flux-core requires C99, thus __func__ may replace the older (and longer, and LOUDER!) __FUNCTION__.
https://gcc.gnu.org/onlinedocs/gcc/Function-Names.html
A global search and replace is in order I think.
While transitioning to __func__, perhaps we could also reduce many uses of this predefined macro in debug and error messages in favor of explicit strings.
Many times I've tried to grep for an error message in the code without success because the error string is "%s: %s", __FUNCTION__, strerror (errno). AFAICT, __FUNCTION__ and __func__ don't add much value excepth when used in macros (besides making it easier to cut and paste?), though it is likely I'm just missing something.
We discussed this offline and maybe reached a consensus?
__func__ is insufficient to locate a given error message but adding __FILE__ and __LINE__ would do it, in cases where the error is sufficiently unlikely that we don't want to work too hard on a human readable error and just want a code reference that somebody can cut and paste into a github issue.
Also it was pointed out that these special symbols are meant to be used in macros, not directly.
We do have this macro (rarely used):
#define FLUX_LOG_ERROR(h) \
(void)flux_log_error ((h), "%s::%d[%s]", __FILE__, __LINE__, __FUNCTION__)
But no way to append a message. Not that useful, and (hence) not used much.
Maybe we could go with something like:
#define log_err(h, fmt, arg...) \
flux_log ((h), LOG_ERR, __FILE__ "::" __LINE__ ": " fmt, ##arg)
with variants log_info, log_debug, etc. for different logging levels?
See also: Linux kernel printk macros: https://lwn.net/Articles/487437/
Is log_err too generic? Could that cause some name conflicts with other libraries?
Otherwise, I love it!
Oops, it collides with libutil/log.h.
flog_err(), flog_info(), ...?
I don't always like writing in C, but when I do, there is nothing like my __FUNCTION__ __YELLING__ __AT__ __ME__!