new support for a limit of the log size in the backend,

small changes to the output format

svn path=/trunk/kdepim/; revision=289528
wilder-work
Andreas Gungl 22 years ago
parent 73eec6b0b0
commit fb2b6b4925
  1. 58
      filterlog.cpp
  2. 27
      filterlog.h
  3. 14
      filterlogdlg.cpp
  4. 1
      filterlogdlg.h
  5. 18
      kmsearchpattern.cpp

@ -37,6 +37,21 @@ using namespace KMail;
FilterLog * FilterLog::self = NULL;
FilterLog::FilterLog()
{
self = this;
// start with logging enabled by default
logging = true;
// better limit the log to 512 KByte to avoid out of memory situations
// when the log i sgoing to become very long
maxLogSize = 512 * 1024;
currentLogSize = 0;
allowedTypes = meta | patternDesc | ruleResult |
patternResult | appliedAction;
};
FilterLog::~FilterLog()
{}
@ -57,12 +72,24 @@ void FilterLog::add( QString logEntry, ContentType contentType )
{
logEntries.append( logEntry );
emit logEntryAdded( logEntry );
// FIXME remove it
kdDebug(5006) << "New filter log entry added."<< endl;
currentLogSize += logEntry.length();
checkLogSize();
}
}
void FilterLog::setMaxLogSize( long size )
{
if ( size < -1)
size = -1;
// do not allow less than 1 KByte except unlimited (-1)
if ( size >= 0 && size < 1024 )
size = 1024;
maxLogSize = size;
checkLogSize();
};
void FilterLog::dump()
{
#ifndef NDEBUG
@ -77,4 +104,31 @@ void FilterLog::dump()
}
void FilterLog::checkLogSize()
{
if ( currentLogSize > maxLogSize && maxLogSize >= -1 )
{
kdDebug(5006) << "Filter log: memory limit reached, starting to discard old items, size = "
<< QString::number( currentLogSize ) << endl;
// avoid some kind of hysteresis, shrink the log to 90% of its maximum
while ( currentLogSize > ( maxLogSize * 0.9 ) )
{
QValueListIterator<QString> it = logEntries.begin();
if ( it != logEntries.end())
{
currentLogSize -= (*it).length();
logEntries.remove( it );
kdDebug(5006) << "Filter log: new size = " << QString::number( currentLogSize ) << endl;
}
else
{
kdDebug(5006) << "Filter log: size reduction disaster!" << endl;
clear();
}
}
emit logShrinked();
}
}
#include "filterlog.moc"

