1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: Assorted wxLogXXX functions, and wxLog (sink for logs)
4 // Author: Vadim Zeitlin
8 // Copyright: (c) 1998 Vadim Zeitlin <zeitlin@dptmaths.ens-cachan.fr>
9 // Licence: wxWindows license
10 /////////////////////////////////////////////////////////////////////////////
12 // ============================================================================
14 // ============================================================================
16 // ----------------------------------------------------------------------------
18 // ----------------------------------------------------------------------------
20 #pragma implementation "log.h"
23 // For compilers that support precompilation, includes "wx.h".
24 #include "wx/wxprec.h"
32 #include "wx/window.h"
34 #include "wx/msw/private.h"
38 #include "wx/string.h"
42 #include "wx/msgdlg.h"
43 #include "wx/filedlg.h"
44 #include "wx/textctrl.h"
48 #include "wx/textfile.h"
50 #include "wx/wxchar.h"
53 // other standard headers
60 // Redefines OutputDebugString if necessary
61 #include "wx/msw/private.h"
66 // ----------------------------------------------------------------------------
67 // non member functions
68 // ----------------------------------------------------------------------------
70 // define this to enable wrapping of log messages
71 //#define LOG_PRETTY_WRAP
73 #ifdef LOG_PRETTY_WRAP
74 static void wxLogWrap(FILE *f
, const char *pszPrefix
, const char *psz
);
77 // ----------------------------------------------------------------------------
79 // ----------------------------------------------------------------------------
81 // we use a global variable to store the frame pointer for wxLogStatus - bad,
82 // but it's he easiest way
83 static wxFrame
*gs_pFrame
; // FIXME MT-unsafe
85 // ============================================================================
87 // ============================================================================
89 // ----------------------------------------------------------------------------
90 // implementation of Log functions
92 // NB: unfortunately we need all these distinct functions, we can't make them
93 // macros and not all compilers inline vararg functions.
94 // ----------------------------------------------------------------------------
96 // log functions can't allocate memory (LogError("out of memory...") should
97 // work!), so we use a static buffer for all log messages
98 #define LOG_BUFFER_SIZE (4096)
100 // static buffer for error messages (FIXME MT-unsafe)
101 static wxChar s_szBuf
[LOG_BUFFER_SIZE
];
103 // generic log function
104 void wxLogGeneric(wxLogLevel level
, const wxChar
*szFormat
, ...)
106 if ( wxLog::GetActiveTarget() != NULL
) {
108 va_start(argptr
, szFormat
);
109 wxVsprintf(s_szBuf
, szFormat
, argptr
);
112 wxLog::OnLog(level
, s_szBuf
, time(NULL
));
116 #define IMPLEMENT_LOG_FUNCTION(level) \
117 void wxLog##level(const wxChar *szFormat, ...) \
119 if ( wxLog::GetActiveTarget() != NULL ) { \
121 va_start(argptr, szFormat); \
122 wxVsprintf(s_szBuf, szFormat, argptr); \
125 wxLog::OnLog(wxLOG_##level, s_szBuf, time(NULL)); \
129 IMPLEMENT_LOG_FUNCTION(FatalError
)
130 IMPLEMENT_LOG_FUNCTION(Error
)
131 IMPLEMENT_LOG_FUNCTION(Warning
)
132 IMPLEMENT_LOG_FUNCTION(Message
)
133 IMPLEMENT_LOG_FUNCTION(Info
)
134 IMPLEMENT_LOG_FUNCTION(Status
)
136 // accepts an additional argument which tells to which frame the output should
138 void wxLogStatus(wxFrame
*pFrame
, const wxChar
*szFormat
, ...)
140 wxLog
*pLog
= wxLog::GetActiveTarget();
141 if ( pLog
!= NULL
) {
143 va_start(argptr
, szFormat
);
144 wxVsprintf(s_szBuf
, szFormat
, argptr
);
147 wxASSERT( gs_pFrame
== NULL
); // should be reset!
149 wxLog::OnLog(wxLOG_Status
, s_szBuf
, time(NULL
));
150 gs_pFrame
= (wxFrame
*) NULL
;
154 // same as info, but only if 'verbose' mode is on
155 void wxLogVerbose(const wxChar
*szFormat
, ...)
157 wxLog
*pLog
= wxLog::GetActiveTarget();
158 if ( pLog
!= NULL
&& pLog
->GetVerbose() ) {
160 va_start(argptr
, szFormat
);
161 wxVsprintf(s_szBuf
, szFormat
, argptr
);
164 wxLog::OnLog(wxLOG_Info
, s_szBuf
, time(NULL
));
170 #define IMPLEMENT_LOG_DEBUG_FUNCTION(level) \
171 void wxLog##level(const wxChar *szFormat, ...) \
173 if ( wxLog::GetActiveTarget() != NULL ) { \
175 va_start(argptr, szFormat); \
176 wxVsprintf(s_szBuf, szFormat, argptr); \
179 wxLog::OnLog(wxLOG_##level, s_szBuf, time(NULL)); \
183 void wxLogTrace(const wxChar
*mask
, const wxChar
*szFormat
, ...)
185 wxLog
*pLog
= wxLog::GetActiveTarget();
187 if ( pLog
!= NULL
&& wxLog::IsAllowedTraceMask(mask
) ) {
189 va_start(argptr
, szFormat
);
190 wxVsprintf(s_szBuf
, szFormat
, argptr
);
193 wxLog::OnLog(wxLOG_Trace
, s_szBuf
, time(NULL
));
197 void wxLogTrace(wxTraceMask mask
, const wxChar
*szFormat
, ...)
199 wxLog
*pLog
= wxLog::GetActiveTarget();
201 // we check that all of mask bits are set in the current mask, so
202 // that wxLogTrace(wxTraceRefCount | wxTraceOle) will only do something
203 // if both bits are set.
204 if ( pLog
!= NULL
&& ((pLog
->GetTraceMask() & mask
) == mask
) ) {
206 va_start(argptr
, szFormat
);
207 wxVsprintf(s_szBuf
, szFormat
, argptr
);
210 wxLog::OnLog(wxLOG_Trace
, s_szBuf
, time(NULL
));
215 #define IMPLEMENT_LOG_DEBUG_FUNCTION(level)
218 IMPLEMENT_LOG_DEBUG_FUNCTION(Debug
)
219 IMPLEMENT_LOG_DEBUG_FUNCTION(Trace
)
221 // wxLogSysError: one uses the last error code, for other you must give it
224 // common part of both wxLogSysError
225 void wxLogSysErrorHelper(long lErrCode
)
227 wxChar szErrMsg
[LOG_BUFFER_SIZE
/ 2];
228 wxSprintf(szErrMsg
, _(" (error %ld: %s)"), lErrCode
, wxSysErrorMsg(lErrCode
));
229 wxStrncat(s_szBuf
, szErrMsg
, WXSIZEOF(s_szBuf
) - wxStrlen(s_szBuf
));
231 wxLog::OnLog(wxLOG_Error
, s_szBuf
, time(NULL
));
234 void WXDLLEXPORT
wxLogSysError(const wxChar
*szFormat
, ...)
237 va_start(argptr
, szFormat
);
238 wxVsprintf(s_szBuf
, szFormat
, argptr
);
241 wxLogSysErrorHelper(wxSysErrorCode());
244 void WXDLLEXPORT
wxLogSysError(long lErrCode
, const wxChar
*szFormat
, ...)
247 va_start(argptr
, szFormat
);
248 wxVsprintf(s_szBuf
, szFormat
, argptr
);
251 wxLogSysErrorHelper(lErrCode
);
254 // ----------------------------------------------------------------------------
255 // wxLog class implementation
256 // ----------------------------------------------------------------------------
260 m_bHasMessages
= FALSE
;
262 // enable verbose messages by default in the debug builds
267 #endif // debug/release
270 wxLog
*wxLog::GetActiveTarget()
272 if ( ms_bAutoCreate
&& ms_pLogger
== NULL
) {
273 // prevent infinite recursion if someone calls wxLogXXX() from
274 // wxApp::CreateLogTarget()
275 static bool s_bInGetActiveTarget
= FALSE
;
276 if ( !s_bInGetActiveTarget
) {
277 s_bInGetActiveTarget
= TRUE
;
280 ms_pLogger
= new wxLogStderr
;
282 // ask the application to create a log target for us
283 if ( wxTheApp
!= NULL
)
284 ms_pLogger
= wxTheApp
->CreateLogTarget();
286 ms_pLogger
= new wxLogStderr
;
289 s_bInGetActiveTarget
= FALSE
;
291 // do nothing if it fails - what can we do?
298 wxLog
*wxLog::SetActiveTarget(wxLog
*pLogger
)
300 if ( ms_pLogger
!= NULL
) {
301 // flush the old messages before changing because otherwise they might
302 // get lost later if this target is not restored
306 wxLog
*pOldLogger
= ms_pLogger
;
307 ms_pLogger
= pLogger
;
312 void wxLog::RemoveTraceMask(const wxString
& str
)
314 int index
= ms_aTraceMasks
.Index(str
);
315 if ( index
!= wxNOT_FOUND
)
316 ms_aTraceMasks
.Remove((size_t)index
);
319 void wxLog::TimeStamp(wxString
*str
)
325 (void)time(&timeNow
);
326 wxStrftime(buf
, WXSIZEOF(buf
), ms_timestamp
, localtime(&timeNow
));
329 *str
<< buf
<< _T(": ");
333 void wxLog::DoLog(wxLogLevel level
, const wxChar
*szString
, time_t t
)
336 case wxLOG_FatalError
:
337 DoLogString(wxString(_("Fatal error: ")) + szString
, t
);
338 DoLogString(_("Program aborted."), t
);
344 DoLogString(wxString(_("Error: ")) + szString
, t
);
348 DoLogString(wxString(_("Warning: ")) + szString
, t
);
354 default: // log unknown log levels too
355 DoLogString(szString
, t
);
365 DoLogString(szString
, t
);
371 void wxLog::DoLogString(const wxChar
*WXUNUSED(szString
), time_t WXUNUSED(t
))
373 wxFAIL_MSG(_T("DoLogString must be overriden if it's called."));
381 // ----------------------------------------------------------------------------
382 // wxLogStderr class implementation
383 // ----------------------------------------------------------------------------
385 wxLogStderr::wxLogStderr(FILE *fp
)
393 void wxLogStderr::DoLogString(const wxChar
*szString
, time_t WXUNUSED(t
))
397 str
<< szString
<< _T('\n');
399 fputs(str
.mb_str(), m_fp
);
402 // under Windows, programs usually don't have stderr at all, so make show the
403 // messages also under debugger
405 OutputDebugString(str
+ _T('\r'));
409 // ----------------------------------------------------------------------------
410 // wxLogStream implementation
411 // ----------------------------------------------------------------------------
413 #if wxUSE_STD_IOSTREAM
414 wxLogStream::wxLogStream(ostream
*ostr
)
422 void wxLogStream::DoLogString(const wxChar
*szString
, time_t WXUNUSED(t
))
424 (*m_ostr
) << wxConvCurrent
->cWX2MB(szString
) << endl
<< flush
;
426 #endif // wxUSE_STD_IOSTREAM
430 // ----------------------------------------------------------------------------
431 // wxLogTextCtrl implementation
432 // ----------------------------------------------------------------------------
434 wxLogTextCtrl::wxLogTextCtrl(wxTextCtrl
*pTextCtrl
)
436 m_pTextCtrl
= pTextCtrl
;
439 void wxLogTextCtrl::DoLogString(const wxChar
*szString
, time_t t
)
443 msg
<< szString
<< _T('\n');
445 m_pTextCtrl
->AppendText(msg
);
448 // ----------------------------------------------------------------------------
449 // wxLogGui implementation (FIXME MT-unsafe)
450 // ----------------------------------------------------------------------------
457 void wxLogGui::Clear()
459 m_bErrors
= m_bWarnings
= FALSE
;
464 void wxLogGui::Flush()
466 if ( !m_bHasMessages
)
469 // do it right now to block any new calls to Flush() while we're here
470 m_bHasMessages
= FALSE
;
472 // concatenate all strings (but not too many to not overfill the msg box)
475 nMsgCount
= m_aMessages
.Count();
477 // start from the most recent message
478 for ( size_t n
= nMsgCount
; n
> 0; n
-- ) {
479 // for Windows strings longer than this value are wrapped (NT 4.0)
480 const size_t nMsgLineWidth
= 156;
482 nLines
+= (m_aMessages
[n
- 1].Len() + nMsgLineWidth
- 1) / nMsgLineWidth
;
484 if ( nLines
> 25 ) // don't put too many lines in message box
487 str
<< m_aMessages
[n
- 1] << _T("\n");
497 else if ( m_bWarnings
) {
498 title
= _("Warning");
499 style
= wxICON_EXCLAMATION
;
502 title
= _("Information");
503 style
= wxICON_INFORMATION
;
506 wxMessageBox(str
, title
, wxOK
| style
);
508 // no undisplayed messages whatsoever
512 m_bHasMessages
= FALSE
;
515 // the default behaviour is to discard all informational messages if there
516 // are any errors/warnings.
517 void wxLogGui::DoLog(wxLogLevel level
, const wxChar
*szString
, time_t t
)
524 m_aMessages
.Add(szString
);
525 m_aTimes
.Add((long)t
);
526 m_bHasMessages
= TRUE
;
533 // find the top window and set it's status text if it has any
534 wxFrame
*pFrame
= gs_pFrame
;
535 if ( pFrame
== NULL
) {
536 wxWindow
*pWin
= wxTheApp
->GetTopWindow();
537 if ( pWin
!= NULL
&& pWin
->IsKindOf(CLASSINFO(wxFrame
)) ) {
538 pFrame
= (wxFrame
*)pWin
;
542 if ( pFrame
!= NULL
)
543 pFrame
->SetStatusText(szString
);
545 #endif // wxUSE_STATUSBAR
553 // don't prepend debug/trace here: it goes to the
554 // debug window anyhow, but do put a timestamp
557 str
<< szString
<< _T("\n\r");
558 OutputDebugString(str
);
560 // send them to stderr
561 wxFprintf(stderr
, _T("%s: %s\n"),
562 level
== wxLOG_Trace
? _T("Trace")
568 #endif // __WXDEBUG__
572 case wxLOG_FatalError
:
573 // show this one immediately
574 wxMessageBox(szString
, _("Fatal error"), wxICON_HAND
);
578 // discard earlier informational messages if this is the 1st
579 // error because they might not make sense any more
589 // for the warning we don't discard the info messages
593 m_aMessages
.Add(szString
);
594 m_aTimes
.Add((long)t
);
595 m_bHasMessages
= TRUE
;
600 // ----------------------------------------------------------------------------
601 // wxLogWindow and wxLogFrame implementation
602 // ----------------------------------------------------------------------------
606 class wxLogFrame
: public wxFrame
610 wxLogFrame(wxFrame
*pParent
, wxLogWindow
*log
, const wxChar
*szTitle
);
611 virtual ~wxLogFrame();
614 void OnClose(wxCommandEvent
& event
);
615 void OnCloseWindow(wxCloseEvent
& event
);
617 void OnSave (wxCommandEvent
& event
);
619 void OnClear(wxCommandEvent
& event
);
621 void OnIdle(wxIdleEvent
&);
624 wxTextCtrl
*TextCtrl() const { return m_pTextCtrl
; }
634 // instead of closing just hide the window to be able to Show() it later
635 void DoClose() { Show(FALSE
); }
637 wxTextCtrl
*m_pTextCtrl
;
640 DECLARE_EVENT_TABLE()
643 BEGIN_EVENT_TABLE(wxLogFrame
, wxFrame
)
644 // wxLogWindow menu events
645 EVT_MENU(Menu_Close
, wxLogFrame::OnClose
)
647 EVT_MENU(Menu_Save
, wxLogFrame::OnSave
)
649 EVT_MENU(Menu_Clear
, wxLogFrame::OnClear
)
651 EVT_CLOSE(wxLogFrame::OnCloseWindow
)
654 wxLogFrame::wxLogFrame(wxFrame
*pParent
, wxLogWindow
*log
, const wxChar
*szTitle
)
655 : wxFrame(pParent
, -1, szTitle
)
659 m_pTextCtrl
= new wxTextCtrl(this, -1, wxEmptyString
, wxDefaultPosition
,
666 wxMenuBar
*pMenuBar
= new wxMenuBar
;
667 wxMenu
*pMenu
= new wxMenu
;
669 pMenu
->Append(Menu_Save
, _("&Save..."), _("Save log contents to file"));
671 pMenu
->Append(Menu_Clear
, _("C&lear"), _("Clear the log contents"));
672 pMenu
->AppendSeparator();
673 pMenu
->Append(Menu_Close
, _("&Close"), _("Close this window"));
674 pMenuBar
->Append(pMenu
, _("&Log"));
675 SetMenuBar(pMenuBar
);
678 // status bar for menu prompts
680 #endif // wxUSE_STATUSBAR
682 m_log
->OnFrameCreate(this);
685 void wxLogFrame::OnClose(wxCommandEvent
& WXUNUSED(event
))
690 void wxLogFrame::OnCloseWindow(wxCloseEvent
& WXUNUSED(event
))
696 void wxLogFrame::OnSave(wxCommandEvent
& WXUNUSED(event
))
700 const wxChar
*szFileName
= wxSaveFileSelector(_T("log"), _T("txt"), _T("log.txt"));
701 if ( szFileName
== NULL
) {
710 if ( wxFile::Exists(szFileName
) ) {
711 bool bAppend
= FALSE
;
713 strMsg
.Printf(_("Append log to file '%s' "
714 "(choosing [No] will overwrite it)?"), szFileName
);
715 switch ( wxMessageBox(strMsg
, _("Question"), wxYES_NO
| wxCANCEL
) ) {
728 wxFAIL_MSG(_("invalid message box return value"));
732 bOk
= file
.Open(szFileName
, wxFile::write_append
);
735 bOk
= file
.Create(szFileName
, TRUE
/* overwrite */);
739 bOk
= file
.Create(szFileName
);
742 // retrieve text and save it
743 // -------------------------
744 int nLines
= m_pTextCtrl
->GetNumberOfLines();
745 for ( int nLine
= 0; bOk
&& nLine
< nLines
; nLine
++ ) {
746 bOk
= file
.Write(m_pTextCtrl
->GetLineText(nLine
) +
747 // we're not going to pull in the whole wxTextFile if all we need is this...
750 #else // !wxUSE_TEXTFILE
752 #endif // wxUSE_TEXTFILE
760 wxLogError(_("Can't save log contents to file."));
763 wxLogStatus(this, _("Log saved to the file '%s'."), szFileName
);
768 void wxLogFrame::OnClear(wxCommandEvent
& WXUNUSED(event
))
770 m_pTextCtrl
->Clear();
773 wxLogFrame::~wxLogFrame()
775 m_log
->OnFrameDelete(this);
780 wxLogWindow::wxLogWindow(wxFrame
*pParent
,
781 const wxChar
*szTitle
,
785 m_bPassMessages
= bDoPass
;
787 m_pLogFrame
= new wxLogFrame(pParent
, this, szTitle
);
788 m_pOldLog
= wxLog::SetActiveTarget(this);
791 m_pLogFrame
->Show(TRUE
);
794 void wxLogWindow::Show(bool bShow
)
796 m_pLogFrame
->Show(bShow
);
799 void wxLogWindow::Flush()
801 if ( m_pOldLog
!= NULL
)
804 m_bHasMessages
= FALSE
;
807 void wxLogWindow::DoLog(wxLogLevel level
, const wxChar
*szString
, time_t t
)
809 // first let the previous logger show it
810 if ( m_pOldLog
!= NULL
&& m_bPassMessages
) {
811 // FIXME why can't we access protected wxLog method from here (we derive
812 // from wxLog)? gcc gives "DoLog is protected in this context", what
813 // does this mean? Anyhow, the cast is harmless and let's us do what
815 ((wxLogWindow
*)m_pOldLog
)->DoLog(level
, szString
, t
);
821 // by default, these messages are ignored by wxLog, so process
823 if ( !wxIsEmpty(szString
) )
826 str
<< _("Status: ") << szString
;
831 // don't put trace messages in the text window for 2 reasons:
832 // 1) there are too many of them
833 // 2) they may provoke other trace messages thus sending a program
834 // into an infinite loop
839 // and this will format it nicely and call our DoLogString()
840 wxLog::DoLog(level
, szString
, t
);
844 m_bHasMessages
= TRUE
;
847 void wxLogWindow::DoLogString(const wxChar
*szString
, time_t WXUNUSED(t
))
849 // put the text into our window
850 wxTextCtrl
*pText
= m_pLogFrame
->TextCtrl();
852 // remove selection (WriteText is in fact ReplaceSelection)
854 long nLen
= pText
->GetLastPosition();
855 pText
->SetSelection(nLen
, nLen
);
860 msg
<< szString
<< _T('\n');
862 pText
->AppendText(msg
);
864 // TODO ensure that the line can be seen
867 wxFrame
*wxLogWindow::GetFrame() const
872 void wxLogWindow::OnFrameCreate(wxFrame
* WXUNUSED(frame
))
876 void wxLogWindow::OnFrameDelete(wxFrame
* WXUNUSED(frame
))
878 m_pLogFrame
= (wxLogFrame
*)NULL
;
881 wxLogWindow::~wxLogWindow()
885 // may be NULL if log frame already auto destroyed itself
891 // ============================================================================
892 // Global functions/variables
893 // ============================================================================
895 // ----------------------------------------------------------------------------
897 // ----------------------------------------------------------------------------
899 wxLog
*wxLog::ms_pLogger
= (wxLog
*)NULL
;
900 bool wxLog::ms_doLog
= TRUE
;
901 bool wxLog::ms_bAutoCreate
= TRUE
;
903 const wxChar
*wxLog::ms_timestamp
= _T("%X"); // time only, no date
905 wxTraceMask
wxLog::ms_ulTraceMask
= (wxTraceMask
)0;
906 wxArrayString
wxLog::ms_aTraceMasks
;
908 // ----------------------------------------------------------------------------
909 // stdout error logging helper
910 // ----------------------------------------------------------------------------
912 // helper function: wraps the message and justifies it under given position
913 // (looks more pretty on the terminal). Also adds newline at the end.
915 // TODO this is now disabled until I find a portable way of determining the
916 // terminal window size (ok, I found it but does anybody really cares?)
917 #ifdef LOG_PRETTY_WRAP
918 static void wxLogWrap(FILE *f
, const char *pszPrefix
, const char *psz
)
920 size_t nMax
= 80; // FIXME
921 size_t nStart
= strlen(pszPrefix
);
925 while ( *psz
!= '\0' ) {
926 for ( n
= nStart
; (n
< nMax
) && (*psz
!= '\0'); n
++ )
930 if ( *psz
!= '\0' ) {
932 for ( n
= 0; n
< nStart
; n
++ )
935 // as we wrapped, squeeze all white space
936 while ( isspace(*psz
) )
943 #endif //LOG_PRETTY_WRAP
945 // ----------------------------------------------------------------------------
946 // error code/error message retrieval functions
947 // ----------------------------------------------------------------------------
949 // get error code from syste
950 unsigned long wxSysErrorCode()
954 return ::GetLastError();
956 // TODO what to do on Windows 3.1?
964 // get error message from system
965 const wxChar
*wxSysErrorMsg(unsigned long nErrCode
)
968 nErrCode
= wxSysErrorCode();
972 static wxChar s_szBuf
[LOG_BUFFER_SIZE
/ 2];
974 // get error message from system
976 FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER
| FORMAT_MESSAGE_FROM_SYSTEM
,
978 MAKELANGID(LANG_NEUTRAL
, SUBLANG_DEFAULT
),
982 // copy it to our buffer and free memory
983 wxStrncpy(s_szBuf
, (const wxChar
*)lpMsgBuf
, WXSIZEOF(s_szBuf
) - 1);
984 s_szBuf
[WXSIZEOF(s_szBuf
) - 1] = _T('\0');
987 // returned string is capitalized and ended with '\r\n' - bad
988 s_szBuf
[0] = (wxChar
)wxTolower(s_szBuf
[0]);
989 size_t len
= wxStrlen(s_szBuf
);
992 if ( s_szBuf
[len
- 2] == _T('\r') )
993 s_szBuf
[len
- 2] = _T('\0');
1003 static wxChar s_szBuf
[LOG_BUFFER_SIZE
/ 2];
1004 wxConvCurrent
->MB2WC(s_szBuf
, strerror(nErrCode
), WXSIZEOF(s_szBuf
) -1);
1007 return strerror(nErrCode
);
1012 // ----------------------------------------------------------------------------
1014 // ----------------------------------------------------------------------------
1018 // break into the debugger
1023 #elif defined(__WXMAC__)
1029 #elif defined(__UNIX__)
1036 // this function is called when an assert fails
1037 void wxOnAssert(const wxChar
*szFile
, int nLine
, const wxChar
*szMsg
)
1039 // this variable can be set to true to suppress "assert failure" messages
1040 static bool s_bNoAsserts
= FALSE
;
1041 static bool s_bInAssert
= FALSE
; // FIXME MT-unsafe
1043 if ( s_bInAssert
) {
1044 // He-e-e-e-elp!! we're trapped in endless loop
1047 s_bInAssert
= FALSE
;
1054 wxChar szBuf
[LOG_BUFFER_SIZE
];
1056 // make life easier for people using VC++ IDE: clicking on the message
1057 // will take us immediately to the place of the failed assert
1059 wxSprintf(szBuf
, _T("%s(%d): assert failed"), szFile
, nLine
);
1061 // make the error message more clear for all the others
1062 wxSprintf(szBuf
, _T("Assert failed in file %s at line %d"), szFile
, nLine
);
1065 if ( szMsg
!= NULL
) {
1066 wxStrcat(szBuf
, _T(": "));
1067 wxStrcat(szBuf
, szMsg
);
1070 wxStrcat(szBuf
, _T("."));
1073 if ( !s_bNoAsserts
) {
1074 // send it to the normal log destination
1080 // this message is intentionally not translated - it is for
1082 wxStrcat(szBuf
, _T("\nDo you want to stop the program?"
1083 "\nYou can also choose [Cancel] to suppress "
1084 "further warnings."));
1086 switch ( wxMessageBox(szBuf
, _("Debug"),
1087 wxYES_NO
| wxCANCEL
| wxICON_STOP
) ) {
1093 s_bNoAsserts
= TRUE
;
1096 //case wxNO: nothing to do
1101 s_bInAssert
= FALSE
;