SDL: Add --logfile command line argument to specify logfile path

This commit is contained in:
Thierry Crozat 2020-04-12 18:48:51 +01:00
parent 259a7bc3e0
commit b196d26b3e
2 changed files with 22 additions and 11 deletions

View file

@ -150,16 +150,6 @@ void OSystem_SDL::init() {
// Disable OS cursor // Disable OS cursor
SDL_ShowCursor(SDL_DISABLE); SDL_ShowCursor(SDL_DISABLE);
if (!_logger)
_logger = new Backends::Log::Log(this);
if (_logger) {
Common::WriteStream *logFile = createLogFile();
if (logFile)
_logger->open(logFile);
}
// Creates the early needed managers, if they don't exist yet // Creates the early needed managers, if they don't exist yet
// (we check for this to allow subclasses to provide their own). // (we check for this to allow subclasses to provide their own).
if (_mutexManager == 0) if (_mutexManager == 0)
@ -189,6 +179,15 @@ void OSystem_SDL::initBackend() {
// Check if backend has not been initialized // Check if backend has not been initialized
assert(!_inited); assert(!_inited);
if (!_logger)
_logger = new Backends::Log::Log(this);
if (_logger) {
Common::WriteStream *logFile = createLogFile();
if (logFile)
_logger->open(logFile);
}
#if SDL_VERSION_ATLEAST(2, 0, 0) #if SDL_VERSION_ATLEAST(2, 0, 0)
const char *sdlDriverName = SDL_GetCurrentVideoDriver(); const char *sdlDriverName = SDL_GetCurrentVideoDriver();
#else #else
@ -435,7 +434,11 @@ Common::WriteStream *OSystem_SDL::createLogFile() {
// of a failure, we know that no log file is open. // of a failure, we know that no log file is open.
_logFilePath.clear(); _logFilePath.clear();
Common::String logFile = getDefaultLogFileName(); Common::String logFile;
if (ConfMan.hasKey("logfile"))
logFile = ConfMan.get("logfile");
else
logFile = getDefaultLogFileName();
if (logFile.empty()) if (logFile.empty())
return nullptr; return nullptr;

View file

@ -87,6 +87,9 @@ static const char HELP_STRING[] =
#endif #endif
"\n" "\n"
" -c, --config=CONFIG Use alternate configuration file\n" " -c, --config=CONFIG Use alternate configuration file\n"
#if defined(SDL_BACKEND)
" -l, --logfile=PATH Use alternate path for log file\n"
#endif
" -p, --path=PATH Path to where the game is installed\n" " -p, --path=PATH Path to where the game is installed\n"
" -x, --save-slot[=NUM] Save game slot to load (default: autosave)\n" " -x, --save-slot[=NUM] Save game slot to load (default: autosave)\n"
" -f, --fullscreen Force full-screen mode\n" " -f, --fullscreen Force full-screen mode\n"
@ -544,6 +547,11 @@ Common::String parseCommandLine(Common::StringMap &settings, int argc, const cha
DO_OPTION('c', "config") DO_OPTION('c', "config")
END_OPTION END_OPTION
#if defined(SDL_BACKEND)
DO_OPTION('l', "logfile")
END_OPTION
#endif
DO_OPTION_INT('b', "boot-param") DO_OPTION_INT('b', "boot-param")
END_OPTION END_OPTION