1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/common/log.cpp
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 licence
10 /////////////////////////////////////////////////////////////////////////////
12 // ============================================================================
14 // ============================================================================
16 // ----------------------------------------------------------------------------
18 // ----------------------------------------------------------------------------
20 // For compilers that support precompilation, includes "wx.h".
21 #include "wx/wxprec.h"
33 #include "wx/arrstr.h"
35 #include "wx/string.h"
39 #include "wx/apptrait.h"
40 #include "wx/datetime.h"
42 #include "wx/msgout.h"
43 #include "wx/textfile.h"
44 #include "wx/thread.h"
47 // other standard headers
57 #include "wx/msw/wince/time.h"
60 #if defined(__WINDOWS__)
61 #include "wx/msw/private.h" // includes windows.h
64 // ----------------------------------------------------------------------------
65 // non member functions
66 // ----------------------------------------------------------------------------
68 // define this to enable wrapping of log messages
69 //#define LOG_PRETTY_WRAP
71 #ifdef LOG_PRETTY_WRAP
72 static void wxLogWrap(FILE *f
, const char *pszPrefix
, const char *psz
);
75 // ============================================================================
77 // ============================================================================
79 // ----------------------------------------------------------------------------
80 // implementation of Log functions
82 // NB: unfortunately we need all these distinct functions, we can't make them
83 // macros and not all compilers inline vararg functions.
84 // ----------------------------------------------------------------------------
86 // generic log function
87 void wxVLogGeneric(wxLogLevel level
, const wxString
& format
, va_list argptr
)
89 if ( wxLog::IsEnabled() ) {
90 wxLog::OnLog(level
, wxString::FormatV(format
, argptr
), time(NULL
));
94 #if !wxUSE_UTF8_LOCALE_ONLY
95 void wxDoLogGenericWchar(wxLogLevel level
, const wxChar
*format
, ...)
98 va_start(argptr
, format
);
99 wxVLogGeneric(level
, format
, argptr
);
102 #endif // wxUSE_UTF8_LOCALE_ONLY
104 #if wxUSE_UNICODE_UTF8
105 void wxDoLogGenericUtf8(wxLogLevel level
, const char *format
, ...)
108 va_start(argptr
, format
);
109 wxVLogGeneric(level
, format
, argptr
);
112 #endif // wxUSE_UNICODE_UTF8
114 #if !wxUSE_UTF8_LOCALE_ONLY
115 #define IMPLEMENT_LOG_FUNCTION_WCHAR(level) \
116 void wxDoLog##level##Wchar(const wxChar *format, ...) \
119 va_start(argptr, format); \
120 wxVLog##level(format, argptr); \
124 #define IMPLEMENT_LOG_FUNCTION_WCHAR(level)
127 #if wxUSE_UNICODE_UTF8
128 #define IMPLEMENT_LOG_FUNCTION_UTF8(level) \
129 void wxDoLog##level##Utf8(const char *format, ...) \
132 va_start(argptr, format); \
133 wxVLog##level(format, argptr); \
137 #define IMPLEMENT_LOG_FUNCTION_UTF8(level)
140 #define IMPLEMENT_LOG_FUNCTION(level) \
141 void wxVLog##level(const wxString& format, va_list argptr) \
143 if ( wxLog::IsEnabled() ) { \
144 wxLog::OnLog(wxLOG_##level, \
145 wxString::FormatV(format, argptr), time(NULL)); \
148 IMPLEMENT_LOG_FUNCTION_WCHAR(level) \
149 IMPLEMENT_LOG_FUNCTION_UTF8(level)
151 IMPLEMENT_LOG_FUNCTION(Error
)
152 IMPLEMENT_LOG_FUNCTION(Warning
)
153 IMPLEMENT_LOG_FUNCTION(Message
)
154 IMPLEMENT_LOG_FUNCTION(Info
)
155 IMPLEMENT_LOG_FUNCTION(Status
)
157 void wxSafeShowMessage(const wxString
& title
, const wxString
& text
)
160 ::MessageBox(NULL
, text
, title
, MB_OK
| MB_ICONSTOP
);
162 wxFprintf(stderr
, _T("%s: %s\n"), title
.c_str(), text
.c_str());
167 // fatal errors can't be suppressed nor handled by the custom log target and
168 // always terminate the program
169 void wxVLogFatalError(const wxString
& format
, va_list argptr
)
171 wxSafeShowMessage(_T("Fatal Error"), wxString::FormatV(format
, argptr
));
180 #if !wxUSE_UTF8_LOCALE_ONLY
181 void wxDoLogFatalErrorWchar(const wxChar
*format
, ...)
184 va_start(argptr
, format
);
185 wxVLogFatalError(format
, argptr
);
187 // some compilers warn about unreachable code and it shouldn't matter
188 // for the others anyhow...
191 #endif // wxUSE_UTF8_LOCALE_ONLY
193 #if wxUSE_UNICODE_UTF8
194 void wxDoLogFatalErrorUtf8(const char *format
, ...)
197 va_start(argptr
, format
);
198 wxVLogFatalError(format
, argptr
);
200 // some compilers warn about unreachable code and it shouldn't matter
201 // for the others anyhow...
204 #endif // wxUSE_UNICODE_UTF8
206 // same as info, but only if 'verbose' mode is on
207 void wxVLogVerbose(const wxString
& format
, va_list argptr
)
209 if ( wxLog::IsEnabled() ) {
210 if ( wxLog::GetActiveTarget() != NULL
&& wxLog::GetVerbose() ) {
211 wxLog::OnLog(wxLOG_Info
,
212 wxString::FormatV(format
, argptr
), time(NULL
));
217 #if !wxUSE_UTF8_LOCALE_ONLY
218 void wxDoLogVerboseWchar(const wxChar
*format
, ...)
221 va_start(argptr
, format
);
222 wxVLogVerbose(format
, argptr
);
225 #endif // !wxUSE_UTF8_LOCALE_ONLY
227 #if wxUSE_UNICODE_UTF8
228 void wxDoLogVerboseUtf8(const char *format
, ...)
231 va_start(argptr
, format
);
232 wxVLogVerbose(format
, argptr
);
235 #endif // wxUSE_UNICODE_UTF8
240 #if !wxUSE_UTF8_LOCALE_ONLY
241 #define IMPLEMENT_LOG_DEBUG_FUNCTION_WCHAR(level) \
242 void wxDoLog##level##Wchar(const wxChar *format, ...) \
245 va_start(argptr, format); \
246 wxVLog##level(format, argptr); \
250 #define IMPLEMENT_LOG_DEBUG_FUNCTION_WCHAR(level)
253 #if wxUSE_UNICODE_UTF8
254 #define IMPLEMENT_LOG_DEBUG_FUNCTION_UTF8(level) \
255 void wxDoLog##level##Utf8(const char *format, ...) \
258 va_start(argptr, format); \
259 wxVLog##level(format, argptr); \
263 #define IMPLEMENT_LOG_DEBUG_FUNCTION_UTF8(level)
266 #define IMPLEMENT_LOG_DEBUG_FUNCTION(level) \
267 void wxVLog##level(const wxString& format, va_list argptr) \
269 if ( wxLog::IsEnabled() ) { \
270 wxLog::OnLog(wxLOG_##level, \
271 wxString::FormatV(format, argptr), time(NULL)); \
274 IMPLEMENT_LOG_DEBUG_FUNCTION_WCHAR(level) \
275 IMPLEMENT_LOG_DEBUG_FUNCTION_UTF8(level)
278 void wxVLogTrace(const wxString
& mask
, const wxString
& format
, va_list argptr
)
280 if ( wxLog::IsEnabled() && wxLog::IsAllowedTraceMask(mask
) ) {
282 msg
<< _T("(") << mask
<< _T(") ") << wxString::FormatV(format
, argptr
);
284 wxLog::OnLog(wxLOG_Trace
, msg
, time(NULL
));
288 #if !wxUSE_UTF8_LOCALE_ONLY
289 void wxDoLogTraceWchar(const wxString
& mask
, const wxChar
*format
, ...)
292 va_start(argptr
, format
);
293 wxVLogTrace(mask
, format
, argptr
);
296 #endif // !wxUSE_UTF8_LOCALE_ONLY
298 #if wxUSE_UNICODE_UTF8
299 void wxDoLogTraceUtf8(const wxString
& mask
, const char *format
, ...)
302 va_start(argptr
, format
);
303 wxVLogTrace(mask
, format
, argptr
);
306 #endif // wxUSE_UNICODE_UTF8
308 void wxVLogTrace(wxTraceMask mask
, const wxString
& format
, va_list argptr
)
310 // we check that all of mask bits are set in the current mask, so
311 // that wxLogTrace(wxTraceRefCount | wxTraceOle) will only do something
312 // if both bits are set.
313 if ( wxLog::IsEnabled() && ((wxLog::GetTraceMask() & mask
) == mask
) ) {
314 wxLog::OnLog(wxLOG_Trace
, wxString::FormatV(format
, argptr
), time(NULL
));
318 #if !wxUSE_UTF8_LOCALE_ONLY
319 void wxDoLogTraceWchar(wxTraceMask mask
, const wxChar
*format
, ...)
322 va_start(argptr
, format
);
323 wxVLogTrace(mask
, format
, argptr
);
326 #endif // !wxUSE_UTF8_LOCALE_ONLY
328 #if wxUSE_UNICODE_UTF8
329 void wxDoLogTraceUtf8(wxTraceMask mask
, const char *format
, ...)
332 va_start(argptr
, format
);
333 wxVLogTrace(mask
, format
, argptr
);
336 #endif // wxUSE_UNICODE_UTF8
339 // workaround for http://bugzilla.openwatcom.org/show_bug.cgi?id=351
340 void wxDoLogTraceWchar(int mask
, const wxChar
*format
, ...)
343 va_start(argptr
, format
);
344 wxVLogTrace(mask
, format
, argptr
);
348 void wxDoLogTraceWchar(const char *mask
, const wxChar
*format
, ...)
351 va_start(argptr
, format
);
352 wxVLogTrace(mask
, format
, argptr
);
356 void wxDoLogTraceWchar(const wchar_t *mask
, const wxChar
*format
, ...)
359 va_start(argptr
, format
);
360 wxVLogTrace(mask
, format
, argptr
);
364 void wxVLogTrace(int mask
, const wxString
& format
, va_list argptr
)
365 { wxVLogTrace((wxTraceMask
)mask
, format
, argptr
); }
366 void wxVLogTrace(const char *mask
, const wxString
& format
, va_list argptr
)
367 { wxVLogTrace(wxString(mask
), format
, argptr
); }
368 void wxVLogTrace(const wchar_t *mask
, const wxString
& format
, va_list argptr
)
369 { wxVLogTrace(wxString(mask
), format
, argptr
); }
370 #endif // __WATCOMC__
373 #define IMPLEMENT_LOG_DEBUG_FUNCTION(level)
376 IMPLEMENT_LOG_DEBUG_FUNCTION(Debug
)
377 IMPLEMENT_LOG_DEBUG_FUNCTION(Trace
)
379 // wxLogSysError: one uses the last error code, for other you must give it
382 // return the system error message description
383 static inline wxString
wxLogSysErrorHelper(long err
)
385 return wxString::Format(_(" (error %ld: %s)"), err
, wxSysErrorMsg(err
));
388 void WXDLLEXPORT
wxVLogSysError(const wxString
& format
, va_list argptr
)
390 wxVLogSysError(wxSysErrorCode(), format
, argptr
);
393 #if !wxUSE_UTF8_LOCALE_ONLY
394 void WXDLLEXPORT
wxDoLogSysErrorWchar(const wxChar
*format
, ...)
397 va_start(argptr
, format
);
398 wxVLogSysError(format
, argptr
);
401 #endif // !wxUSE_UTF8_LOCALE_ONLY
403 #if wxUSE_UNICODE_UTF8
404 void WXDLLEXPORT
wxDoLogSysErrorUtf8(const char *format
, ...)
407 va_start(argptr
, format
);
408 wxVLogSysError(format
, argptr
);
411 #endif // wxUSE_UNICODE_UTF8
413 void WXDLLEXPORT
wxVLogSysError(long err
, const wxString
& format
, va_list argptr
)
415 if ( wxLog::IsEnabled() ) {
416 wxLog::OnLog(wxLOG_Error
,
417 wxString::FormatV(format
, argptr
) + wxLogSysErrorHelper(err
),
422 #if !wxUSE_UTF8_LOCALE_ONLY
423 void WXDLLEXPORT
wxDoLogSysErrorWchar(long lErrCode
, const wxChar
*format
, ...)
426 va_start(argptr
, format
);
427 wxVLogSysError(lErrCode
, format
, argptr
);
430 #endif // !wxUSE_UTF8_LOCALE_ONLY
432 #if wxUSE_UNICODE_UTF8
433 void WXDLLEXPORT
wxDoLogSysErrorUtf8(long lErrCode
, const char *format
, ...)
436 va_start(argptr
, format
);
437 wxVLogSysError(lErrCode
, format
, argptr
);
440 #endif // wxUSE_UNICODE_UTF8
443 // workaround for http://bugzilla.openwatcom.org/show_bug.cgi?id=351
444 void WXDLLEXPORT
wxDoLogSysErrorWchar(unsigned long lErrCode
, const wxChar
*format
, ...)
447 va_start(argptr
, format
);
448 wxVLogSysError(lErrCode
, format
, argptr
);
452 void WXDLLEXPORT
wxVLogSysError(unsigned long err
, const wxString
& format
, va_list argptr
)
453 { wxVLogSysError((long)err
, format
, argptr
); }
454 #endif // __WATCOMC__
456 // ----------------------------------------------------------------------------
457 // wxLog class implementation
458 // ----------------------------------------------------------------------------
461 unsigned wxLog::DoLogNumberOfRepeats()
463 long retval
= ms_prevCounter
;
464 wxLog
*pLogger
= GetActiveTarget();
465 if ( pLogger
&& ms_prevCounter
> 0 )
469 msg
.Printf(wxPLURAL("The previous message repeated once.",
470 "The previous message repeated %lu times.",
474 msg
.Printf(wxT("The previous message was repeated."));
477 ms_prevString
.clear();
478 pLogger
->DoLog(ms_prevLevel
, msg
, ms_prevTimeStamp
);
485 if ( ms_prevCounter
> 0 )
487 // looks like the repeat count has not been logged yet,
488 // so let's do it now
489 wxLog::DoLogNumberOfRepeats();
494 void wxLog::OnLog(wxLogLevel level
, const wxString
& szString
, time_t t
)
496 if ( IsEnabled() && ms_logLevel
>= level
)
498 wxLog
*pLogger
= GetActiveTarget();
501 if ( GetRepetitionCounting() && ms_prevString
== szString
)
507 if ( GetRepetitionCounting() )
509 DoLogNumberOfRepeats();
511 ms_prevString
= szString
;
512 ms_prevLevel
= level
;
513 ms_prevTimeStamp
= t
;
514 pLogger
->DoLog(level
, szString
, t
);
520 // deprecated function
521 #if WXWIN_COMPATIBILITY_2_6
523 wxChar
*wxLog::SetLogBuffer(wxChar
* WXUNUSED(buf
), size_t WXUNUSED(size
))
528 #endif // WXWIN_COMPATIBILITY_2_6
530 #if WXWIN_COMPATIBILITY_2_8
532 void wxLog::DoLog(wxLogLevel
WXUNUSED(level
),
533 const char *WXUNUSED(szString
),
538 void wxLog::DoLog(wxLogLevel
WXUNUSED(level
),
539 const wchar_t *WXUNUSED(wzString
),
544 #endif // WXWIN_COMPATIBILITY_2_8
546 wxLog
*wxLog::GetActiveTarget()
548 if ( ms_bAutoCreate
&& ms_pLogger
== NULL
) {
549 // prevent infinite recursion if someone calls wxLogXXX() from
550 // wxApp::CreateLogTarget()
551 static bool s_bInGetActiveTarget
= false;
552 if ( !s_bInGetActiveTarget
) {
553 s_bInGetActiveTarget
= true;
555 // ask the application to create a log target for us
556 if ( wxTheApp
!= NULL
)
557 ms_pLogger
= wxTheApp
->GetTraits()->CreateLogTarget();
559 ms_pLogger
= new wxLogStderr
;
561 s_bInGetActiveTarget
= false;
563 // do nothing if it fails - what can we do?
570 wxLog
*wxLog::SetActiveTarget(wxLog
*pLogger
)
572 if ( ms_pLogger
!= NULL
) {
573 // flush the old messages before changing because otherwise they might
574 // get lost later if this target is not restored
578 wxLog
*pOldLogger
= ms_pLogger
;
579 ms_pLogger
= pLogger
;
584 void wxLog::DontCreateOnDemand()
586 ms_bAutoCreate
= false;
588 // this is usually called at the end of the program and we assume that it
589 // is *always* called at the end - so we free memory here to avoid false
590 // memory leak reports from wxWin memory tracking code
594 void wxLog::DoCreateOnDemand()
596 ms_bAutoCreate
= true;
599 void wxLog::RemoveTraceMask(const wxString
& str
)
601 int index
= ms_aTraceMasks
.Index(str
);
602 if ( index
!= wxNOT_FOUND
)
603 ms_aTraceMasks
.RemoveAt((size_t)index
);
606 void wxLog::ClearTraceMasks()
608 ms_aTraceMasks
.Clear();
611 void wxLog::TimeStamp(wxString
*str
)
618 (void)time(&timeNow
);
621 wxStrftime(buf
, WXSIZEOF(buf
),
622 ms_timestamp
, wxLocaltime_r(&timeNow
, &tm
));
625 *str
<< buf
<< wxT(": ");
627 #endif // wxUSE_DATETIME
630 void wxLog::DoLog(wxLogLevel level
, const wxString
& szString
, time_t t
)
632 #if WXWIN_COMPATIBILITY_2_8
633 // DoLog() signature changed since 2.8, so we call the old versions here
634 // so that existing custom log classes still work:
635 DoLog(level
, (const char*)szString
.mb_str(), t
);
636 DoLog(level
, (const wchar_t*)szString
.wc_str(), t
);
640 case wxLOG_FatalError
:
641 LogString(_("Fatal error: ") + szString
, t
);
642 LogString(_("Program aborted."), t
);
652 LogString(_("Error: ") + szString
, t
);
656 LogString(_("Warning: ") + szString
, t
);
663 default: // log unknown log levels too
664 LogString(szString
, t
);
671 wxString msg
= level
== wxLOG_Trace
? wxT("Trace: ")
681 void wxLog::DoLogString(const wxString
& szString
, time_t t
)
683 #if WXWIN_COMPATIBILITY_2_8
684 // DoLogString() signature changed since 2.8, so we call the old versions
685 // here so that existing custom log classes still work; unfortunately this
686 // also means that we can't have the wxFAIL_MSG below in compat mode
687 DoLogString((const char*)szString
.mb_str(), t
);
688 DoLogString((const wchar_t*)szString
.wc_str(), t
);
690 wxFAIL_MSG(wxT("DoLogString must be overriden if it's called."));
691 wxUnusedVar(szString
);
698 // nothing to do here
701 /*static*/ bool wxLog::IsAllowedTraceMask(const wxString
& mask
)
703 for ( wxArrayString::iterator it
= ms_aTraceMasks
.begin(),
704 en
= ms_aTraceMasks
.end();
711 // ----------------------------------------------------------------------------
712 // wxLogBuffer implementation
713 // ----------------------------------------------------------------------------
715 void wxLogBuffer::Flush()
717 if ( !m_str
.empty() )
719 wxMessageOutputBest out
;
720 out
.Printf(_T("%s"), m_str
.c_str());
725 void wxLogBuffer::DoLog(wxLogLevel level
, const wxString
& szString
, time_t t
)
732 // don't put debug messages in the buffer, we don't want to show
733 // them to the user in a msg box, log them immediately
739 wxMessageOutputDebug dbgout
;
740 dbgout
.Printf(_T("%s\n"), str
.c_str());
742 #endif // __WXDEBUG__
746 wxLog::DoLog(level
, szString
, t
);
750 void wxLogBuffer::DoLogString(const wxString
& szString
, time_t WXUNUSED(t
))
752 m_str
<< szString
<< _T("\n");
755 // ----------------------------------------------------------------------------
756 // wxLogStderr class implementation
757 // ----------------------------------------------------------------------------
759 wxLogStderr::wxLogStderr(FILE *fp
)
767 void wxLogStderr::DoLogString(const wxString
& szString
, time_t WXUNUSED(t
))
774 wxFputc(_T('\n'), m_fp
);
777 // under GUI systems such as Windows or Mac, programs usually don't have
778 // stderr at all, so show the messages also somewhere else, typically in
779 // the debugger window so that they go at least somewhere instead of being
781 if ( m_fp
== stderr
)
783 wxAppTraits
*traits
= wxTheApp
? wxTheApp
->GetTraits() : NULL
;
784 if ( traits
&& !traits
->HasStderr() )
786 wxMessageOutputDebug dbgout
;
787 dbgout
.Printf(_T("%s\n"), str
.c_str());
792 // ----------------------------------------------------------------------------
793 // wxLogStream implementation
794 // ----------------------------------------------------------------------------
796 #if wxUSE_STD_IOSTREAM
797 #include "wx/ioswrap.h"
798 wxLogStream::wxLogStream(wxSTD ostream
*ostr
)
801 m_ostr
= &wxSTD cerr
;
806 void wxLogStream::DoLogString(const wxString
& szString
, time_t WXUNUSED(t
))
810 (*m_ostr
) << stamp
<< szString
<< wxSTD endl
;
812 #endif // wxUSE_STD_IOSTREAM
814 // ----------------------------------------------------------------------------
816 // ----------------------------------------------------------------------------
818 wxLogChain::wxLogChain(wxLog
*logger
)
820 m_bPassMessages
= true;
823 m_logOld
= wxLog::SetActiveTarget(this);
826 wxLogChain::~wxLogChain()
830 if ( m_logNew
!= this )
834 void wxLogChain::SetLog(wxLog
*logger
)
836 if ( m_logNew
!= this )
842 void wxLogChain::Flush()
847 // be careful to avoid infinite recursion
848 if ( m_logNew
&& m_logNew
!= this )
852 void wxLogChain::DoLog(wxLogLevel level
, const wxString
& szString
, time_t t
)
854 // let the previous logger show it
855 if ( m_logOld
&& IsPassingMessages() )
857 // bogus cast just to access protected DoLog
858 ((wxLogChain
*)m_logOld
)->DoLog(level
, szString
, t
);
861 if ( m_logNew
&& m_logNew
!= this )
864 ((wxLogChain
*)m_logNew
)->DoLog(level
, szString
, t
);
868 // ----------------------------------------------------------------------------
870 // ----------------------------------------------------------------------------
873 // "'this' : used in base member initializer list" - so what?
874 #pragma warning(disable:4355)
877 wxLogPassThrough::wxLogPassThrough()
883 #pragma warning(default:4355)
886 // ============================================================================
887 // Global functions/variables
888 // ============================================================================
890 // ----------------------------------------------------------------------------
892 // ----------------------------------------------------------------------------
894 bool wxLog::ms_bRepetCounting
= false;
895 wxString
wxLog::ms_prevString
;
896 unsigned int wxLog::ms_prevCounter
= 0;
897 time_t wxLog::ms_prevTimeStamp
= 0;
898 wxLogLevel
wxLog::ms_prevLevel
;
900 wxLog
*wxLog::ms_pLogger
= (wxLog
*)NULL
;
901 bool wxLog::ms_doLog
= true;
902 bool wxLog::ms_bAutoCreate
= true;
903 bool wxLog::ms_bVerbose
= false;
905 wxLogLevel
wxLog::ms_logLevel
= wxLOG_Max
; // log everything by default
907 size_t wxLog::ms_suspendCount
= 0;
909 wxString
wxLog::ms_timestamp(wxT("%X")); // time only, no date
911 wxTraceMask
wxLog::ms_ulTraceMask
= (wxTraceMask
)0;
912 wxArrayString
wxLog::ms_aTraceMasks
;
914 // ----------------------------------------------------------------------------
915 // stdout error logging helper
916 // ----------------------------------------------------------------------------
918 // helper function: wraps the message and justifies it under given position
919 // (looks more pretty on the terminal). Also adds newline at the end.
921 // TODO this is now disabled until I find a portable way of determining the
922 // terminal window size (ok, I found it but does anybody really cares?)
923 #ifdef LOG_PRETTY_WRAP
924 static void wxLogWrap(FILE *f
, const char *pszPrefix
, const char *psz
)
926 size_t nMax
= 80; // FIXME
927 size_t nStart
= strlen(pszPrefix
);
931 while ( *psz
!= '\0' ) {
932 for ( n
= nStart
; (n
< nMax
) && (*psz
!= '\0'); n
++ )
936 if ( *psz
!= '\0' ) {
938 for ( n
= 0; n
< nStart
; n
++ )
941 // as we wrapped, squeeze all white space
942 while ( isspace(*psz
) )
949 #endif //LOG_PRETTY_WRAP
951 // ----------------------------------------------------------------------------
952 // error code/error message retrieval functions
953 // ----------------------------------------------------------------------------
955 // get error code from syste
956 unsigned long wxSysErrorCode()
958 #if defined(__WXMSW__) && !defined(__WXMICROWIN__)
959 return ::GetLastError();
965 // get error message from system
966 const wxChar
*wxSysErrorMsg(unsigned long nErrCode
)
969 nErrCode
= wxSysErrorCode();
971 #if defined(__WXMSW__) && !defined(__WXMICROWIN__)
972 static wxChar s_szBuf
[1024];
974 // get error message from system
978 FORMAT_MESSAGE_ALLOCATE_BUFFER
| FORMAT_MESSAGE_FROM_SYSTEM
,
981 MAKELANGID(LANG_NEUTRAL
, SUBLANG_DEFAULT
),
987 // if this happens, something is seriously wrong, so don't use _() here
989 wxSprintf(s_szBuf
, _T("unknown error %lx"), nErrCode
);
994 // copy it to our buffer and free memory
995 // Crashes on SmartPhone (FIXME)
996 #if !defined(__SMARTPHONE__) /* of WinCE */
999 wxStrncpy(s_szBuf
, (const wxChar
*)lpMsgBuf
, WXSIZEOF(s_szBuf
) - 1);
1000 s_szBuf
[WXSIZEOF(s_szBuf
) - 1] = wxT('\0');
1002 LocalFree(lpMsgBuf
);
1004 // returned string is capitalized and ended with '\r\n' - bad
1005 s_szBuf
[0] = (wxChar
)wxTolower(s_szBuf
[0]);
1006 size_t len
= wxStrlen(s_szBuf
);
1009 if ( s_szBuf
[len
- 2] == wxT('\r') )
1010 s_szBuf
[len
- 2] = wxT('\0');
1014 #endif // !__SMARTPHONE__
1016 s_szBuf
[0] = wxT('\0');
1022 static wchar_t s_wzBuf
[1024];
1023 wxConvCurrent
->MB2WC(s_wzBuf
, strerror((int)nErrCode
),
1024 WXSIZEOF(s_wzBuf
) - 1);
1027 return strerror((int)nErrCode
);
1029 #endif // __WXMSW__/!__WXMSW__