aboutsummaryrefslogtreecommitdiff
path: root/backends/platform/sdl/sdl.cpp
diff options
context:
space:
mode:
authorJohannes Schickel2010-11-26 00:51:42 +0000
committerJohannes Schickel2010-11-26 00:51:42 +0000
commit425f28405036a0ee6422fe848476561100ade6ab (patch)
treee09cd402080897c5920bc311a8fc3c23778d234e /backends/platform/sdl/sdl.cpp
parente793d62c8d5f6406f9ff78dce8d8c7972458463f (diff)
downloadscummvm-rg350-425f28405036a0ee6422fe848476561100ade6ab.tar.gz
scummvm-rg350-425f28405036a0ee6422fe848476561100ade6ab.tar.bz2
scummvm-rg350-425f28405036a0ee6422fe848476561100ade6ab.zip
SDL: Hook up file logger to log on UNIX-like systems.
As discussed on -devel this always logs to ~/.scummvm/logs/scummvm.log. svn-id: r54489
Diffstat (limited to 'backends/platform/sdl/sdl.cpp')
-rw-r--r--backends/platform/sdl/sdl.cpp77
1 files changed, 77 insertions, 0 deletions
diff --git a/backends/platform/sdl/sdl.cpp b/backends/platform/sdl/sdl.cpp
index ea7d4b0523..5e09eaa957 100644
--- a/backends/platform/sdl/sdl.cpp
+++ b/backends/platform/sdl/sdl.cpp
@@ -92,6 +92,10 @@
#include <CoreFoundation/CoreFoundation.h>
#endif
+#if defined(UNIX)
+#include <errno.h>
+#include <sys/stat.h>
+#endif
static Uint32 timer_handler(Uint32 interval, void *param) {
((DefaultTimerManager *)param)->handler();
@@ -188,6 +192,16 @@ void OSystem_SDL::initBackend() {
error("Could not initialize SDL: %s", SDL_GetError());
}
+
+ if (!_logger)
+ _logger = new Backends::Log::Log(this);
+
+ if (_logger) {
+ Common::WriteStream *logFile = createLogFile();
+ if (logFile)
+ _logger->open(logFile);
+ }
+
_graphicsMutex = createMutex();
SDL_ShowCursor(SDL_DISABLE);
@@ -295,6 +309,7 @@ OSystem_SDL::OSystem_SDL()
_fsFactory(0),
_savefile(0),
_mixer(0),
+ _logger(0),
_timer(0),
_screenIsLocked(false),
_graphicsMutex(0), _transactionMode(kTransactionNone) {
@@ -476,6 +491,64 @@ Common::WriteStream *OSystem_SDL::createConfigWriteStream() {
return file.createWriteStream();
}
+#define DEFAULT_LOG_FILE "scummvm.log"
+
+Common::WriteStream *OSystem_SDL::createLogFile() {
+#if defined(MACOSX)
+ return 0;
+#elif defined(UNIX)
+ const char *home = getenv("HOME");
+ if (home == NULL)
+ return 0;
+
+ Common::String logFile(home);
+ logFile += "/.scummvm";
+
+ struct stat sb;
+
+ // Check whether the dir exists
+ if (stat(logFile.c_str(), &sb) == -1) {
+ // The dir does not exist, or stat failed for some other reason.
+ if (errno != ENOENT)
+ return 0;
+
+ // If the problem was that the path pointed to nothing, try
+ // to create the dir.
+ if (mkdir(logFile.c_str(), 0755) != 0)
+ return 0;
+ } else if (!S_ISDIR(sb.st_mode)) {
+ // Path is no directory. Oops
+ return 0;
+ }
+
+ logFile += "/logs";
+
+ // Check whether the dir exists
+ if (stat(logFile.c_str(), &sb) == -1) {
+ // The dir does not exist, or stat failed for some other reason.
+ if (errno != ENOENT)
+ return 0;
+
+ // If the problem was that the path pointed to nothing, try
+ // to create the dir.
+ if (mkdir(logFile.c_str(), 0755) != 0)
+ return 0;
+ } else if (!S_ISDIR(sb.st_mode)) {
+ // Path is no directory. Oops
+ return 0;
+ }
+
+ logFile += "/" DEFAULT_LOG_FILE;
+
+ Common::FSNode file(logFile);
+ return file.createWriteStream();
+#elif defined (WIN32) && !defined(_WIN32_WCE) && !defined(__SYMBIAN32__)
+ return 0;
+#else
+ return 0;
+#endif
+}
+
void OSystem_SDL::setWindowCaption(const char *caption) {
Common::String cap;
byte c;
@@ -551,6 +624,8 @@ void OSystem_SDL::deinit() {
free(_mouseData);
delete _timer;
+ delete _logger;
+ _logger = 0;
SDL_Quit();
@@ -570,6 +645,8 @@ void OSystem_SDL::quit() {
void OSystem_SDL::logMessage(LogMessageType::Type type, const char *message) {
BaseBackend::logMessage(type, message);
+ if (_logger)
+ _logger->print(message);
#if defined( USE_WINDBG )
#if defined( _WIN32_WCE )