2025-02-21 06:41 PM - edited 2025-02-21 08:17 PM
Hello,
The following code compiles, but doesn't give the me results I'm expecting:
void syslog2(uint8_t pri, const char *fmt, ...) {
va_list args;
va_start(args, fmt);
printf(fmt, args);
va_end(args);
}
main() {
printf("%s\r\n", _tx_version_id);
syslog2(SYSLOG_INFO, "Azure RTOS - %s\r\n", "test" /*_tx_version_id*/);
}
this is the output:
what am I missing?
thanks
Matthew
Solved! Go to Solution.
2025-02-22 01:55 AM
This is a C question and not a ST microcontrollers question. With va_list arguments, you should use vprintf. See https://cplusplus.com/reference/cstdio/vprintf/
2025-02-22 01:55 AM
This is a C question and not a ST microcontrollers question. With va_list arguments, you should use vprintf. See https://cplusplus.com/reference/cstdio/vprintf/
2025-02-22 02:54 AM - edited 2025-02-22 03:02 AM
Hi @AA1
Where were you 2 hours ago?? LOL
I ended up writing my own macro to get around this issue:
#define _LOG_FORMAT_STD(letter, format) "%s" format "\r\n", SysLog_prefix( letter )
#define _LOG_FORMAT(letter, format) \
"%s [%s:%u] %s(): " format "\r\n", SysLog_prefix( letter ), GetFileName( __FILE__), __LINE__, __FUNCTION__
#define syslog(level, format, ...) \
if (level == SYSLOG_FATAL) { \
printf(_LOG_FORMAT(level, format), ##__VA_ARGS__); \
} else if (level <= syslog_level) \
printf(_LOG_FORMAT_STD(level, format), ##__VA_ARGS__)
But I did test your suggestion (vprintf), and it works as well.
thanks
Matthew