slightly simplified wxLog repetition counting code
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@49403 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -301,20 +301,20 @@ protected:
|
|||||||
#define wxSUPPRESS_DOLOGSTRING_HIDE_WARNING()
|
#define wxSUPPRESS_DOLOGSTRING_HIDE_WARNING()
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// log a line containing the number of times the previous message was
|
// log a message indicating the number of times the previous message was
|
||||||
// repeated
|
// repeated; only does something if ms_prevCounter > 0
|
||||||
// returns: the number
|
static void LogLastRepetitionCountIfNeeded();
|
||||||
static unsigned DoLogNumberOfRepeats();
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
// static variables
|
// static variables
|
||||||
// ----------------
|
// ----------------
|
||||||
|
|
||||||
// traditional behaviour or counting repetitions
|
// if true, don't log the same message multiple times, only log it once
|
||||||
|
// with the number of times it was repeated
|
||||||
static bool ms_bRepetCounting;
|
static bool ms_bRepetCounting;
|
||||||
|
|
||||||
static wxString ms_prevString; // previous message that was logged
|
static wxString ms_prevString; // previous message that was logged
|
||||||
// how many times the previous message was logged
|
static unsigned ms_prevCounter; // how many times it was repeated
|
||||||
static unsigned ms_prevCounter;
|
|
||||||
static time_t ms_prevTimeStamp;// timestamp of the previous message
|
static time_t ms_prevTimeStamp;// timestamp of the previous message
|
||||||
static wxLogLevel ms_prevLevel; // level of the previous message
|
static wxLogLevel ms_prevLevel; // level of the previous message
|
||||||
|
|
||||||
|
@@ -458,11 +458,10 @@ void WXDLLEXPORT wxVLogSysError(unsigned long err, const wxString& format, va_li
|
|||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
|
|
||||||
/* static */
|
/* static */
|
||||||
unsigned wxLog::DoLogNumberOfRepeats()
|
void wxLog::LogLastRepetitionCountIfNeeded()
|
||||||
{
|
{
|
||||||
long retval = ms_prevCounter;
|
|
||||||
wxLog *pLogger = GetActiveTarget();
|
wxLog *pLogger = GetActiveTarget();
|
||||||
if ( pLogger && ms_prevCounter > 0 )
|
if ( pLogger && ms_prevCounter )
|
||||||
{
|
{
|
||||||
wxString msg;
|
wxString msg;
|
||||||
#if wxUSE_INTL
|
#if wxUSE_INTL
|
||||||
@@ -471,23 +470,18 @@ unsigned wxLog::DoLogNumberOfRepeats()
|
|||||||
ms_prevCounter),
|
ms_prevCounter),
|
||||||
ms_prevCounter);
|
ms_prevCounter);
|
||||||
#else
|
#else
|
||||||
msg.Printf(wxT("The previous message was repeated."));
|
msg.Printf(wxT("The previous message was repeated %lu times."),
|
||||||
|
ms_prevCounter);
|
||||||
#endif
|
#endif
|
||||||
ms_prevCounter = 0;
|
ms_prevCounter = 0;
|
||||||
ms_prevString.clear();
|
ms_prevString.clear();
|
||||||
pLogger->DoLog(ms_prevLevel, msg, ms_prevTimeStamp);
|
pLogger->DoLog(ms_prevLevel, msg, ms_prevTimeStamp);
|
||||||
}
|
}
|
||||||
return retval;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
wxLog::~wxLog()
|
wxLog::~wxLog()
|
||||||
{
|
{
|
||||||
if ( ms_prevCounter > 0 )
|
LogLastRepetitionCountIfNeeded();
|
||||||
{
|
|
||||||
// looks like the repeat count has not been logged yet,
|
|
||||||
// so let's do it now
|
|
||||||
wxLog::DoLogNumberOfRepeats();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* static */
|
/* static */
|
||||||
@@ -498,21 +492,26 @@ void wxLog::OnLog(wxLogLevel level, const wxString& szString, time_t t)
|
|||||||
wxLog *pLogger = GetActiveTarget();
|
wxLog *pLogger = GetActiveTarget();
|
||||||
if ( pLogger )
|
if ( pLogger )
|
||||||
{
|
{
|
||||||
if ( GetRepetitionCounting() && ms_prevString == szString )
|
if ( GetRepetitionCounting() )
|
||||||
{
|
{
|
||||||
ms_prevCounter++;
|
if ( szString == ms_prevString )
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
if ( GetRepetitionCounting() )
|
|
||||||
{
|
{
|
||||||
DoLogNumberOfRepeats();
|
ms_prevCounter++;
|
||||||
|
|
||||||
|
// nothing else to do, in particular, don't log the
|
||||||
|
// repeated message
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
LogLastRepetitionCountIfNeeded();
|
||||||
|
|
||||||
|
// reset repetition counter for a new message
|
||||||
ms_prevString = szString;
|
ms_prevString = szString;
|
||||||
ms_prevLevel = level;
|
ms_prevLevel = level;
|
||||||
ms_prevTimeStamp = t;
|
ms_prevTimeStamp = t;
|
||||||
pLogger->DoLog(level, szString, t);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pLogger->DoLog(level, szString, t);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user