From c0cdb2ad99a1e2a6ade5ce76c91177a79258e669 Mon Sep 17 00:00:00 2001 From: Daniel Wilhelm Date: Fri, 18 Apr 2014 17:10:11 +0200 Subject: 3.14 --- library/error_log.cpp | 68 ++++++++++++++++++++++++++++++++++++--------------- 1 file changed, 48 insertions(+), 20 deletions(-) (limited to 'library/error_log.cpp') diff --git a/library/error_log.cpp b/library/error_log.cpp index 4f7c5847..1549c6b5 100644 --- a/library/error_log.cpp +++ b/library/error_log.cpp @@ -12,46 +12,74 @@ using ffs3::ErrorLogging; -void ErrorLogging::logInfo(const wxString& infoMessage) +void ErrorLogging::logMsg(const wxString& message, ffs3::MessageType type) { - const wxString prefix = wxString(wxT("[")) + wxDateTime::Now().FormatTime() + wxT("] ") + _("Info") + wxT(": "); - formattedMessages.push_back(assembleMessage(prefix, infoMessage)); -} + Entry newEntry; + newEntry.type = type; + newEntry.time = wxDateTime::GetTimeNow(); + newEntry.message = message; + messages.push_back(newEntry); -void ErrorLogging::logWarning(const wxString& warningMessage) -{ - const wxString prefix = wxString(wxT("[")) + wxDateTime::Now().FormatTime() + wxT("] ") + _("Warning") + wxT(": "); - formattedMessages.push_back(assembleMessage(prefix, warningMessage)); + ++statistics[type]; } -void ErrorLogging::logError(const wxString& errorMessage) +int ErrorLogging::typeCount(int types) const { - ++errorCount; + int count = 0; + + if (types & TYPE_INFO) + count += statistics[TYPE_INFO]; + if (types & TYPE_WARNING) + count += statistics[TYPE_WARNING]; + if (types & TYPE_ERROR) + count += statistics[TYPE_ERROR]; + if (types & TYPE_FATAL_ERROR) + count += statistics[TYPE_FATAL_ERROR]; - const wxString prefix = wxString(wxT("[")) + wxDateTime::Now().FormatTime() + wxT("] ") + _("Error") + wxT(": "); - formattedMessages.push_back(assembleMessage(prefix, errorMessage)); + return count; } -void ErrorLogging::logFatalError(const wxString& errorMessage) +std::vector ErrorLogging::getFormattedMessages(int types) const { - ++errorCount; + std::vector output; - const wxString prefix = wxString(wxT("[")) + wxDateTime::Now().FormatTime() + wxT("] ") + _("Fatal Error") + wxT(": "); - formattedMessages.push_back(assembleMessage(prefix, errorMessage)); + for (std::vector::const_iterator i = messages.begin(); i != messages.end(); ++i) + if (i->type & types) + output.push_back(formatMessage(*i)); + + return output; } -wxString ErrorLogging::assembleMessage(const wxString& prefix, const wxString& message) +wxString ErrorLogging::formatMessage(const Entry& msg) { - const size_t prefixLength = prefix.size(); + wxString typeName; + switch (msg.type) + { + case TYPE_INFO: + typeName = _("Info"); + break; + case TYPE_WARNING: + typeName = _("Warning"); + break; + case TYPE_ERROR: + typeName = _("Error"); + break; + case TYPE_FATAL_ERROR: + typeName = _("Fatal Error"); + break; + } + + const wxString prefix = wxString(wxT("[")) + wxDateTime(msg.time).FormatTime() + wxT("] ") + typeName + wxT(": "); + wxString formattedText = prefix; - for (wxString::const_iterator i = message.begin(); i != message.end(); ++i) + for (wxString::const_iterator i = msg.message.begin(); i != msg.message.end(); ++i) if (*i == wxChar('\n')) { - formattedText += wxString(wxChar('\n')).Pad(prefixLength, wxChar(' '), true); + formattedText += wxString(wxChar('\n')).Pad(prefix.size(), wxChar(' '), true); while (*++i == wxChar('\n')) //remove duplicate newlines ; --i; -- cgit