From 37d3625bf395d4cb4a33719fd71a32054673bfce Mon Sep 17 00:00:00 2001 From: Flyinghead Date: Thu, 2 Apr 2020 12:20:03 +0200 Subject: [PATCH] gui: Add log to file option. don't create log file if disabled --- core/log/LogManager.cpp | 13 +++++++++++-- core/rend/gui.cpp | 13 +++++++++++++ 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/core/log/LogManager.cpp b/core/log/LogManager.cpp index 1f9341bfb..50bbde58c 100644 --- a/core/log/LogManager.cpp +++ b/core/log/LogManager.cpp @@ -18,6 +18,7 @@ #include "StringUtil.h" #include "cfg/cfg.h" #include "oslib/oslib.h" +#include "stdclass.h" constexpr size_t MAX_MSGLEN = 1024; @@ -114,7 +115,6 @@ LogManager::LogManager() m_log[LogTypes::SAVESTATE] = {"SAVESTATE", "Save States"}; m_log[LogTypes::SH4] = {"SH4", "SH4 Modules"}; - RegisterListener(LogListener::FILE_LISTENER, new FileLogListener("flycast.log")); RegisterListener(LogListener::CONSOLE_LISTENER, new ConsoleListener()); // Set up log listeners @@ -127,7 +127,16 @@ LogManager::LogManager() verbosity = MAX_LOGLEVEL; SetLogLevel(static_cast(verbosity)); - EnableListener(LogListener::FILE_LISTENER, cfgLoadBool("log", "LogToFile", false)); + if (cfgLoadBool("log", "LogToFile", false)) + { +#ifdef __ANDROID__ + std::string logPath = get_writable_data_path("/flycast.log"); +#else + std::string logPath = "flycast.log"; +#endif + RegisterListener(LogListener::FILE_LISTENER, new FileLogListener(logPath)); + EnableListener(LogListener::FILE_LISTENER, true); + } EnableListener(LogListener::CONSOLE_LISTENER, cfgLoadBool("log", "LogToConsole", true)); // EnableListener(LogListener::LOG_WINDOW_LISTENER, Config::Get(LOGGER_WRITE_TO_WINDOW)); diff --git a/core/rend/gui.cpp b/core/rend/gui.cpp index 3086075f2..03eac9da4 100644 --- a/core/rend/gui.cpp +++ b/core/rend/gui.cpp @@ -39,6 +39,7 @@ #include "version.h" #include "oslib/audiostream.h" #include "imgread/common.h" +#include "log/LogManager.h" extern void dc_loadstate(); extern void dc_savestate(); @@ -1295,6 +1296,18 @@ static void gui_display_settings() ImGui::Checkbox("Dump Textures", &settings.rend.DumpTextures); ImGui::SameLine(); ShowHelpMarker("Dump all textures into data/texdump/"); + + bool logToFile = cfgLoadBool("log", "LogToFile", false); + bool newLogToFile = logToFile; + ImGui::Checkbox("Log to File", &newLogToFile); + if (logToFile != newLogToFile) + { + cfgSaveBool("log", "LogToFile", newLogToFile); + LogManager::Shutdown(); + LogManager::Init(); + } + ImGui::SameLine(); + ShowHelpMarker("Log debug information to flycast.log"); } ImGui::PopStyleVar(); ImGui::EndTabItem();