[Scummvm-cvs-logs] SF.net SVN: scummvm:[54451] scummvm/trunk/backends

lordhoto at users.sourceforge.net lordhoto at users.sourceforge.net
Wed Nov 24 01:08:26 CET 2010


Revision: 54451
          http://scummvm.svn.sourceforge.net/scummvm/?rev=54451&view=rev
Author:   lordhoto
Date:     2010-11-24 00:08:26 +0000 (Wed, 24 Nov 2010)

Log Message:
-----------
BACKENDS: Add a basic logger implementation.

This is the logger I posted at our patch tracker. Item #3115757
"OSYSTEM: Basic logger". It includes the changes proposed by Max.

It is currently not hooked into any backend, since we still need to decide
where to log files, whether to have multiple log files etc.

Modified Paths:
--------------
    scummvm/trunk/backends/module.mk

Added Paths:
-----------
    scummvm/trunk/backends/log/
    scummvm/trunk/backends/log/log.cpp
    scummvm/trunk/backends/log/log.h

Added: scummvm/trunk/backends/log/log.cpp
===================================================================
--- scummvm/trunk/backends/log/log.cpp	                        (rev 0)
+++ scummvm/trunk/backends/log/log.cpp	2010-11-24 00:08:26 UTC (rev 54451)
@@ -0,0 +1,107 @@
+/* ScummVM - Graphic Adventure Engine
+ *
+ * ScummVM is the legal property of its developers, whose names
+ * are too numerous to list here. Please refer to the COPYRIGHT
+ * file distributed with this source distribution.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * $URL$
+ * $Id$
+ *
+ */
+
+#include "backends/log/log.h"
+
+#include "common/stream.h"
+#include "common/str.h"
+#include "common/system.h"
+
+#include "base/version.h"
+
+namespace Backends {
+namespace Log {
+
+Log::Log(OSystem *system)
+    : _system(system), _stream(0), _startOfLine(true) {
+	assert(system);
+}
+
+void Log::open(Common::WriteStream *stream) {
+	// Close the previous log
+	close();
+
+	_stream = stream;
+
+	// Output information about the ScummVM version at the start of the log
+	// file
+	print(gScummVMFullVersion);
+	print("\n");
+	print(gScummVMFeatures);
+	print("\n");
+	print("--- Log opened.\n");
+}
+
+void Log::close() {
+	if (_stream) {
+		// Output a message to indicate that the log was closed successfully
+		print("--- Log closed successfully.\n");
+
+		delete _stream;
+		_stream = 0;
+	}
+}
+
+void Log::print(const char *message, const bool printTime) {
+	if (!_stream)
+		return;
+
+	while (*message) {
+		if (_startOfLine) {
+			_startOfLine = false;
+			if (printTime)
+				printTimeStamp();
+		}
+
+		const char *msgStart = message;
+		// scan for end of line/string
+		while (*message && *message != '\n')
+			++message;
+
+		if (*message == '\n') {
+			++message;
+			_startOfLine = true;
+		}
+
+		// TODO: It might be wise to check for write errors and/or incomplete
+		// writes here, since losing certain bits of the log is not nice.
+		_stream->write(msgStart, message - msgStart);
+	}
+
+	_stream->flush();
+}
+
+void Log::printTimeStamp() {
+	TimeDate date;
+	_system->getTimeAndDate(date);
+
+	_stream->writeString(Common::String::format("[%d-%02d-%02d %02d:%02d:%02d] ",
+	                     date.tm_year + 1900, date.tm_mon, date.tm_mday,
+	                     date.tm_hour, date.tm_min, date.tm_sec));
+}
+
+} // End of namespace Log
+} // End of namespace Backends
+


Property changes on: scummvm/trunk/backends/log/log.cpp
___________________________________________________________________
Added: svn:mime-type
   + text/plain
Added: svn:keywords
   + Date Rev Author URL Id
Added: svn:eol-style
   + native

