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"
52 // other standard headers
59 // Redefines OutputDebugString if necessary
60 #include "wx/msw/private.h"
65 // ----------------------------------------------------------------------------
66 // non member functions
67 // ----------------------------------------------------------------------------
69 // define this to enable wrapping of log messages
70 //#define LOG_PRETTY_WRAP
72 #ifdef LOG_PRETTY_WRAP
73 static void wxLogWrap(FILE *f
, const char *pszPrefix
, const char *psz
);
76 // ----------------------------------------------------------------------------
78 // ----------------------------------------------------------------------------
80 // we use a global variable to store the frame pointer for wxLogStatus - bad,
81 // but it's he easiest way
82 static wxFrame
*gs_pFrame
; // FIXME MT-unsafe
84 // ============================================================================
86 // ============================================================================
88 // ----------------------------------------------------------------------------
89 // implementation of Log functions
91 // NB: unfortunately we need all these distinct functions, we can't make them
92 // macros and not all compilers inline vararg functions.
93 // ----------------------------------------------------------------------------
95 // log functions can't allocate memory (LogError("out of memory...") should
96 // work!), so we use a static buffer for all log messages
97 #define LOG_BUFFER_SIZE (4096)
99 // static buffer for error messages (FIXME MT-unsafe)
100 static wxChar s_szBuf
[LOG_BUFFER_SIZE
];
102 // generic log function
103 void wxLogGeneric(wxLogLevel level
, const wxChar
*szFormat
, ...)
105 if ( wxLog::GetActiveTarget() != NULL
) {
107 va_start(argptr
, szFormat
);
108 wxVsprintf(s_szBuf
, szFormat
, argptr
);
111 wxLog::OnLog(level
, s_szBuf
, time(NULL
));
115 #define IMPLEMENT_LOG_FUNCTION(level) \
116 void wxLog##level(const wxChar *szFormat, ...) \
118 if ( wxLog::GetActiveTarget() != NULL ) { \
120 va_start(argptr, szFormat); \
121 wxVsprintf(s_szBuf, szFormat, argptr); \
124 wxLog::OnLog(wxLOG_##level, s_szBuf, time(NULL)); \
128 IMPLEMENT_LOG_FUNCTION(FatalError
)
129 IMPLEMENT_LOG_FUNCTION(Error
)
130 IMPLEMENT_LOG_FUNCTION(Warning
)
131 IMPLEMENT_LOG_FUNCTION(Message
)
132 IMPLEMENT_LOG_FUNCTION(Info
)
133 IMPLEMENT_LOG_FUNCTION(Status
)
135 // accepts an additional argument which tells to which frame the output should
137 void wxLogStatus(wxFrame
*pFrame
, const wxChar
*szFormat
, ...)
139 wxLog
*pLog
= wxLog::GetActiveTarget();
140 if ( pLog
!= NULL
) {
142 va_start(argptr
, szFormat
);
143 wxVsprintf(s_szBuf
, szFormat
, argptr
);
146 wxASSERT( gs_pFrame
== NULL
); // should be reset!
148 wxLog::OnLog(wxLOG_Status
, s_szBuf
, time(NULL
));
149 gs_pFrame
= (wxFrame
*) NULL
;
153 // same as info, but only if 'verbose' mode is on
154 void wxLogVerbose(const wxChar
*szFormat
, ...)
156 wxLog
*pLog
= wxLog::GetActiveTarget();
157 if ( pLog
!= NULL
&& pLog
->GetVerbose() ) {
159 va_start(argptr
, szFormat
);
160 wxVsprintf(s_szBuf
, szFormat
, argptr
);
163 wxLog::OnLog(wxLOG_Info
, s_szBuf
, time(NULL
));
169 #define IMPLEMENT_LOG_DEBUG_FUNCTION(level) \
170 void wxLog##level(const wxChar *szFormat, ...) \
172 if ( wxLog::GetActiveTarget() != NULL ) { \
174 va_start(argptr, szFormat); \
175 wxVsprintf(s_szBuf, szFormat, argptr); \
178 wxLog::OnLog(wxLOG_##level, s_szBuf, time(NULL)); \
182 void wxLogTrace(const wxChar
*mask
, const wxChar
*szFormat
, ...)
184 wxLog
*pLog
= wxLog::GetActiveTarget();
186 if ( pLog
!= NULL
&& wxLog::IsAllowedTraceMask(mask
) ) {
188 va_start(argptr
, szFormat
);
189 wxVsprintf(s_szBuf
, szFormat
, argptr
);
192 wxLog::OnLog(wxLOG_Trace
, s_szBuf
, time(NULL
));
196 void wxLogTrace(wxTraceMask mask
, const wxChar
*szFormat
, ...)
198 wxLog
*pLog
= wxLog::GetActiveTarget();
200 // we check that all of mask bits are set in the current mask, so
201 // that wxLogTrace(wxTraceRefCount | wxTraceOle) will only do something
202 // if both bits are set.
203 if ( pLog
!= NULL
&& ((pLog
->GetTraceMask() & mask
) == mask
) ) {
205 va_start(argptr
, szFormat
);
206 wxVsprintf(s_szBuf
, szFormat
, argptr
);
209 wxLog::OnLog(wxLOG_Trace
, s_szBuf
, time(NULL
));
214 #define IMPLEMENT_LOG_DEBUG_FUNCTION(level)
217 IMPLEMENT_LOG_DEBUG_FUNCTION(Debug
)
218 IMPLEMENT_LOG_DEBUG_FUNCTION(Trace
)
220 // wxLogSysError: one uses the last error code, for other you must give it
223 // common part of both wxLogSysError
224 void wxLogSysErrorHelper(long lErrCode
)
226 wxChar szErrMsg
[LOG_BUFFER_SIZE
/ 2];
227 wxSprintf(szErrMsg
, _(" (error %ld: %s)"), lErrCode
, wxSysErrorMsg(lErrCode
));
228 wxStrncat(s_szBuf
, szErrMsg
, WXSIZEOF(s_szBuf
) - wxStrlen(s_szBuf
));
230 wxLog::OnLog(wxLOG_Error
, s_szBuf
, time(NULL
));
233 void WXDLLEXPORT
wxLogSysError(const wxChar
*szFormat
, ...)
236 va_start(argptr
, szFormat
);
237 wxVsprintf(s_szBuf
, szFormat
, argptr
);
240 wxLogSysErrorHelper(wxSysErrorCode());
243 void WXDLLEXPORT
wxLogSysError(long lErrCode
, const wxChar
*szFormat
, ...)
246 va_start(argptr
, szFormat
);
247 wxVsprintf(s_szBuf
, szFormat
, argptr
);
250 wxLogSysErrorHelper(lErrCode
);
253 // ----------------------------------------------------------------------------
254 // wxLog class implementation
255 // ----------------------------------------------------------------------------
259 m_bHasMessages
= FALSE
;
261 // enable verbose messages by default in the debug builds
266 #endif // debug/release
269 wxLog
*wxLog::GetActiveTarget()
271 if ( ms_bAutoCreate
&& ms_pLogger
== NULL
) {
272 // prevent infinite recursion if someone calls wxLogXXX() from
273 // wxApp::CreateLogTarget()
274 static bool s_bInGetActiveTarget
= FALSE
;
275 if ( !s_bInGetActiveTarget
) {
276 s_bInGetActiveTarget
= TRUE
;
279 ms_pLogger
= new wxLogStderr
;
281 // ask the application to create a log target for us
282 if ( wxTheApp
!= NULL
)
283 ms_pLogger
= wxTheApp
->CreateLogTarget();
285 ms_pLogger
= new wxLogStderr
;
288 s_bInGetActiveTarget
= FALSE
;
290 // do nothing if it fails - what can we do?
297 wxLog
*wxLog::SetActiveTarget(wxLog
*pLogger
)
299 if ( ms_pLogger
!= NULL
) {
300 // flush the old messages before changing because otherwise they might
301 // get lost later if this target is not restored
305 wxLog
*pOldLogger
= ms_pLogger
;
306 ms_pLogger
= pLogger
;
311 void wxLog::RemoveTraceMask(const wxString
& str
)
313 int index
= ms_aTraceMasks
.Index(str
);
314 if ( index
!= wxNOT_FOUND
)
315 ms_aTraceMasks
.Remove((size_t)index
);
318 void wxLog::TimeStamp(wxString
*str
)
324 (void)time(&timeNow
);
325 wxStrftime(buf
, WXSIZEOF(buf
), ms_timestamp
, localtime(&timeNow
));
328 *str
<< buf
<< _T(": ");
332 void wxLog::DoLog(wxLogLevel level
, const wxChar
*szString
, time_t t
)
335 case wxLOG_FatalError
:
336 DoLogString(wxString(_("Fatal error: ")) + szString
, t
);
337 DoLogString(_("Program aborted."), t
);
343 DoLogString(wxString(_("Error: ")) + szString
, t
);
347 DoLogString(wxString(_("Warning: ")) + szString
, t
);
353 default: // log unknown log levels too
354 DoLogString(szString
, t
);
364 DoLogString(szString
, t
);
370 void wxLog::DoLogString(const wxChar
*WXUNUSED(szString
), time_t WXUNUSED(t
))
372 wxFAIL_MSG(_T("DoLogString must be overriden if it's called."));
380 // ----------------------------------------------------------------------------
381 // wxLogStderr class implementation
382 // ----------------------------------------------------------------------------
384 wxLogStderr::wxLogStderr(FILE *fp
)
392 void wxLogStderr::DoLogString(const wxChar
*szString
, time_t WXUNUSED(t
))
396 str
<< szString
<< _T('\n');
398 fputs(str
.mb_str(), m_fp
);
401 // under Windows, programs usually don't have stderr at all, so make show the
402 // messages also under debugger
404 OutputDebugString(str
+ _T('\r'));
408 // ----------------------------------------------------------------------------
409 // wxLogStream implementation
410 // ----------------------------------------------------------------------------
412 #if wxUSE_STD_IOSTREAM
413 wxLogStream::wxLogStream(ostream
*ostr
)
421 void wxLogStream::DoLogString(const wxChar
*szString
, time_t WXUNUSED(t
))
423 (*m_ostr
) << wxConvCurrent
->cWX2MB(szString
) << endl
<< flush
;
425 #endif // wxUSE_STD_IOSTREAM
429 // ----------------------------------------------------------------------------
430 // wxLogTextCtrl implementation
431 // ----------------------------------------------------------------------------
433 wxLogTextCtrl::wxLogTextCtrl(wxTextCtrl
*pTextCtrl
)
435 m_pTextCtrl
= pTextCtrl
;
438 void wxLogTextCtrl::DoLogString(const wxChar
*szString
, time_t t
)
442 msg
<< szString
<< _T('\n');
444 m_pTextCtrl
->AppendText(msg
);
447 // ----------------------------------------------------------------------------
448 // wxLogGui implementation (FIXME MT-unsafe)
449 // ----------------------------------------------------------------------------
456 void wxLogGui::Clear()
458 m_bErrors
= m_bWarnings
= FALSE
;
463 void wxLogGui::Flush()
465 if ( !m_bHasMessages
)
468 // do it right now to block any new calls to Flush() while we're here
469 m_bHasMessages
= FALSE
;
471 // concatenate all strings (but not too many to not overfill the msg box)
474 nMsgCount
= m_aMessages
.Count();
476 // start from the most recent message
477 for ( size_t n
= nMsgCount
; n
> 0; n
-- ) {
478 // for Windows strings longer than this value are wrapped (NT 4.0)
479 const size_t nMsgLineWidth
= 156;
481 nLines
+= (m_aMessages
[n
- 1].Len() + nMsgLineWidth
- 1) / nMsgLineWidth
;
483 if ( nLines
> 25 ) // don't put too many lines in message box
486 str
<< m_aMessages
[n
- 1] << _T("\n");
496 else if ( m_bWarnings
) {
497 title
= _("Warning");
498 style
= wxICON_EXCLAMATION
;
501 title
= _("Information");
502 style
= wxICON_INFORMATION
;
505 wxMessageBox(str
, title
, wxOK
| style
);
507 // no undisplayed messages whatsoever
511 // the default behaviour is to discard all informational messages if there
512 // are any errors/warnings.
513 void wxLogGui::DoLog(wxLogLevel level
, const wxChar
*szString
, time_t t
)
520 m_aMessages
.Add(szString
);
521 m_aTimes
.Add((long)t
);
522 m_bHasMessages
= TRUE
;
529 // find the top window and set it's status text if it has any
530 wxFrame
*pFrame
= gs_pFrame
;
531 if ( pFrame
== NULL
) {
532 wxWindow
*pWin
= wxTheApp
->GetTopWindow();
533 if ( pWin
!= NULL
&& pWin
->IsKindOf(CLASSINFO(wxFrame
)) ) {
534 pFrame
= (wxFrame
*)pWin
;
538 if ( pFrame
!= NULL
)
539 pFrame
->SetStatusText(szString
);
541 #endif // wxUSE_STATUSBAR
549 // don't prepend debug/trace here: it goes to the
550 // debug window anyhow, but do put a timestamp
553 str
<< szString
<< _T("\n\r");
554 OutputDebugString(str
);
556 // send them to stderr
557 wxFprintf(stderr
, _T("%s: %s\n"),
558 level
== wxLOG_Trace
? _T("Trace")
564 #endif // __WXDEBUG__
568 case wxLOG_FatalError
:
569 // show this one immediately
570 wxMessageBox(szString
, _("Fatal error"), wxICON_HAND
);
574 // discard earlier informational messages if this is the 1st
575 // error because they might not make sense any more
579 m_bHasMessages
= TRUE
;
586 // for the warning we don't discard the info messages
590 m_aMessages
.Add(szString
);
591 m_aTimes
.Add((long)t
);
596 // ----------------------------------------------------------------------------
597 // wxLogWindow and wxLogFrame implementation
598 // ----------------------------------------------------------------------------
602 class wxLogFrame
: public wxFrame
606 wxLogFrame(wxFrame
*pParent
, wxLogWindow
*log
, const wxChar
*szTitle
);
607 virtual ~wxLogFrame();
610 void OnClose(wxCommandEvent
& event
);
611 void OnCloseWindow(wxCloseEvent
& event
);
613 void OnSave (wxCommandEvent
& event
);
615 void OnClear(wxCommandEvent
& event
);
617 void OnIdle(wxIdleEvent
&);
620 wxTextCtrl
*TextCtrl() const { return m_pTextCtrl
; }
630 // instead of closing just hide the window to be able to Show() it later
631 void DoClose() { Show(FALSE
); }
633 wxTextCtrl
*m_pTextCtrl
;
636 DECLARE_EVENT_TABLE()
639 BEGIN_EVENT_TABLE(wxLogFrame
, wxFrame
)
640 // wxLogWindow menu events
641 EVT_MENU(Menu_Close
, wxLogFrame::OnClose
)
643 EVT_MENU(Menu_Save
, wxLogFrame::OnSave
)
645 EVT_MENU(Menu_Clear
, wxLogFrame::OnClear
)
647 EVT_CLOSE(wxLogFrame::OnCloseWindow
)
650 wxLogFrame::wxLogFrame(wxFrame
*pParent
, wxLogWindow
*log
, const wxChar
*szTitle
)
651 : wxFrame(pParent
, -1, szTitle
)
655 m_pTextCtrl
= new wxTextCtrl(this, -1, wxEmptyString
, wxDefaultPosition
,
662 wxMenuBar
*pMenuBar
= new wxMenuBar
;
663 wxMenu
*pMenu
= new wxMenu
;
665 pMenu
->Append(Menu_Save
, _("&Save..."), _("Save log contents to file"));
667 pMenu
->Append(Menu_Clear
, _("C&lear"), _("Clear the log contents"));
668 pMenu
->AppendSeparator();
669 pMenu
->Append(Menu_Close
, _("&Close"), _("Close this window"));
670 pMenuBar
->Append(pMenu
, _("&Log"));
671 SetMenuBar(pMenuBar
);
674 // status bar for menu prompts
676 #endif // wxUSE_STATUSBAR
678 m_log
->OnFrameCreate(this);
681 void wxLogFrame::OnClose(wxCommandEvent
& WXUNUSED(event
))
686 void wxLogFrame::OnCloseWindow(wxCloseEvent
& WXUNUSED(event
))
692 void wxLogFrame::OnSave(wxCommandEvent
& WXUNUSED(event
))
696 const wxChar
*szFileName
= wxSaveFileSelector(_T("log"), _T("txt"), _T("log.txt"));
697 if ( szFileName
== NULL
) {
706 if ( wxFile::Exists(szFileName
) ) {
707 bool bAppend
= FALSE
;
709 strMsg
.Printf(_("Append log to file '%s' "
710 "(choosing [No] will overwrite it)?"), szFileName
);
711 switch ( wxMessageBox(strMsg
, _("Question"), wxYES_NO
| wxCANCEL
) ) {
724 wxFAIL_MSG(_("invalid message box return value"));
728 bOk
= file
.Open(szFileName
, wxFile::write_append
);
731 bOk
= file
.Create(szFileName
, TRUE
/* overwrite */);
735 bOk
= file
.Create(szFileName
);
738 // retrieve text and save it
739 // -------------------------
740 int nLines
= m_pTextCtrl
->GetNumberOfLines();
741 for ( int nLine
= 0; bOk
&& nLine
< nLines
; nLine
++ ) {
742 bOk
= file
.Write(m_pTextCtrl
->GetLineText(nLine
) +
743 // we're not going to pull in the whole wxTextFile if all we need is this...
746 #else // !wxUSE_TEXTFILE
748 #endif // wxUSE_TEXTFILE
756 wxLogError(_("Can't save log contents to file."));
759 wxLogStatus(this, _("Log saved to the file '%s'."), szFileName
);
764 void wxLogFrame::OnClear(wxCommandEvent
& WXUNUSED(event
))
766 m_pTextCtrl
->Clear();
769 wxLogFrame::~wxLogFrame()
771 m_log
->OnFrameDelete(this);
776 wxLogWindow::wxLogWindow(wxFrame
*pParent
,
777 const wxChar
*szTitle
,
781 m_bPassMessages
= bDoPass
;
783 m_pLogFrame
= new wxLogFrame(pParent
, this, szTitle
);
784 m_pOldLog
= wxLog::SetActiveTarget(this);
787 m_pLogFrame
->Show(TRUE
);
790 void wxLogWindow::Show(bool bShow
)
792 m_pLogFrame
->Show(bShow
);
795 void wxLogWindow::Flush()
797 if ( m_pOldLog
!= NULL
)
800 m_bHasMessages
= FALSE
;
803 void wxLogWindow::DoLog(wxLogLevel level
, const wxChar
*szString
, time_t t
)
805 // first let the previous logger show it
806 if ( m_pOldLog
!= NULL
&& m_bPassMessages
) {
807 // FIXME why can't we access protected wxLog method from here (we derive
808 // from wxLog)? gcc gives "DoLog is protected in this context", what
809 // does this mean? Anyhow, the cast is harmless and let's us do what
811 ((wxLogWindow
*)m_pOldLog
)->DoLog(level
, szString
, t
);
817 // by default, these messages are ignored by wxLog, so process
819 if ( !wxIsEmpty(szString
) )
822 str
<< _("Status: ") << szString
;
827 // don't put trace messages in the text window for 2 reasons:
828 // 1) there are too many of them
829 // 2) they may provoke other trace messages thus sending a program
830 // into an infinite loop
835 // and this will format it nicely and call our DoLogString()
836 wxLog::DoLog(level
, szString
, t
);
840 m_bHasMessages
= TRUE
;
843 void wxLogWindow::DoLogString(const wxChar
*szString
, time_t WXUNUSED(t
))
845 // put the text into our window
846 wxTextCtrl
*pText
= m_pLogFrame
->TextCtrl();
848 // remove selection (WriteText is in fact ReplaceSelection)
850 long nLen
= pText
->GetLastPosition();
851 pText
->SetSelection(nLen
, nLen
);
856 msg
<< szString
<< _T('\n');
858 pText
->AppendText(msg
);
860 // TODO ensure that the line can be seen
863 wxFrame
*wxLogWindow::GetFrame() const
868 void wxLogWindow::OnFrameCreate(wxFrame
* WXUNUSED(frame
))
872 void wxLogWindow::OnFrameDelete(wxFrame
* WXUNUSED(frame
))
874 m_pLogFrame
= (wxLogFrame
*)NULL
;
877 wxLogWindow::~wxLogWindow()
881 // may be NULL if log frame already auto destroyed itself
887 // ============================================================================
888 // Global functions/variables
889 // ============================================================================
891 // ----------------------------------------------------------------------------
893 // ----------------------------------------------------------------------------
895 wxLog
*wxLog::ms_pLogger
= (wxLog
*)NULL
;
896 bool wxLog::ms_doLog
= TRUE
;
897 bool wxLog::ms_bAutoCreate
= TRUE
;
899 const wxChar
*wxLog::ms_timestamp
= "%X"; // time only, no date
901 wxTraceMask
wxLog::ms_ulTraceMask
= (wxTraceMask
)0;
902 wxArrayString
wxLog::ms_aTraceMasks
;
904 // ----------------------------------------------------------------------------
905 // stdout error logging helper
906 // ----------------------------------------------------------------------------
908 // helper function: wraps the message and justifies it under given position
909 // (looks more pretty on the terminal). Also adds newline at the end.
911 // TODO this is now disabled until I find a portable way of determining the
912 // terminal window size (ok, I found it but does anybody really cares?)
913 #ifdef LOG_PRETTY_WRAP
914 static void wxLogWrap(FILE *f
, const char *pszPrefix
, const char *psz
)
916 size_t nMax
= 80; // FIXME
917 size_t nStart
= strlen(pszPrefix
);
921 while ( *psz
!= '\0' ) {
922 for ( n
= nStart
; (n
< nMax
) && (*psz
!= '\0'); n
++ )
926 if ( *psz
!= '\0' ) {
928 for ( n
= 0; n
< nStart
; n
++ )
931 // as we wrapped, squeeze all white space
932 while ( isspace(*psz
) )
939 #endif //LOG_PRETTY_WRAP
941 // ----------------------------------------------------------------------------
942 // error code/error message retrieval functions
943 // ----------------------------------------------------------------------------
945 // get error code from syste
946 unsigned long wxSysErrorCode()
950 return ::GetLastError();
952 // TODO what to do on Windows 3.1?
960 // get error message from system
961 const wxChar
*wxSysErrorMsg(unsigned long nErrCode
)
964 nErrCode
= wxSysErrorCode();
968 static wxChar s_szBuf
[LOG_BUFFER_SIZE
/ 2];
970 // get error message from system
972 FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER
| FORMAT_MESSAGE_FROM_SYSTEM
,
974 MAKELANGID(LANG_NEUTRAL
, SUBLANG_DEFAULT
),
978 // copy it to our buffer and free memory
979 wxStrncpy(s_szBuf
, (const wxChar
*)lpMsgBuf
, WXSIZEOF(s_szBuf
) - 1);
980 s_szBuf
[WXSIZEOF(s_szBuf
) - 1] = _T('\0');
983 // returned string is capitalized and ended with '\r\n' - bad
984 s_szBuf
[0] = (wxChar
)wxTolower(s_szBuf
[0]);
985 size_t len
= wxStrlen(s_szBuf
);
988 if ( s_szBuf
[len
- 2] == _T('\r') )
989 s_szBuf
[len
- 2] = _T('\0');
999 static wxChar s_szBuf
[LOG_BUFFER_SIZE
/ 2];
1000 wxConvCurrent
->MB2WC(s_szBuf
, strerror(nErrCode
), WXSIZEOF(s_szBuf
) -1);
1003 return strerror(nErrCode
);
1008 // ----------------------------------------------------------------------------
1010 // ----------------------------------------------------------------------------
1014 // break into the debugger
1019 #elif defined(__WXMAC__)
1025 #elif defined(__UNIX__)
1032 // this function is called when an assert fails
1033 void wxOnAssert(const wxChar
*szFile
, int nLine
, const wxChar
*szMsg
)
1035 // this variable can be set to true to suppress "assert failure" messages
1036 static bool s_bNoAsserts
= FALSE
;
1037 static bool s_bInAssert
= FALSE
; // FIXME MT-unsafe
1039 if ( s_bInAssert
) {
1040 // He-e-e-e-elp!! we're trapped in endless loop
1043 s_bInAssert
= FALSE
;
1050 wxChar szBuf
[LOG_BUFFER_SIZE
];
1052 // make life easier for people using VC++ IDE: clicking on the message
1053 // will take us immediately to the place of the failed assert
1055 wxSprintf(szBuf
, _T("%s(%d): assert failed"), szFile
, nLine
);
1057 // make the error message more clear for all the others
1058 wxSprintf(szBuf
, _T("Assert failed in file %s at line %d"), szFile
, nLine
);
1061 if ( szMsg
!= NULL
) {
1062 wxStrcat(szBuf
, _T(": "));
1063 wxStrcat(szBuf
, szMsg
);
1066 wxStrcat(szBuf
, _T("."));
1069 if ( !s_bNoAsserts
) {
1070 // send it to the normal log destination
1076 // this message is intentionally not translated - it is for
1078 wxStrcat(szBuf
, _T("\nDo you want to stop the program?"
1079 "\nYou can also choose [Cancel] to suppress "
1080 "further warnings."));
1082 switch ( wxMessageBox(szBuf
, _("Debug"),
1083 wxYES_NO
| wxCANCEL
| wxICON_STOP
) ) {
1089 s_bNoAsserts
= TRUE
;
1092 //case wxNO: nothing to do
1097 s_bInAssert
= FALSE
;