mirror of
https://github.com/open62541/open62541.git
synced 2026-10-17 04:42:09 +08:00
use va_list in logging API (necessary for static inline functions)
This commit is contained in:
+1
-1
@@ -61,7 +61,7 @@ typedef enum {
|
||||
* Do not use the logger directly but make use of the following macros that take
|
||||
* the minimum log-level defined in ua_config.h into account. */
|
||||
typedef void (*UA_Logger)(UA_LogLevel level, UA_LogCategory category,
|
||||
const char *msg, ...);
|
||||
const char *msg, va_list args);
|
||||
|
||||
static inline void
|
||||
UA_LOG_TRACE(UA_Logger logger, UA_LogCategory category, const char *msg, ...) {
|
||||
|
||||
+15
-14
@@ -7,25 +7,26 @@
|
||||
#include "ua_types_generated.h"
|
||||
#include "ua_types_generated_handling.h"
|
||||
|
||||
#ifdef UA_ENABLE_MULTITHREADING
|
||||
#include <pthread.h>
|
||||
static pthread_mutex_t printf_mutex = PTHREAD_MUTEX_INITIALIZER;
|
||||
#endif
|
||||
|
||||
const char *LogLevelNames[6] = {"trace", "debug", "info", "warning", "error", "fatal"};
|
||||
const char *LogCategoryNames[6] = {"network", "channel", "session", "server", "client", "userland"};
|
||||
|
||||
#if (defined(__GNUC__) && defined(__GNUC_MINOR__) && __GNUC__ >= 4 && __GNUC_MINOR__ >= 6) || defined(__clang__)
|
||||
# pragma GCC diagnostic push
|
||||
# pragma GCC diagnostic ignored "-Wformat-nonliteral"
|
||||
#endif
|
||||
|
||||
void UA_Log_Stdout(UA_LogLevel level, UA_LogCategory category, const char *msg, ...) {
|
||||
void
|
||||
UA_Log_Stdout(UA_LogLevel level, UA_LogCategory category,
|
||||
const char *msg, va_list args) {
|
||||
UA_String t = UA_DateTime_toString(UA_DateTime_now());
|
||||
#ifdef UA_ENABLE_MULTITHREADING
|
||||
pthread_mutex_lock(&printf_mutex);
|
||||
#endif
|
||||
printf("[%.23s] %s/%s\t", t.data, LogLevelNames[level], LogCategoryNames[category]);
|
||||
UA_ByteString_deleteMembers(&t);
|
||||
va_list ap;
|
||||
va_start(ap, msg);
|
||||
vprintf(msg, ap);
|
||||
va_end(ap);
|
||||
vprintf(msg, args);
|
||||
printf("\n");
|
||||
}
|
||||
|
||||
#if (defined(__GNUC__) && defined(__GNUC_MINOR__) && __GNUC__ >= 4 && __GNUC_MINOR__ >= 6) || defined(__clang__)
|
||||
# pragma GCC diagnostic pop
|
||||
#ifdef UA_ENABLE_MULTITHREADING
|
||||
pthread_mutex_unlock(&printf_mutex);
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -11,7 +11,9 @@
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
UA_EXPORT void UA_Log_Stdout(UA_LogLevel level, UA_LogCategory category, const char *msg, ...);
|
||||
UA_EXPORT void
|
||||
UA_Log_Stdout(UA_LogLevel level, UA_LogCategory category,
|
||||
const char *msg, va_list args);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user