diff options
author | Chris Robinson <[email protected]> | 2018-12-28 02:16:46 -0800 |
---|---|---|
committer | Chris Robinson <[email protected]> | 2018-12-28 12:29:05 -0800 |
commit | 983904bbdce5d0973c3cda143f499872e55013e3 (patch) | |
tree | 201052174329b177066707d683f9da085aa28af6 /Alc | |
parent | aff58265cb458b2ac2c42fef96383e9751d094d1 (diff) |
Add a method to prefix logged function names
Diffstat (limited to 'Alc')
-rw-r--r-- | Alc/helpers.cpp | 8 | ||||
-rw-r--r-- | Alc/logging.h | 16 |
2 files changed, 9 insertions, 15 deletions
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 <android/log.h> -#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 */ |