Stop the Oboe recording stream when recording is stopped
[openal-soft.git] / core / logging.cpp
blobdd7f53c79ed970c5fe6af5694654eba182c5fe0c
2 #include "config.h"
4 #include "logging.h"
6 #include <cstdarg>
7 #include <cstdio>
8 #include <string>
10 #include "strutils.h"
11 #include "vector.h"
14 #ifdef _WIN32
16 #define WIN32_LEAN_AND_MEAN
17 #include <windows.h>
19 void al_print(LogLevel level, FILE *logfile, const char *fmt, ...)
21 al::vector<char> dynmsg;
22 char stcmsg[256];
23 char *str{stcmsg};
25 std::va_list args, args2;
26 va_start(args, fmt);
27 va_copy(args2, args);
28 int msglen{std::vsnprintf(str, sizeof(stcmsg), fmt, args)};
29 if UNLIKELY(msglen >= 0 && static_cast<size_t>(msglen) >= sizeof(stcmsg))
31 dynmsg.resize(static_cast<size_t>(msglen) + 1u);
32 str = dynmsg.data();
33 msglen = std::vsnprintf(str, dynmsg.size(), fmt, args2);
35 va_end(args2);
36 va_end(args);
38 std::wstring wstr{utf8_to_wstr(str)};
39 if(gLogLevel >= level)
41 fputws(wstr.c_str(), logfile);
42 fflush(logfile);
44 OutputDebugStringW(wstr.c_str());
47 #else
49 #ifdef __ANDROID__
50 #include <android/log.h>
51 #endif
53 void al_print(LogLevel level, FILE *logfile, const char *fmt, ...)
55 al::vector<char> dynmsg;
56 char stcmsg[256];
57 char *str{stcmsg};
59 std::va_list args, args2;
60 va_start(args, fmt);
61 va_copy(args2, args);
62 int msglen{std::vsnprintf(str, sizeof(stcmsg), fmt, args)};
63 if UNLIKELY(msglen >= 0 && static_cast<size_t>(msglen) >= sizeof(stcmsg))
65 dynmsg.resize(static_cast<size_t>(msglen) + 1u);
66 str = dynmsg.data();
67 msglen = std::vsnprintf(str, dynmsg.size(), fmt, args2);
69 va_end(args2);
70 va_end(args);
72 if(gLogLevel >= level)
74 std::fputs(str, logfile);
75 std::fflush(logfile);
77 #ifdef __ANDROID__
78 auto android_severity = [](LogLevel l) noexcept
80 switch(l)
82 case LogLevel::Trace: return ANDROID_LOG_DEBUG;
83 case LogLevel::Warning: return ANDROID_LOG_WARN;
84 case LogLevel::Error: return ANDROID_LOG_ERROR;
85 /* Should not happen. */
86 case LogLevel::Disable:
87 break;
89 return ANDROID_LOG_ERROR;
91 __android_log_print(android_severity(level), "openal", "%s", str);
92 #endif
95 #endif