Added: scummvm/trunk/backends/log/log.h
===================================================================
--- scummvm/trunk/backends/log/log.h	                        (rev 0)
+++ scummvm/trunk/backends/log/log.h	2010-11-24 00:08:26 UTC (rev 54451)
@@ -0,0 +1,132 @@
+/* ScummVM - Graphic Adventure Engine
+ *
+ * ScummVM is the legal property of its developers, whose names
+ * are too numerous to list here. Please refer to the COPYRIGHT
+ * file distributed with this source distribution.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * $URL$
+ * $Id$
+ *
+ */
+
+#ifndef BACKENDS_LOG_LOG_H
+#define BACKENDS_LOG_LOG_H
+
+#include "common/scummsys.h"
+
+class OSystem;
+
+namespace Common {
+class WriteStream;
+} // End of namespace Common
+
+namespace Backends {
+namespace Log {
+
+/**
+ * Log file writer.
+ *
+ * This can be used by the backends to implement file logging functionality.
+ */
+class Log {
+public:
+	/**
+	 * Constructor for the logger object.
+	 *
+	 * @param system The OSystem instance to use. Must be non-null.
+	 */
+	Log(OSystem *system);
+	~Log() { close(); }
+
+	/**
+	 * Opens a new log file.
+	 *
+	 * The previous log, which was handled by this logger, will be closed
+	 * before the new stream is associated.
+	 *
+	 * The current implemention will always call flush after data is written
+	 * to the log file. It might thus be wise to pass an unbuffered write
+	 * stream here to avoid unnecessary overhead.
+	 * @see Common::WriteStream::flush
+	 *
+	 * Calling open with stream being 0 is valid and will result in the same
+	 * behavior as calling close, but it may have additional overhead.
+	 * @see close
+	 *
+	 * This function will output information about the ScummVM version and
+	 * the features built into ScummVM automatically. It will also add a short
+	 * notice to indicate that the log was opened successfully.
+	 *
+	 * @param stream Stream where to output the log contents.
+	 *               Note that the stream will be deleted by the logger.
+	 */
+	void open(Common::WriteStream *stream);
+
+	/**
+	 * Closes the current log file.
+	 *
+	 * This function will output a line saying that the log was closed
+	 * successfully. This can be used to check whether a log is incomplete
+	 * because of whatever reasons.
+	 */
+	void close();
+
+	/**
+	 * Prints a message to the log stream.
+	 *
+	 * This has optional support to output a timestamp on every new line.
+	 * The timestamp will look like: "[YYYY-MM-DD HH:MM:SS] ".
+	 * Printing of a timestamp is done by default.
+	 *
+	 * It might be noteworthy that this function does not append a new line
+	 * to the given message.
+	 *
+	 * In case no stream is associated with this logger, this function will
+	 * quit immediatly.
+	 *
+	 * @param message            The message to write.
+	 * @param printTimeOnNewline Whether to print a timestamp on the start of
+	 *                           a new line.
+	 */
+	void print(const char *message, const bool printTimeOnNewline = true);
+private:
+	/**
+	 * Prints a time stamp in the form: "[YYYY-MM-DD HH:MM:SS] ".
+	 */
+	void printTimeStamp();
+
+	/**
+	 * The OSystem instance used to query data like the time.
+	 */
+	OSystem *_system;
+
+	/**
+	 * Where to write the output too.
+	 */
+	Common::WriteStream *_stream;
+
+	/**
+	 * Whether we are at the start of a line.
+	 */
+	bool _startOfLine;
+};
+
+} // End of namespace Log
+} // End of namespace Backends
+
+#endif
+


Property changes on: scummvm/trunk/backends/log/log.h
___________________________________________________________________
Added: svn:mime-type
   + text/plain
Added: svn:keywords
   + Date Rev Author URL Id
Added: svn:eol-style
   + native

Modified: scummvm/trunk/backends/module.mk
===================================================================
--- scummvm/trunk/backends/module.mk	2010-11-23 22:49:45 UTC (rev 54450)
+++ scummvm/trunk/backends/module.mk	2010-11-24 00:08:26 UTC (rev 54451)
@@ -15,6 +15,7 @@
 	keymapper/keymap.o \
 	keymapper/keymapper.o \
 	keymapper/remap-dialog.o \
+	log/log.o \
 	midi/alsa.o \
 	midi/camd.o \
 	midi/coreaudio.o \


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