summaryrefslogtreecommitdiff
path: root/library/error_log.cpp
diff options
context:
space:
mode:
authorDaniel Wilhelm <daniel@wili.li>2014-04-18 17:10:11 +0200
committerDaniel Wilhelm <daniel@wili.li>2014-04-18 17:10:11 +0200
commitc0cdb2ad99a1e2a6ade5ce76c91177a79258e669 (patch)
tree4701a015385d9a6a5a4ba99a8f1f5d400fff26b1 /library/error_log.cpp
parent3.13 (diff)
downloadFreeFileSync-c0cdb2ad99a1e2a6ade5ce76c91177a79258e669.tar.gz
FreeFileSync-c0cdb2ad99a1e2a6ade5ce76c91177a79258e669.tar.bz2
FreeFileSync-c0cdb2ad99a1e2a6ade5ce76c91177a79258e669.zip
3.14
Diffstat (limited to 'library/error_log.cpp')
-rw-r--r--library/error_log.cpp68
1 files changed, 48 insertions, 20 deletions
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<wxString> ErrorLogging::getFormattedMessages(int types) const
{
- ++errorCount;
+ std::vector<wxString> output;
- const wxString prefix = wxString(wxT("[")) + wxDateTime::Now().FormatTime() + wxT("] ") + _("Fatal Error") + wxT(": ");
- formattedMessages.push_back(assembleMessage(prefix, errorMessage));
+ for (std::vector<Entry>::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;
bgstack15