]> git.saurik.com Git - wxWidgets.git/blobdiff - src/common/log.cpp
Don't emit bogus size events if a child window
[wxWidgets.git] / src / common / log.cpp
index c17db339d96abb3ff26f934f80225debb0ab3b4a..275ed6dcd9f831b3665ed09da51a792289d032f1 100644 (file)
@@ -166,6 +166,7 @@ void wxSafeShowMessage(const wxString& title, const wxString& text)
     ::MessageBox(NULL, text, title, MB_OK | MB_ICONSTOP);
 #else
     wxFprintf(stderr, _T("%s: %s\n"), title.c_str(), text.c_str());
+    fflush(stderr);
 #endif
 }
 
@@ -356,6 +357,66 @@ void WXDLLEXPORT wxLogSysError(long lErrCode, const wxChar *szFormat, ...)
 // wxLog class implementation
 // ----------------------------------------------------------------------------
 
+/* static */
+unsigned wxLog::DoLogNumberOfRepeats()
+{
+    long retval = ms_prevCounter;
+    wxLog *pLogger = GetActiveTarget();
+    if ( pLogger && ms_prevCounter > 0 )
+    {
+        wxString msg;
+#if wxUSE_INTL
+        msg.Printf(wxPLURAL("The previous message repeated once.",
+                            "The previous message repeated %lu times.",
+                            ms_prevCounter),
+                   ms_prevCounter);
+#else
+        msg.Printf(wxT("The previous message was repeated."));
+#endif
+        ms_prevCounter = 0;
+        ms_prevString.clear();
+        pLogger->DoLog(ms_prevLevel, msg.c_str(), ms_prevTimeStamp);
+    }
+    return retval;
+}
+
+wxLog::~wxLog()
+{
+    if ( ms_prevCounter > 0 )
+    {
+        // looks like the repeat count has not been logged yet,
+        // so let's do it now
+        wxLog::DoLogNumberOfRepeats();
+    }
+}
+
+/* static */
+void wxLog::OnLog(wxLogLevel level, const wxChar *szString, time_t t)
+{
+    if ( IsEnabled() && ms_logLevel >= level )
+    {
+        wxLog *pLogger = GetActiveTarget();
+        if ( pLogger )
+        {
+            if ( GetRepetitionCounting() && ms_prevString == szString )
+            {
+                ms_prevCounter++;
+            }
+            else
+            {
+                if ( GetRepetitionCounting() )
+                {
+                    pLogger->DoLogNumberOfRepeats();
+                }
+                ms_prevString = szString;
+                ms_prevLevel = level;
+                ms_prevTimeStamp = t;
+                pLogger->DoLog(level, szString, t);
+            }
+        }
+    }
+}
+
 wxChar *wxLog::SetLogBuffer( wxChar *buf, size_t size)
 {
     wxChar *oldbuf = s_szBuf;
@@ -695,6 +756,12 @@ wxLogPassThrough::wxLogPassThrough()
 // static variables
 // ----------------------------------------------------------------------------
 
+bool            wxLog::ms_bRepetCounting = false;
+wxString        wxLog::ms_prevString;
+unsigned int    wxLog::ms_prevCounter = 0;
+time_t          wxLog::ms_prevTimeStamp= 0;
+wxLogLevel      wxLog::ms_prevLevel;
+
 wxLog          *wxLog::ms_pLogger      = (wxLog *)NULL;
 bool            wxLog::ms_doLog        = true;
 bool            wxLog::ms_bAutoCreate  = true;