diff --git a/alc/alc.cpp b/alc/alc.cpp index 942c7078..71d0b219 100644 --- a/alc/alc.cpp +++ b/alc/alc.cpp @@ -161,7 +161,6 @@ #endif // ALSOFT_EAX -FILE *gLogFile{stderr}; #ifdef _DEBUG LogLevel gLogLevel{LogLevel::Warning}; #else diff --git a/core/logging.cpp b/core/logging.cpp index 34a95e5a..2d897690 100644 --- a/core/logging.cpp +++ b/core/logging.cpp @@ -11,28 +11,13 @@ #include "strutils.h" #include "vector.h" - -#if defined(_WIN32) -#define WIN32_LEAN_AND_MEAN -#include -#elif defined(__ANDROID__) -#include -#endif - -void al_print(LogLevel level, FILE *logfile, const char *fmt, ...) +void al_print(LogLevel level, const char *fmt, ...) { /* Kind of ugly since string literals are const char arrays with a size * that includes the null terminator, which we want to exclude from the * span. */ auto prefix = al::as_span("[ALSOFT] (--) ").first<14>(); - switch(level) - { - case LogLevel::Disable: break; - case LogLevel::Error: prefix = al::as_span("[ALSOFT] (EE) ").first<14>(); break; - case LogLevel::Warning: prefix = al::as_span("[ALSOFT] (WW) ").first<14>(); break; - case LogLevel::Trace: prefix = al::as_span("[ALSOFT] (II) ").first<14>(); break; - } al::vector dynmsg; std::array stcmsg{}; @@ -60,30 +45,20 @@ void al_print(LogLevel level, FILE *logfile, const char *fmt, ...) if(gLogLevel >= level) { - fputs(str, logfile); - fflush(logfile); - } -#if defined(_WIN32) && !defined(NDEBUG) - /* OutputDebugStringW has no 'level' property to distinguish between - * informational, warning, or error debug messages. So only print them for - * non-Release builds. - */ - std::wstring wstr{utf8_to_wstr(str)}; - OutputDebugStringW(wstr.c_str()); -#elif defined(__ANDROID__) - auto android_severity = [](LogLevel l) noexcept - { - switch(l) + switch (level) { - 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::Disable: + case LogLevel::Error: + AuLogError("{}", str); break; + case LogLevel::Warning: + AuLogWarn("{}", str); + break; + case LogLevel::Trace: + AuLogVerbose("{}", str); + break; + default: + AuLogGame("{}", str); } - return ANDROID_LOG_ERROR; - }; - __android_log_print(android_severity(level), "openal", "%s", str); -#endif + } } diff --git a/core/logging.h b/core/logging.h index e2f9d7ac..fdf3abdb 100644 --- a/core/logging.h +++ b/core/logging.h @@ -14,34 +14,32 @@ enum class LogLevel { }; extern LogLevel gLogLevel; -extern FILE *gLogFile; - - -void al_print(LogLevel level, FILE *logfile, const char *fmt, ...); +void al_print(LogLevel level, const char *fmt, ...); #if (!defined(_WIN32) || defined(NDEBUG)) && !defined(__ANDROID__) -#define TRACE(...) do { \ - if(gLogLevel >= LogLevel::Trace) UNLIKELY \ - al_print(LogLevel::Trace, gLogFile, __VA_ARGS__); \ + +#define TRACE(...) do { \ + if(gLogLevel >= LogLevel::Trace) UNLIKELY \ + al_print(LogLevel::Trace, __VA_ARGS__); \ } while(0) -#define WARN(...) do { \ - if(gLogLevel >= LogLevel::Warning) UNLIKELY \ - al_print(LogLevel::Warning, gLogFile, __VA_ARGS__); \ -} while(0) +#define WARN(...) do { \ + if(gLogLevel >= LogLevel::Warning) UNLIKELY \ + al_print(LogLevel::Warning, __VA_ARGS__); \ +} while(0) -#define ERR(...) do { \ - if(gLogLevel >= LogLevel::Error) UNLIKELY \ - al_print(LogLevel::Error, gLogFile, __VA_ARGS__); \ +#define ERR(...) do { \ + if(gLogLevel >= LogLevel::Error) UNLIKELY \ + al_print(LogLevel::Error, __VA_ARGS__); \ } while(0) #else -#define TRACE(...) al_print(LogLevel::Trace, gLogFile, __VA_ARGS__) +#define TRACE(...) al_print(LogLevel::Trace, __VA_ARGS__) -#define WARN(...) al_print(LogLevel::Warning, gLogFile, __VA_ARGS__) +#define WARN(...) al_print(LogLevel::Warning, __VA_ARGS__) -#define ERR(...) al_print(LogLevel::Error, gLogFile, __VA_ARGS__) +#define ERR(...) al_print(LogLevel::Error, __VA_ARGS__) #endif #endif /* CORE_LOGGING_H */