1 /* 2 Copyright (C) 2010-2014 Kristian Duske 3 4 This file is part of TrenchBroom. 5 6 TrenchBroom is free software: you can redistribute it and/or modify 7 it under the terms of the GNU General Public License as published by 8 the Free Software Foundation, either version 3 of the License, or 9 (at your option) any later version. 10 11 TrenchBroom is distributed in the hope that it will be useful, 12 but WITHOUT ANY WARRANTY; without even the implied warranty of 13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 GNU General Public License for more details. 15 16 You should have received a copy of the GNU General Public License 17 along with TrenchBroom. If not, see <http://www.gnu.org/licenses/>. 18 */ 19 20 #include "CachingLogger.h" 21 22 namespace TrenchBroom { 23 namespace View { Message(const Logger::LogLevel i_level,const wxString & i_str)24 CachingLogger::Message::Message(const Logger::LogLevel i_level, const wxString& i_str) : 25 level(i_level), 26 str(i_str) {} 27 CachingLogger()28 CachingLogger::CachingLogger() : 29 m_logger(NULL) {} 30 setParentLogger(Logger * logger)31 void CachingLogger::setParentLogger(Logger* logger) { 32 m_logger = logger; 33 if (m_logger != NULL) { 34 MessageList::const_iterator it, end; 35 for (it = m_cachedMessages.begin(), end = m_cachedMessages.end(); it != end; ++it) { 36 const Message& message = *it; 37 log(message.level, message.str); 38 } 39 m_cachedMessages.clear(); 40 } 41 } 42 doLog(const LogLevel level,const String & message)43 void CachingLogger::doLog(const LogLevel level, const String& message) { 44 doLog(level, wxString(message)); 45 } 46 doLog(const LogLevel level,const wxString & message)47 void CachingLogger::doLog(const LogLevel level, const wxString& message) { 48 if (m_logger == NULL) 49 m_cachedMessages.push_back(Message(level, message)); 50 else 51 m_logger->log(level, message); 52 } 53 } 54 } 55