From 983904bbdce5d0973c3cda143f499872e55013e3 Mon Sep 17 00:00:00 2001 From: Chris Robinson Date: Fri, 28 Dec 2018 02:16:46 -0800 Subject: Add a method to prefix logged function names --- Alc/helpers.cpp | 8 ++++---- Alc/logging.h | 16 +++++----------- 2 files changed, 9 insertions(+), 15 deletions(-) (limited to 'Alc') diff --git a/Alc/helpers.cpp b/Alc/helpers.cpp index 2db544b8..4a80c7e5 100644 --- a/Alc/helpers.cpp +++ b/Alc/helpers.cpp @@ -361,7 +361,7 @@ void *GetSymbol(void *handle, const char *name) } -void al_print(const char *type, const char *func, const char *fmt, ...) +void al_print(const char *type, const char *prefix, const char *func, const char *fmt, ...) { char str[1024]; va_list ap; @@ -372,7 +372,7 @@ void al_print(const char *type, const char *func, const char *fmt, ...) str[sizeof(str)-1] = 0; std::wstring wstr{utf8_to_wstr(str)}; - fprintf(gLogFile, "AL lib: %s %s: %ls", type, func, wstr.c_str()); + fprintf(gLogFile, "AL lib: %s %s%s: %ls", type, prefix, func, wstr.c_str()); fflush(gLogFile); } @@ -588,12 +588,12 @@ void *GetSymbol(void *handle, const char *name) #endif /* HAVE_DLFCN_H */ -void al_print(const char *type, const char *func, const char *fmt, ...) +void al_print(const char *type, const char *prefix, const char *func, const char *fmt, ...) { va_list ap; va_start(ap, fmt); - fprintf(gLogFile, "AL lib: %s %s: ", type, func); + fprintf(gLogFile, "AL lib: %s %s%s: ", type, prefix, func); vfprintf(gLogFile, fmt, ap); va_end(ap); diff --git a/Alc/logging.h b/Alc/logging.h index 41f64f77..ae70e598 100644 --- a/Alc/logging.h +++ b/Alc/logging.h @@ -18,22 +18,20 @@ #define DECL_FORMAT(x, y, z) #endif -#ifdef __cplusplus -extern "C" { -#endif extern FILE *gLogFile; +constexpr inline const char *CurrentPrefix() noexcept { return ""; } #if defined(__GNUC__) && !defined(_WIN32) -#define AL_PRINT(T, MSG, ...) fprintf(gLogFile, "AL lib: %s %s: " MSG, T, __FUNCTION__ , ## __VA_ARGS__) +#define AL_PRINT(T, MSG, ...) fprintf(gLogFile, "AL lib: %s %s%s: " MSG, T, CurrentPrefix(), __FUNCTION__ , ## __VA_ARGS__) #else -void al_print(const char *type, const char *func, const char *fmt, ...) DECL_FORMAT(printf, 3,4); -#define AL_PRINT(T, ...) al_print((T), __FUNCTION__, __VA_ARGS__) +void al_print(const char *type, const char *prefix, const char *func, const char *fmt, ...) DECL_FORMAT(printf, 4,5); +#define AL_PRINT(T, ...) al_print((T), CurrentPrefix(), __FUNCTION__, __VA_ARGS__) #endif #ifdef __ANDROID__ #include -#define LOG_ANDROID(T, MSG, ...) __android_log_print(T, "openal", "AL lib: %s: " MSG, __FUNCTION__ , ## __VA_ARGS__) +#define LOG_ANDROID(T, MSG, ...) __android_log_print(T, "openal", "AL lib: %s%s: " MSG, CurrentPrefix(), __FUNCTION__ , ## __VA_ARGS__) #else #define LOG_ANDROID(T, MSG, ...) ((void)0) #endif @@ -70,8 +68,4 @@ extern LogLevel gLogLevel; LOG_ANDROID(ANDROID_LOG_ERROR, __VA_ARGS__); \ } while(0) -#ifdef __cplusplus -} /* extern "C" */ -#endif - #endif /* LOGGING_H */ -- cgit v1.2.3