@ -63,8 +63,12 @@ namespace KMail {
bool isLogging() { return logging; };
/** set the logging state */
void setLogging( bool active ) { logging = active; };
/** control the size of the log */
void setMaxLogSize( long size = -1 );
/** add a content type to the set of logged ones */
void enableContentType( ContentType contentType ) { allowedTypes |= contentType; };
void enableContentType( ContentType contentType ) { allowedTypes |= contentType; };
/** remove a content type from the set of logged ones */
void disableContentType( ContentType contentType ) { allowedTypes &= ~contentType; };
@ -73,7 +77,7 @@ namespace KMail {
/** add a separating line in the log */
void addSeparator() { add( "------------------------------", meta ); };
/** discard collected log data */
void clear() { logEntries.clear(); };
void clear() { logEntries.clear(); currentLogSize = 0; };
/** get access to the log entries */
const QStringList & getLogEntries() { return logEntries; };
@ -85,22 +89,29 @@ namespace KMail {
signals:
void logEntryAdded( QString );
void logShrinked();
protected:
/** Non-public constructor needed by the singleton implementation */
FilterLog()
{
self = this;
logging = true;
allowedTypes = meta | patternDesc | ruleResult | patternResult | appliedAction;
};
FilterLog();
/** The list contains the single log pieces */
QStringList logEntries;
/** the log status */
bool logging;
/** max size for kept log items, when reached
the last recently added items are discarded
-1 means unlimited */
long maxLogSize;
long currentLogSize;
/** types currently allowed to be legged */
int allowedTypes;
void checkLogSize();
private:
static FilterLog * self;
};

@ -57,6 +57,8 @@ FilterLogDialog::FilterLogDialog( QWidget * parent )
connect(FilterLog::instance(), SIGNAL(logEntryAdded(QString)),
this, SLOT(slotLogEntryAdded(QString)));
connect(FilterLog::instance(), SIGNAL(logShrinked(void)),
this, SLOT(slotLogShrinked(void)));
setInitialSize( QSize( 500, 300 ) );
}
@ -68,6 +70,18 @@ void FilterLogDialog::slotLogEntryAdded( QString logEntry )
}
void FilterLogDialog::slotLogShrinked()
{
textEdit->clear();
QStringList logEntries = FilterLog::instance()->getLogEntries();
for ( QStringList::Iterator it = logEntries.begin();
it != logEntries.end(); ++it )
{
textEdit->append( *it );
}
}
void FilterLogDialog::slotUser1()
{
FilterLog::instance()->clear();

@ -52,6 +52,7 @@ namespace KMail {
protected slots:
void slotLogEntryAdded( QString logEntry );
void slotLogShrinked();
protected:
virtual void slotUser1();

@ -137,7 +137,7 @@ bool KMSearchRule::matches( const DwString & aStr, KMMessage & msg,
const QString KMSearchRule::asString() const
{
QString result = "\t\"" + mField + "\" <";
QString result = "\"" + mField + "\" <";
result += funcConfigNames[(int)mFunction];
result += "> \"" + mContents + "\"";
@ -285,7 +285,7 @@ bool KMSearchRuleString::matches( const KMMessage * msg ) const
}
bool rc = matchesInternal( msgContents );
if ( FilterLog::instance()->isLogging() ) {
QString msg = ( rc ? "\t1 = " : "\t0 = " );
QString msg = ( rc ? "1 = " : "0 = " );
msg += asString() + " (" + msgContents + ")";
FilterLog::instance()->add( msg, FilterLog::ruleResult );
}
@ -378,9 +378,9 @@ bool KMSearchRuleNumerical::matches( const KMMessage * msg ) const
}
bool rc = matchesInternal( numericalValue, numericalMsgContents, msgContents );
if ( FilterLog::instance()->isLogging() ) {
QString msg = ( rc ? "\t1 = " : "\t0 = " );
msg += asString() + " ( " + QString::number(numericalValue);
msg += " / " + QString::number(numericalMsgContents) + " )";
QString msg = ( rc ? "1 = " : "0 = " );
msg += asString() + " ( " + QString::number( numericalMsgContents );
msg += " / " + QString::number( numericalValue ) + " )";
FilterLog::instance()->add( msg, FilterLog::ruleResult );
}
return rc;
@ -514,7 +514,7 @@ bool KMSearchRuleStatus::matches( const KMMessage * msg ) const
}
if ( FilterLog::instance()->isLogging() ) {
QString msg = ( rc ? "\t1 = " : "\t0 = " );
QString msg = ( rc ? "1 = " : "0 = " );
msg += asString();
FilterLog::instance()->add( msg, FilterLog::ruleResult );
}
@ -722,12 +722,12 @@ void KMSearchPattern::init() {
QString KMSearchPattern::asString() const {
QString result = "\t";
if ( mOperator == OpOr )
result += i18n("(match any of the following)") + "\n";
result += i18n("(match any of the following)") + '\n';
else
result += i18n("(match all of the following)") + "\n";
result += i18n("(match all of the following)") + '\n';
for ( QPtrListIterator<KMSearchRule> it( *this ) ; it.current() ; ++it )
result += (*it)->asString() + '\n';
result += '\t' + (*it)->asString() + '\n';
return result;
}

Loading…
Cancel
Save