aboutsummaryrefslogtreecommitdiffstats
path: root/alc/helpers.cpp
diff options
context:
space:
mode:
authorChris Robinson <[email protected]>2020-09-28 11:34:24 -0700
committerChris Robinson <[email protected]>2020-09-28 11:34:24 -0700
commitf02bc1354d406707619c3f4704e06c9d15b24f63 (patch)
treeebd59b653f71c3b00a0df2e7217cd3a17cdcd519 /alc/helpers.cpp
parentda29489ead3ecfc269a220a22ee117d93bed23a6 (diff)
Rework logging a little
Use OutputDebugStringW on Windows in addition to the log file Avoid duplicate formatter parsing with Android
Diffstat (limited to 'alc/helpers.cpp')
-rw-r--r--alc/helpers.cpp58
1 files changed, 49 insertions, 9 deletions
diff --git a/alc/helpers.cpp b/alc/helpers.cpp
index 2b262b65..369ab9f1 100644
--- a/alc/helpers.cpp
+++ b/alc/helpers.cpp
@@ -80,7 +80,7 @@ const PathNamePair &GetProcBinary()
}
-void al_print(FILE *logfile, const char *fmt, ...)
+void al_print(LogLevel level, FILE *logfile, const char *fmt, ...)
{
al::vector<char> dynmsg;
char stcmsg[256];
@@ -100,8 +100,12 @@ void al_print(FILE *logfile, const char *fmt, ...)
va_end(args);
std::wstring wstr{utf8_to_wstr(str)};
- fputws(wstr.c_str(), logfile);
- fflush(logfile);
+ if(gLogLevel >= level)
+ {
+ fputws(wstr.c_str(), logfile);
+ fflush(logfile);
+ }
+ OutputDebugStringW(wstr.c_str());
}
@@ -221,6 +225,9 @@ void SetRTPriority(void)
#ifdef __HAIKU__
#include <FindDirectory.h>
#endif
+#ifdef __ANDROID__
+#include <android/log.h>
+#endif
#ifdef HAVE_PROC_PIDPATH
#include <libproc.h>
#endif
@@ -316,14 +323,47 @@ const PathNamePair &GetProcBinary()
}
-void al_print(FILE *logfile, const char *fmt, ...)
+void al_print(LogLevel level, FILE *logfile, const char *fmt, ...)
{
- std::va_list ap;
- va_start(ap, fmt);
- vfprintf(logfile, fmt, ap);
- va_end(ap);
+ al::vector<char> dynmsg;
+ char stcmsg[256];
+ char *str{stcmsg};
- fflush(logfile);
+ va_list args, args2;
+ va_start(args, fmt);
+ va_copy(args2, args);
+ int msglen{std::vsnprintf(str, sizeof(stcmsg), fmt, args)};
+ if UNLIKELY(msglen >= 0 && static_cast<size_t>(msglen) >= sizeof(stcmsg))
+ {
+ dynmsg.resize(static_cast<size_t>(msglen) + 1u);
+ str = dynmsg.data();
+ msglen = std::vsnprintf(str, dynmsg.size(), fmt, args2);
+ }
+ va_end(args2);
+ va_end(args);
+
+ if(gLogLevel >= level)
+ {
+ fputs(str, logfile);
+ fflush(logfile);
+ }
+#ifdef __ANDROID__
+ auto android_severity = [](LogLevel l) noexcept
+ {
+ switch(l)
+ {
+ case LogLevel::Trace: return ANDROID_LOG_DEBUG;
+ case LogLevel::Warning: return ANDROID_LOG_WARN;
+ case LogLevel::Error: return ANDROID_LOG_ERROR;
+ /* Should not happen. */
+ case LogLevel::Ref:
+ case LogLevel::Disable:
+ break;
+ }
+ return ANDROID_LOG_ERROR;
+ };
+ __android_log_print(android_severity(level), "openal", "%s", str);
+#endif
}