gui: Add log to file option. don't create log file if disabled

This commit is contained in:
Flyinghead 2020-04-02 12:20:03 +02:00
parent 578071e8f9
commit 37d3625bf3
2 changed files with 24 additions and 2 deletions

View File

@ -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<LogTypes::LOG_LEVELS>(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));

View File

@ -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/<game id>");
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();