3DS: Log all messages to a file

This commit is contained in:
Cameron Cawley 2021-08-23 15:26:14 +01:00 committed by Eugene Sandulenko
parent 322f2386de
commit 3c5d806894
2 changed files with 49 additions and 1 deletions

View File

@ -84,7 +84,8 @@ OSystem_3DS::OSystem_3DS():
_screenChangeId(0), _screenChangeId(0),
_magnifyMode(MODE_MAGOFF), _magnifyMode(MODE_MAGOFF),
exiting(false), exiting(false),
sleeping(false) sleeping(false),
_logger(0)
{ {
chdir("sdmc:/"); chdir("sdmc:/");
@ -116,6 +117,9 @@ OSystem_3DS::~OSystem_3DS() {
destroyAudio(); destroyAudio();
destroy3DSGraphics(); destroy3DSGraphics();
delete _logger;
_logger = 0;
delete _timerManager; delete _timerManager;
_timerManager = 0; _timerManager = 0;
} }
@ -125,6 +129,15 @@ void OSystem_3DS::quit() {
} }
void OSystem_3DS::initBackend() { void OSystem_3DS::initBackend() {
if (!_logger)
_logger = new Backends::Log::Log(this);
if (_logger) {
Common::WriteStream *logFile = createLogFile();
if (logFile)
_logger->open(logFile);
}
loadConfig(); loadConfig();
ConfMan.registerDefault("fullscreen", true); ConfMan.registerDefault("fullscreen", true);
ConfMan.registerDefault("aspect_ratio", true); ConfMan.registerDefault("aspect_ratio", true);
@ -157,6 +170,10 @@ Common::String OSystem_3DS::getDefaultConfigFileName() {
return "sdmc:/3ds/scummvm/scummvm.ini"; return "sdmc:/3ds/scummvm/scummvm.ini";
} }
Common::String OSystem_3DS::getDefaultLogFileName() {
return "sdmc:/3ds/scummvm/scummvm.log";
}
void OSystem_3DS::addSysArchivesToSearchSet(Common::SearchSet &s, int priority) { void OSystem_3DS::addSysArchivesToSearchSet(Common::SearchSet &s, int priority) {
s.add("RomFS", new Common::FSDirectory(DATA_PATH"/"), priority); s.add("RomFS", new Common::FSDirectory(DATA_PATH"/"), priority);
} }
@ -222,6 +239,30 @@ void OSystem_3DS::fatalError() {
void OSystem_3DS::logMessage(LogMessageType::Type type, const char *message) { void OSystem_3DS::logMessage(LogMessageType::Type type, const char *message) {
printf("%s", message); printf("%s", message);
// Then log into file (via the logger)
if (_logger)
_logger->print(message);
}
Common::WriteStream *OSystem_3DS::createLogFile() {
// Start out by resetting _logFilePath, so that in case
// of a failure, we know that no log file is open.
_logFilePath.clear();
Common::String logFile;
if (ConfMan.hasKey("logfile"))
logFile = ConfMan.get("logfile");
else
logFile = getDefaultLogFileName();
if (logFile.empty())
return nullptr;
Common::FSNode file(logFile);
Common::WriteStream *stream = file.createWriteStream();
if (stream)
_logFilePath = logFile;
return stream;
} }
} // namespace N3DS } // namespace N3DS

View File

@ -31,6 +31,7 @@
#include "base/main.h" #include "base/main.h"
#include "audio/mixer_intern.h" #include "audio/mixer_intern.h"
#include "backends/graphics/graphics.h" #include "backends/graphics/graphics.h"
#include "backends/log/log.h"
#include "backends/platform/3ds/sprite.h" #include "backends/platform/3ds/sprite.h"
#include "common/rect.h" #include "common/rect.h"
#include "common/queue.h" #include "common/queue.h"
@ -201,8 +202,12 @@ private:
void flushGameScreen(); void flushGameScreen();
void flushCursor(); void flushCursor();
virtual Common::String getDefaultLogFileName();
virtual Common::WriteStream *createLogFile();
protected: protected:
Audio::MixerImpl *_mixer; Audio::MixerImpl *_mixer;
Backends::Log::Log *_logger;
private: private:
u16 _gameWidth, _gameHeight; u16 _gameWidth, _gameHeight;
@ -287,6 +292,8 @@ private:
u16 _magWidth, _magHeight; u16 _magWidth, _magHeight;
u16 _magCenterX, _magCenterY; u16 _magCenterX, _magCenterY;
Common::String _logFilePath;
public: public:
// Pause // Pause
PauseToken _sleepPauseToken; PauseToken _sleepPauseToken;