Ticket #9260: log.patch

File log.patch, 5.5 KB (added by lordhoto, 14 years ago)

Patch against trunk r54415

  • new file ackends/log/log.cpp

    diff --git a/backends/log/log.cpp b/backends/log/log.cpp
    new file mode 100644
    index 0000000..dc7145c
    - +  
     1/* ScummVM - Graphic Adventure Engine
     2 *
     3 * ScummVM is the legal property of its developers, whose names
     4 * are too numerous to list here. Please refer to the COPYRIGHT
     5 * file distributed with this source distribution.
     6 *
     7 * This program is free software; you can redistribute it and/or
     8 * modify it under the terms of the GNU General Public License
     9 * as published by the Free Software Foundation; either version 2
     10 * of the License, or (at your option) any later version.
     11 *
     12 * This program is distributed in the hope that it will be useful,
     13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
     14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     15 * GNU General Public License for more details.
     16 *
     17 * You should have received a copy of the GNU General Public License
     18 * along with this program; if not, write to the Free Software
     19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
     20 *
     21 * $URL$
     22 * $Id$
     23 *
     24 */
     25
     26#include "backends/log/log.h"
     27
     28#include "common/stream.h"
     29#include "common/str.h"
     30#include "common/system.h"
     31
     32#include "base/version.h"
     33
     34namespace Backends {
     35namespace Log {
     36
     37Log::Log(OSystem *system) : _system(system), _stream(0) {
     38        assert(system);
     39}
     40
     41void Log::open(Common::WriteStream *stream) {
     42        close();
     43
     44        _stream = stream;
     45        print(gScummVMFullVersion);
     46        print("\n", false);
     47        print("--- Log opened.\n");
     48}
     49
     50void Log::close() {
     51        if (_stream) {
     52                print("--- Log closed successfully.\n");
     53
     54                delete _stream;
     55                _stream = 0;
     56        }
     57}
     58
     59void Log::print(const char *message, const bool printTime) {
     60        if (!_stream)
     61                return;
     62
     63        if (printTime) {
     64                const uint32 time = _system->getMillis();
     65                _stream->writeString(Common::String::format("[%10d] ", time));
     66        }
     67
     68        _stream->write(message, strlen(message));
     69        _stream->flush();
     70}
     71
     72} // End of namespace Log
     73} // End of namespace Backends
     74
  • new file ackends/log/log.h

    diff --git a/backends/log/log.h b/backends/log/log.h
    new file mode 100644
    index 0000000..ef9f9a2
    - +  
     1/* ScummVM - Graphic Adventure Engine
     2 *
     3 * ScummVM is the legal property of its developers, whose names
     4 * are too numerous to list here. Please refer to the COPYRIGHT
     5 * file distributed with this source distribution.
     6 *
     7 * This program is free software; you can redistribute it and/or
     8 * modify it under the terms of the GNU General Public License
     9 * as published by the Free Software Foundation; either version 2
     10 * of the License, or (at your option) any later version.
     11 *
     12 * This program is distributed in the hope that it will be useful,
     13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
     14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     15 * GNU General Public License for more details.
     16 *
     17 * You should have received a copy of the GNU General Public License
     18 * along with this program; if not, write to the Free Software
     19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
     20 *
     21 * $URL$
     22 * $Id$
     23 *
     24 */
     25
     26#ifndef BACKENDS_LOG_LOG_H
     27#define BACKENDS_LOG_LOG_H
     28
     29#include "common/scummsys.h"
     30
     31class OSystem;
     32
     33namespace Common {
     34class WriteStream;
     35} // End of namespace Common
     36
     37namespace Backends {
     38namespace Log {
     39
     40class Log {
     41public:
     42        Log(OSystem *system);
     43        ~Log() { close(); }
     44
     45        void open(Common::WriteStream *stream);
     46        void close();
     47
     48        void print(const char *message, const bool printTime = true);
     49private:
     50        OSystem *_system;
     51        Common::WriteStream *_stream;
     52};
     53
     54} // End of namespace Log
     55} // End of namespace Backends
     56
     57#endif
     58
  • backends/module.mk

    diff --git a/backends/module.mk b/backends/module.mk
    index db03e80..fab0751 100644
    a b MODULE_OBJS := \  
    1515        keymapper/keymap.o \
    1616        keymapper/keymapper.o \
    1717        keymapper/remap-dialog.o \
     18        log/log.o \
    1819        midi/alsa.o \
    1920        midi/camd.o \
    2021        midi/coreaudio.o \
  • backends/platform/sdl/sdl.cpp

    diff --git a/backends/platform/sdl/sdl.cpp b/backends/platform/sdl/sdl.cpp
    index 8a139e5..589c553 100644
    a b void OSystem_SDL::initBackend() {  
    182182                error("Could not initialize SDL: %s", SDL_GetError());
    183183        }
    184184
     185        _logger = new Backends::Log::Log(this);
     186        assert(_logger);
     187        _logger->open(Common::FSNode("~/scummvm-log").createWriteStream());
     188
    185189        _graphicsMutex = createMutex();
    186190
    187191        SDL_ShowCursor(SDL_DISABLE);
    OSystem_SDL::OSystem_SDL()  
    304308        memset(&_mouseCurState, 0, sizeof(_mouseCurState));
    305309
    306310        _inited = false;
    307 
     311        _logger = 0;
    308312
    309313        #if defined(__amigaos4__)
    310314                _fsFactory = new AmigaOSFilesystemFactory();
    void OSystem_SDL::deinit() {  
    545549        free(_mouseData);
    546550
    547551        delete _timer;
     552        delete _logger;
    548553
    549554        SDL_Quit();
    550555
    void OSystem_SDL::quit() {  
    564569
    565570void OSystem_SDL::logMessage(LogMessageType::Type type, const char *message) {
    566571        BaseBackend::logMessage(type, message);
     572        if (_logger)
     573                _logger->print(message);
    567574
    568575#if defined( USE_WINDBG )
    569576#if defined( _WIN32_WCE )
  • backends/platform/sdl/sdl.h

    diff --git a/backends/platform/sdl/sdl.h b/backends/platform/sdl/sdl.h
    index 328bb03..660ad07 100644
    a b  
    3333#endif
    3434
    3535#include "backends/base-backend.h"
     36#include "backends/log/log.h"
    3637#include "graphics/scaler.h"
    3738
    3839
    public:  
    243244
    244245protected:
    245246        bool _inited;
     247
     248        // Logging
     249        Backends::Log::Log *_logger;
     250
    246251        SDL_AudioSpec _obtainedRate;
    247252
    248253#ifdef USE_OSD