ResidualVM logo ResidualVM website - Forums - Contact us BuildBot - Doxygen - Wiki curved edge

log.cpp

Go to the documentation of this file.
00001 /* ScummVM - Graphic Adventure Engine
00002  *
00003  * ScummVM is the legal property of its developers, whose names
00004  * are too numerous to list here. Please refer to the COPYRIGHT
00005  * file distributed with this source distribution.
00006  *
00007  * This program is free software; you can redistribute it and/or
00008  * modify it under the terms of the GNU General Public License
00009  * as published by the Free Software Foundation; either version 2
00010  * of the License, or (at your option) any later version.
00011  *
00012  * This program is distributed in the hope that it will be useful,
00013  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015  * GNU General Public License for more details.
00016  *
00017  * You should have received a copy of the GNU General Public License
00018  * along with this program; if not, write to the Free Software
00019  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
00020  *
00021  */
00022 
00023 #include "backends/log/log.h"
00024 
00025 #include "common/stream.h"
00026 #include "common/str.h"
00027 #include "common/system.h"
00028 
00029 #include "base/version.h"
00030 
00031 namespace Backends {
00032 namespace Log {
00033 
00034 Log::Log(OSystem *system)
00035     : _system(system), _stream(0), _startOfLine(true) {
00036     assert(system);
00037 }
00038 
00039 void Log::open(Common::WriteStream *stream) {
00040     // Close the previous log
00041     close();
00042 
00043     _stream = stream;
00044 
00045     // Output information about the ScummVM version at the start of the log
00046     // file
00047     print(gScummVMFullVersion);
00048     print("\n");
00049     print(gScummVMFeatures);
00050     print("\n");
00051     print("--- Log opened.\n");
00052     _startOfLine = true;
00053 }
00054 
00055 void Log::close() {
00056     if (_stream) {
00057         // Output a message to indicate that the log was closed successfully
00058         print("--- Log closed successfully.\n");
00059 
00060         delete _stream;
00061         _stream = 0;
00062     }
00063 }
00064 
00065 void Log::print(const char *message, const bool printTime) {
00066     if (!_stream)
00067         return;
00068 
00069     while (*message) {
00070         if (_startOfLine) {
00071             _startOfLine = false;
00072             if (printTime)
00073                 printTimeStamp();
00074         }
00075 
00076         const char *msgStart = message;
00077         // scan for end of line/string
00078         while (*message && *message != '\n')
00079             ++message;
00080 
00081         if (*message == '\n') {
00082             ++message;
00083             _startOfLine = true;
00084         }
00085 
00086         // TODO: It might be wise to check for write errors and/or incomplete
00087         // writes here, since losing certain bits of the log is not nice.
00088         _stream->write(msgStart, message - msgStart);
00089     }
00090 
00091     _stream->flush();
00092 }
00093 
00094 void Log::printTimeStamp() {
00095     TimeDate date;
00096     int curMonth;
00097     _system->getTimeAndDate(date);
00098     curMonth = date.tm_mon + 1; // month is base 0, we need base 1 (1 = january and so on)
00099 
00100     _stream->writeString(Common::String::format("[%d-%02d-%02d %02d:%02d:%02d] ",
00101                          date.tm_year + 1900, curMonth, date.tm_mday,
00102                          date.tm_hour, date.tm_min, date.tm_sec));
00103 }
00104 
00105 } // End of namespace Log
00106 } // End of namespace Backends


Generated on Sat Jul 13 2019 05:00:54 for ResidualVM by doxygen 1.7.1
curved edge   curved edge