X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/dbaa16de075ca1f81ee663f11a67cecf4c0eb7bd..02f07b1980c4b5dc289340de3835f90662c759a3:/src/common/log.cpp?ds=inline diff --git a/src/common/log.cpp b/src/common/log.cpp index 250b7b3924..9f4134f41b 100644 --- a/src/common/log.cpp +++ b/src/common/log.cpp @@ -51,16 +51,42 @@ #include +#ifndef __WXPALMOS5__ #ifndef __WXWINCE__ #include #else #include "wx/msw/wince/time.h" #endif +#endif /* ! __WXPALMOS5__ */ #if defined(__WINDOWS__) #include "wx/msw/private.h" // includes windows.h #endif +#if wxUSE_THREADS + +// define static functions providing access to the critical sections we use +// instead of just using static critical section variables as log functions may +// be used during static initialization and while this is certainly not +// advisable it's still better to not crash (as we'd do if we used a yet +// uninitialized critical section) if it happens + +static inline wxCriticalSection& GetTraceMaskCS() +{ + static wxCriticalSection s_csTrace; + + return s_csTrace; +} + +static inline wxCriticalSection& GetPreviousLogCS() +{ + static wxCriticalSection s_csPrev; + + return s_csPrev; +} + +#endif // wxUSE_THREADS + // ---------------------------------------------------------------------------- // non member functions // ---------------------------------------------------------------------------- @@ -157,7 +183,7 @@ IMPLEMENT_LOG_FUNCTION(Status) void wxSafeShowMessage(const wxString& title, const wxString& text) { #ifdef __WINDOWS__ - ::MessageBox(NULL, text.wx_str(), title.wx_str(), MB_OK | MB_ICONSTOP); + ::MessageBox(NULL, text.t_str(), title.t_str(), MB_OK | MB_ICONSTOP); #else wxFprintf(stderr, wxS("%s: %s\n"), title.c_str(), text.c_str()); fflush(stderr); @@ -459,7 +485,7 @@ void WXDLLIMPEXP_BASE wxVLogSysError(unsigned long err, const wxString& format, unsigned wxLog::LogLastRepeatIfNeeded() { - wxCRIT_SECT_LOCKER(lock, ms_prevCS); + wxCRIT_SECT_LOCKER(lock, GetPreviousLogCS()); return LogLastRepeatIfNeededUnlocked(); } @@ -490,7 +516,17 @@ unsigned wxLog::LogLastRepeatIfNeededUnlocked() wxLog::~wxLog() { - LogLastRepeatIfNeeded(); + // Flush() must be called before destroying the object as otherwise some + // messages could be lost + if ( ms_prevCounter ) + { + wxMessageOutputDebug().Printf + ( + wxS("Last repeated message (\"%s\", %lu times) wasn't output"), + ms_prevString, + ms_prevCounter + ); + } } /* static */ @@ -503,7 +539,7 @@ void wxLog::OnLog(wxLogLevel level, const wxString& szString, time_t t) { if ( GetRepetitionCounting() ) { - wxCRIT_SECT_LOCKER(lock, ms_prevCS); + wxCRIT_SECT_LOCKER(lock, GetPreviousLogCS()); if ( szString == ms_prevString ) { @@ -606,8 +642,17 @@ void wxLog::DoCreateOnDemand() ms_bAutoCreate = true; } +void wxLog::AddTraceMask(const wxString& str) +{ + wxCRIT_SECT_LOCKER(lock, GetTraceMaskCS()); + + ms_aTraceMasks.push_back(str); +} + void wxLog::RemoveTraceMask(const wxString& str) { + wxCRIT_SECT_LOCKER(lock, GetTraceMaskCS()); + int index = ms_aTraceMasks.Index(str); if ( index != wxNOT_FOUND ) ms_aTraceMasks.RemoveAt((size_t)index); @@ -615,6 +660,8 @@ void wxLog::RemoveTraceMask(const wxString& str) void wxLog::ClearTraceMasks() { + wxCRIT_SECT_LOCKER(lock, GetTraceMaskCS()); + ms_aTraceMasks.Clear(); } @@ -705,16 +752,21 @@ void wxLog::DoLogString(const wxString& szString, time_t t) void wxLog::Flush() { - // nothing to do here + LogLastRepeatIfNeeded(); } /*static*/ bool wxLog::IsAllowedTraceMask(const wxString& mask) { + wxCRIT_SECT_LOCKER(lock, GetTraceMaskCS()); + for ( wxArrayString::iterator it = ms_aTraceMasks.begin(), en = ms_aTraceMasks.end(); it != en; ++it ) + { if ( *it == mask) return true; + } + return false; } @@ -896,7 +948,7 @@ wxLogInterposer::wxLogInterposer() wxLogInterposerTemp::wxLogInterposerTemp() : wxLogChain(this) { - DetachOldLog(); + DetachOldLog(); } #ifdef __VISUALC__ @@ -911,16 +963,13 @@ wxLogInterposerTemp::wxLogInterposerTemp() // static variables // ---------------------------------------------------------------------------- -#if wxUSE_THREADS -wxCriticalSection wxLog::ms_prevCS; -#endif // wxUSE_THREADS 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; +wxLog *wxLog::ms_pLogger = NULL; bool wxLog::ms_doLog = true; bool wxLog::ms_bAutoCreate = true; bool wxLog::ms_bVerbose = false; @@ -1019,8 +1068,7 @@ const wxChar *wxSysErrorMsg(unsigned long nErrCode) #if !defined(__SMARTPHONE__) /* of WinCE */ if( lpMsgBuf != 0 ) { - wxStrncpy(s_szBuf, (const wxChar *)lpMsgBuf, WXSIZEOF(s_szBuf) - 1); - s_szBuf[WXSIZEOF(s_szBuf) - 1] = wxS('\0'); + wxStrlcpy(s_szBuf, (const wxChar *)lpMsgBuf, WXSIZEOF(s_szBuf)); LocalFree(lpMsgBuf);