X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/91c536df157aa500e832ff9e8541839d2e07f6b4..f357c0d42c17bf5be30e65e68cd99c474678da71:/src/common/log.cpp diff --git a/src/common/log.cpp b/src/common/log.cpp index 510b939984..81ab68239b 100644 --- a/src/common/log.cpp +++ b/src/common/log.cpp @@ -159,17 +159,22 @@ IMPLEMENT_LOG_FUNCTION(Message) IMPLEMENT_LOG_FUNCTION(Info) IMPLEMENT_LOG_FUNCTION(Status) +void wxSafeShowMessage(const wxString& title, const wxString& text) +{ +#ifdef __WINDOWS__ + ::MessageBox(NULL, text, title, MB_OK | MB_ICONSTOP); +#else + wxFprintf(stderr, _T("%s: %s\n"), title.c_str(), text.c_str()); +#endif +} + // fatal errors can't be suppressed nor handled by the custom log target and // always terminate the program void wxVLogFatalError(const wxChar *szFormat, va_list argptr) { wxVsnprintf(s_szBuf, s_szBufSize, szFormat, argptr); -#if wxUSE_GUI - wxMessageBox(s_szBuf, _("Fatal Error"), wxID_OK | wxICON_STOP); -#else - wxFprintf(stderr, _("Fatal error: %s\n"), s_szBuf); -#endif + wxSafeShowMessage(_T("Fatal Error"), s_szBuf); abort(); } @@ -346,7 +351,6 @@ void WXDLLEXPORT wxLogSysError(long lErrCode, const wxChar *szFormat, ...) wxLog::wxLog() { - m_bHasMessages = FALSE; } wxChar *wxLog::SetLogBuffer( wxChar *buf, size_t size) @@ -488,8 +492,7 @@ void wxLog::DoLogString(const wxChar *WXUNUSED(szString), time_t WXUNUSED(t)) void wxLog::Flush() { - // remember that we don't have any more messages to show - m_bHasMessages = FALSE; + // nothing to do here } // ---------------------------------------------------------------------------- @@ -504,9 +507,8 @@ wxLogStderr::wxLogStderr(FILE *fp) m_fp = fp; } -#if defined(__WXMAC__) && !defined(__DARWIN__) && (__MWERKS__ > 0x5300) +#if defined(__WXMAC__) && !defined(__DARWIN__) && defined(__MWERKS__) && (__MWERKS__ >= 0x2400) -#if !TARGET_API_MAC_CARBON // MetroNub stuff doesn't seem to work in CodeWarrior 5.3 Carbon builds... #ifndef __MetroNubUtils__ @@ -689,9 +691,7 @@ OSErr ClearWatchPoint (WatchPointIDT watchPointID) } #endif -#endif // !TARGET_API_MAC_CARBON - -#endif // defined(__WXMAC__) && !defined(__DARWIN__) && (__MWERKS__ > 0x5300) +#endif // defined(__WXMAC__) && !defined(__DARWIN__) && (__MWERKS__ >= 0x2400) void wxLogStderr::DoLogString(const wxChar *szString, time_t WXUNUSED(t)) { @@ -704,11 +704,17 @@ void wxLogStderr::DoLogString(const wxChar *szString, time_t WXUNUSED(t)) fflush(m_fp); // under Windows, programs usually don't have stderr at all, so show the - // messages also under debugger - unless it's a console program + // messages also under debugger (unless it's a console program which does + // have stderr or unless this is a file logger which doesn't use stderr at + // all) #if defined(__WXMSW__) && wxUSE_GUI && !defined(__WXMICROWIN__) - str += wxT("\r\n") ; - OutputDebugString(str.c_str()); + if ( m_fp == stderr ) + { + str += wxT("\r\n") ; + OutputDebugString(str.c_str()); + } #endif // MSW + #if defined(__WXMAC__) && !defined(__DARWIN__) && wxUSE_GUI Str255 pstr ; strcpy( (char*) pstr , str.c_str() ) ; @@ -717,7 +723,7 @@ void wxLogStderr::DoLogString(const wxChar *szString, time_t WXUNUSED(t)) Boolean running = false ; -#if !TARGET_API_MAC_CARBON && (__MWERKS__ > 0x5300) +#if defined(__MWERKS__) && (__MWERKS__ >= 0x2400) if ( IsMWDebuggerRunning() && AmIBeingMWDebugged() ) { @@ -742,6 +748,7 @@ void wxLogStderr::DoLogString(const wxChar *szString, time_t WXUNUSED(t)) // ---------------------------------------------------------------------------- #if wxUSE_STD_IOSTREAM +#include "wx/ioswrap.h" wxLogStream::wxLogStream(wxSTD ostream *ostr) { if ( ostr == NULL ) @@ -764,16 +771,24 @@ void wxLogStream::DoLogString(const wxChar *szString, time_t WXUNUSED(t)) wxLogChain::wxLogChain(wxLog *logger) { + m_bPassMessages = TRUE; + m_logNew = logger; m_logOld = wxLog::SetActiveTarget(this); } -void wxLogChain::SetLog(wxLog *logger) +wxLogChain::~wxLogChain() { + delete m_logOld; + if ( m_logNew != this ) delete m_logNew; +} - wxLog::SetActiveTarget(logger); +void wxLogChain::SetLog(wxLog *logger) +{ + if ( m_logNew != this ) + delete m_logNew; m_logNew = logger; } @@ -783,7 +798,7 @@ void wxLogChain::Flush() if ( m_logOld ) m_logOld->Flush(); - // be careful to avoid inifinite recursion + // be careful to avoid infinite recursion if ( m_logNew && m_logNew != this ) m_logNew->Flush(); } @@ -835,6 +850,8 @@ bool wxLog::ms_doLog = TRUE; bool wxLog::ms_bAutoCreate = TRUE; bool wxLog::ms_bVerbose = FALSE; +wxLogLevel wxLog::ms_logLevel = wxLOG_Max; // log everything by default + size_t wxLog::ms_suspendCount = 0; #if wxUSE_GUI