Settings: Default console logging to running from TTY

This commit is contained in:
Stenzek
2024-09-09 20:55:15 +10:00
parent fe9d06a194
commit d1770b616f
7 changed files with 26 additions and 17 deletions

View File

@ -18,6 +18,8 @@
#elif defined(__ANDROID__)
#include <android/log.h>
#else
#include <sys/ioctl.h>
#include <termios.h>
#include <unistd.h>
#endif
@ -128,6 +130,20 @@ float Log::GetCurrentMessageTime()
return static_cast<float>(Common::Timer::ConvertValueToSeconds(Common::Timer::GetCurrentValue() - s_start_timestamp));
}
bool Log::IsConsoleOutputCurrentlyAvailable()
{
#ifdef _WIN32
const HANDLE h = GetStdHandle(STD_OUTPUT_HANDLE);
return (h != NULL && h != INVALID_HANDLE_VALUE);
#elif defined(__ANDROID__)
return false;
#else
// standard output isn't really reliable because it could be redirected to a file. check standard input for tty.
struct termios attr;
return (tcgetattr(STDIN_FILENO, &attr) == 0);
#endif
}
bool Log::IsConsoleOutputEnabled()
{
return s_console_output_enabled;

View File

@ -41,6 +41,7 @@ void UnregisterCallback(CallbackFunctionType callbackFunction, void* pUserParam)
float GetCurrentMessageTime();
// adds a standard console output
bool IsConsoleOutputCurrentlyAvailable();
bool IsConsoleOutputEnabled();
void SetConsoleOutputParams(bool enabled, bool timestamps = true);