Ref T111, allow to limit entries in log component

This commit is contained in:
Klaus Basan
2017-08-08 02:23:27 +02:00
committed by Mathew Sutcliffe
parent 4c8ae06eff
commit 266a418c90
6 changed files with 73 additions and 3 deletions

View File

@@ -139,6 +139,25 @@ namespace BlackMisc
this->removeIf(&CStatusMessage::getSeverity, CStatusMessage::SeverityInfo);
}
int CStatusMessageList::keepLatest(int estimtatedNumber)
{
const int oldSize = this->size();
if (estimtatedNumber >= oldSize) { return 0; }
if (estimtatedNumber < 1)
{
this->clear();
return oldSize;
}
CStatusMessageList copy(*this);
copy.sortLatestFirst();
const QDateTime ts = copy[estimtatedNumber - 1].getUtcTimestamp();
copy = *this; // keep order
copy.removeBefore(ts);
*this = copy;
return oldSize - this->size();
}
CStatusMessage::StatusSeverity CStatusMessageList::worstSeverity() const
{
CStatusMessage::StatusSeverity s = CStatusMessage::SeverityDebug;

View File

@@ -97,6 +97,10 @@ namespace BlackMisc
//! Remove info and below
void removeInfoAndBelow();
//! Keep latest n status messages
//! \remark taking timestamp of n-th oldest messages, deleting all older
int keepLatest(int estimtatedNumber);
//! Find worst severity
CStatusMessage::StatusSeverity worstSeverity() const;