summaryrefslogtreecommitdiff
path: root/zen/error_log.h
diff options
context:
space:
mode:
authorB. Stack <bgstack15@gmail.com>2022-06-26 16:00:37 +0000
committerB. Stack <bgstack15@gmail.com>2022-06-26 16:00:37 +0000
commit2a026bc7d76875b88700bebc7c5a801fef881bfd (patch)
treef820b53379f3d14e103e2663e8b0ecd38d1b2105 /zen/error_log.h
parentMerge branch 'b11.21' into 'master' (diff)
parentadd upstream 11.22 (diff)
downloadFreeFileSync-11.22.tar.gz
FreeFileSync-11.22.tar.bz2
FreeFileSync-11.22.zip
Merge branch '11.22' into 'master'11.22
add upstream 11.22 See merge request opensource-tracking/FreeFileSync!45
Diffstat (limited to 'zen/error_log.h')
-rw-r--r--zen/error_log.h43
1 files changed, 15 insertions, 28 deletions
diff --git a/zen/error_log.h b/zen/error_log.h
index 357232f3..ff630cb8 100644
--- a/zen/error_log.h
+++ b/zen/error_log.h
@@ -32,30 +32,17 @@ struct LogEntry
std::string formatMessage(const LogEntry& entry);
+using ErrorLog = std::vector<LogEntry>;
-class ErrorLog
-{
-public:
- void logMsg(const std::wstring& msg, MessageType type, time_t time = std::time(nullptr));
+void logMsg(ErrorLog& log, const std::wstring& msg, MessageType type, time_t time = std::time(nullptr));
- struct Stats
- {
- int info = 0;
- int warning = 0;
- int error = 0;
- };
- Stats getStats() const;
-
- //subset of std::vector<> interface:
- using const_iterator = std::vector<LogEntry>::const_iterator;
- const_iterator begin() const { return entries_.begin(); }
- const_iterator end () const { return entries_.end (); }
- bool empty() const { return entries_.empty(); }
-
-private:
- std::vector<LogEntry> entries_;
+struct ErrorLogStats
+{
+ int info = 0;
+ int warning = 0;
+ int error = 0;
};
-
+ErrorLogStats getStats(const ErrorLog& log);
@@ -65,18 +52,17 @@ private:
//######################## implementation ##########################
inline
-void ErrorLog::logMsg(const std::wstring& msg, MessageType type, time_t time)
+void logMsg(ErrorLog& log, const std::wstring& msg, MessageType type, time_t time)
{
- entries_.push_back({time, type, utfTo<Zstringc>(msg)});
+ log.push_back({time, type, utfTo<Zstringc>(msg)});
}
-
inline
-ErrorLog::Stats ErrorLog::getStats() const
+ErrorLogStats getStats(const ErrorLog& log)
{
- Stats count;
- for (const LogEntry& entry : entries_)
+ ErrorLogStats count;
+ for (const LogEntry& entry : log)
switch (entry.type)
{
case MSG_TYPE_INFO:
@@ -89,7 +75,7 @@ ErrorLog::Stats ErrorLog::getStats() const
++count.error;
break;
}
- assert(std::ssize(entries_) == count.info + count.warning + count.error);
+ assert(std::ssize(log) == count.info + count.warning + count.error);
return count;
}
@@ -119,6 +105,7 @@ std::string formatMessage(const LogEntry& entry)
const Zstringc msg = trimCpy(entry.message);
static_assert(std::is_same_v<decltype(msg), const Zstringc>, "no worries about copying as long as we're using a ref-counted string!");
+ assert(msg == entry.message); //trimming shouldn't be needed usually!?
for (auto it = msg.begin(); it != msg.end(); )
if (*it == '\n')
bgstack15