Settings: Default console logging to running from TTY

This commit is contained in:
Stenzek 2024-09-09 20:55:15 +10:00
parent 163a9d6ae4
commit 2fe4877dbc
No known key found for this signature in database
7 changed files with 26 additions and 17 deletions

View File

@ -18,6 +18,8 @@
#elif defined(__ANDROID__) #elif defined(__ANDROID__)
#include <android/log.h> #include <android/log.h>
#else #else
#include <sys/ioctl.h>
#include <termios.h>
#include <unistd.h> #include <unistd.h>
#endif #endif
@ -128,6 +130,20 @@ float Log::GetCurrentMessageTime()
return static_cast<float>(Common::Timer::ConvertValueToSeconds(Common::Timer::GetCurrentValue() - s_start_timestamp)); 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() bool Log::IsConsoleOutputEnabled()
{ {
return s_console_output_enabled; return s_console_output_enabled;

View File

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

View File

@ -5146,7 +5146,7 @@ void FullscreenUI::DrawAdvancedSettingsPage()
"LogLevel", Settings::DEFAULT_LOG_LEVEL, &Settings::ParseLogLevelName, &Settings::GetLogLevelName, "LogLevel", Settings::DEFAULT_LOG_LEVEL, &Settings::ParseLogLevelName, &Settings::GetLogLevelName,
&Settings::GetLogLevelDisplayName, LOGLEVEL_COUNT); &Settings::GetLogLevelDisplayName, LOGLEVEL_COUNT);
DrawToggleSetting(bsi, FSUI_CSTR("Log To System Console"), FSUI_CSTR("Logs messages to the console window."), DrawToggleSetting(bsi, FSUI_CSTR("Log To System Console"), FSUI_CSTR("Logs messages to the console window."),
FSUI_CSTR("Logging"), "LogToConsole", Settings::DEFAULT_LOG_TO_CONSOLE); FSUI_CSTR("Logging"), "LogToConsole", false);
DrawToggleSetting(bsi, FSUI_CSTR("Log To Debug Console"), DrawToggleSetting(bsi, FSUI_CSTR("Log To Debug Console"),
FSUI_CSTR("Logs messages to the debug console where supported."), "Logging", "LogToDebug", false); FSUI_CSTR("Logs messages to the debug console where supported."), "Logging", "LogToDebug", false);
DrawToggleSetting(bsi, FSUI_CSTR("Log To File"), FSUI_CSTR("Logs messages to duckstation.log in the user directory."), DrawToggleSetting(bsi, FSUI_CSTR("Log To File"), FSUI_CSTR("Logs messages to duckstation.log in the user directory."),

View File

@ -421,7 +421,7 @@ void Settings::Load(SettingsInterface& si, SettingsInterface& controller_si)
.value_or(DEFAULT_LOG_LEVEL); .value_or(DEFAULT_LOG_LEVEL);
log_filter = si.GetStringValue("Logging", "LogFilter", ""); log_filter = si.GetStringValue("Logging", "LogFilter", "");
log_timestamps = si.GetBoolValue("Logging", "LogTimestamps", true); log_timestamps = si.GetBoolValue("Logging", "LogTimestamps", true);
log_to_console = si.GetBoolValue("Logging", "LogToConsole", DEFAULT_LOG_TO_CONSOLE); log_to_console = si.GetBoolValue("Logging", "LogToConsole", false);
log_to_debug = si.GetBoolValue("Logging", "LogToDebug", false); log_to_debug = si.GetBoolValue("Logging", "LogToDebug", false);
log_to_window = si.GetBoolValue("Logging", "LogToWindow", false); log_to_window = si.GetBoolValue("Logging", "LogToWindow", false);
log_to_file = si.GetBoolValue("Logging", "LogToFile", false); log_to_file = si.GetBoolValue("Logging", "LogToFile", false);
@ -450,9 +450,6 @@ void Settings::Load(SettingsInterface& si, SettingsInterface& controller_si)
si.GetIntValue("TextureReplacements", "DumpVRAMWriteHeightThreshold", 128); si.GetIntValue("TextureReplacements", "DumpVRAMWriteHeightThreshold", 128);
#ifdef __ANDROID__ #ifdef __ANDROID__
// No expansion due to license incompatibility.
audio_expansion_mode = AudioExpansionMode::Disabled;
// Android users are incredibly silly and don't understand that stretch is in the aspect ratio list... // Android users are incredibly silly and don't understand that stretch is in the aspect ratio list...
if (si.GetBoolValue("Display", "Stretch", false)) if (si.GetBoolValue("Display", "Stretch", false))
display_aspect_ratio = DisplayAspectRatio::MatchWindow; display_aspect_ratio = DisplayAspectRatio::MatchWindow;

View File

@ -277,7 +277,7 @@ struct Settings
LOGLEVEL log_level = DEFAULT_LOG_LEVEL; LOGLEVEL log_level = DEFAULT_LOG_LEVEL;
std::string log_filter; std::string log_filter;
bool log_timestamps : 1 = true; bool log_timestamps : 1 = true;
bool log_to_console : 1 = DEFAULT_LOG_TO_CONSOLE; bool log_to_console : 1 = false;
bool log_to_debug : 1 = false; bool log_to_debug : 1 = false;
bool log_to_window : 1 = false; bool log_to_window : 1 = false;
bool log_to_file : 1 = false; bool log_to_file : 1 = false;
@ -529,13 +529,6 @@ struct Settings
static constexpr u32 DEFAULT_MEDIA_CAPTURE_AUDIO_BITRATE = 128; static constexpr u32 DEFAULT_MEDIA_CAPTURE_AUDIO_BITRATE = 128;
#endif #endif
// Enable console logging by default on Linux platforms.
#if defined(__linux__) && !defined(__ANDROID__)
static constexpr bool DEFAULT_LOG_TO_CONSOLE = true;
#else
static constexpr bool DEFAULT_LOG_TO_CONSOLE = false;
#endif
// Android doesn't create settings until they're first opened, so we have to override the defaults here. // Android doesn't create settings until they're first opened, so we have to override the defaults here.
#ifndef __ANDROID__ #ifndef __ANDROID__
static constexpr bool DEFAULT_SAVE_STATE_BACKUPS = true; static constexpr bool DEFAULT_SAVE_STATE_BACKUPS = true;

View File

@ -1347,6 +1347,11 @@ void System::SetDefaultSettings(SettingsInterface& si)
temp.Save(si, false); temp.Save(si, false);
#if !defined(_WIN32) && !defined(__ANDROID__)
// On Linux, default the console to whether standard input is currently available.
si.SetBoolValue("Logging", "LogToConsole", Log::IsConsoleOutputCurrentlyAvailable());
#endif
#ifndef __ANDROID__ #ifndef __ANDROID__
si.SetStringValue("MediaCapture", "Backend", MediaCapture::GetBackendName(Settings::DEFAULT_MEDIA_CAPTURE_BACKEND)); si.SetStringValue("MediaCapture", "Backend", MediaCapture::GetBackendName(Settings::DEFAULT_MEDIA_CAPTURE_BACKEND));
si.SetStringValue("MediaCapture", "Container", Settings::DEFAULT_MEDIA_CAPTURE_CONTAINER); si.SetStringValue("MediaCapture", "Container", Settings::DEFAULT_MEDIA_CAPTURE_CONTAINER);

View File

@ -472,11 +472,8 @@ bool QtHost::InitializeConfig(std::string settings_filename)
MigrateSettings(); MigrateSettings();
// We need to create the console window early, otherwise it appears in front of the main window. // We need to create the console window early, otherwise it appears in front of the main window.
if (!Log::IsConsoleOutputEnabled() && if (!Log::IsConsoleOutputEnabled() && s_base_settings_interface->GetBoolValue("Logging", "LogToConsole", false))
s_base_settings_interface->GetBoolValue("Logging", "LogToConsole", Settings::DEFAULT_LOG_TO_CONSOLE))
{
Log::SetConsoleOutputParams(true, s_base_settings_interface->GetBoolValue("Logging", "LogTimestamps", true)); Log::SetConsoleOutputParams(true, s_base_settings_interface->GetBoolValue("Logging", "LogTimestamps", true));
}
UpdateApplicationLanguage(nullptr); UpdateApplicationLanguage(nullptr);
return true; return true;