[Scummvm-cvs-logs] SF.net SVN: scummvm:[54489] scummvm/trunk/backends/platform/sdl

lordhoto at users.sourceforge.net lordhoto at users.sourceforge.net
Fri Nov 26 01:51:42 CET 2010


Revision: 54489
          http://scummvm.svn.sourceforge.net/scummvm/?rev=54489&view=rev
Author:   lordhoto
Date:     2010-11-26 00:51:42 +0000 (Fri, 26 Nov 2010)

Log Message:
-----------
SDL: Hook up file logger to log on UNIX-like systems.

As discussed on -devel this always logs to ~/.scummvm/logs/scummvm.log.

Modified Paths:
--------------
    scummvm/trunk/backends/platform/sdl/sdl.cpp
    scummvm/trunk/backends/platform/sdl/sdl.h

Modified: scummvm/trunk/backends/platform/sdl/sdl.cpp
===================================================================
--- scummvm/trunk/backends/platform/sdl/sdl.cpp	2010-11-26 00:10:51 UTC (rev 54488)
+++ scummvm/trunk/backends/platform/sdl/sdl.cpp	2010-11-26 00:51:42 UTC (rev 54489)
@@ -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 @@
 		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 @@
 	_fsFactory(0),
 	_savefile(0),
 	_mixer(0),
+	_logger(0),
 	_timer(0),
 	_screenIsLocked(false),
 	_graphicsMutex(0), _transactionMode(kTransactionNone) {
@@ -476,6 +491,64 @@
 	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 @@
 	free(_mouseData);
 
 	delete _timer;
+	delete _logger;
+	_logger = 0;
 
 	SDL_Quit();
 
@@ -570,6 +645,8 @@
 
 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 )

Modified: scummvm/trunk/backends/platform/sdl/sdl.h
===================================================================
--- scummvm/trunk/backends/platform/sdl/sdl.h	2010-11-26 00:10:51 UTC (rev 54488)
+++ scummvm/trunk/backends/platform/sdl/sdl.h	2010-11-26 00:51:42 UTC (rev 54489)
@@ -33,6 +33,7 @@
 #endif
 
 #include "backends/base-backend.h"
+#include "backends/log/log.h"
 #include "graphics/scaler.h"
 
 
@@ -447,6 +448,10 @@
 	Common::SaveFileManager *_savefile;
 	Audio::MixerImpl *_mixer;
 
+	// Logging
+	virtual Common::WriteStream *createLogFile();
+	Backends::Log::Log *_logger;
+
 	SDL_TimerID _timerID;
 	Common::TimerManager *_timer;
 


This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.




More information about the Scummvm-git-logs mailing list