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"
45 #include "wx/private/threadinfo.h"
47 #include "wx/vector.h"
49 // other standard headers
60 #include "wx/msw/wince/time.h"
62 #endif /* ! __WXPALMOS5__ */
64 #if defined(__WINDOWS__)
65 #include "wx/msw/private.h" // includes windows.h
68 #undef wxLOG_COMPONENT
69 const char *wxLOG_COMPONENT
= "";
71 // this macro allows to define an object which will be initialized before any
72 // other function in this file is called: this is necessary to allow log
73 // functions to be used during static initialization (this is not advisable
74 // anyhow but we should at least try to not crash) and to also ensure that they
75 // are initialized by the time static initialization is done, i.e. before any
76 // threads are created hopefully
78 // the net effect of all this is that you can use Get##name() function to
79 // access the object without worrying about it being not initialized
81 // see also WX_DEFINE_GLOBAL_CONV2() in src/common/strconv.cpp
82 #define WX_DEFINE_GLOBAL_VAR(type, name) \
83 inline type& Get##name() \
85 static type s_##name; \
89 type *gs_##name##Ptr = &Get##name()
93 wxTLS_TYPE(wxThreadSpecificInfo
) wxThreadInfoVar
;
98 // contains messages logged by the other threads and waiting to be shown until
99 // Flush() is called in the main one
100 typedef wxVector
<wxLogRecord
> wxLogRecords
;
101 wxLogRecords gs_bufferedLogRecords
;
103 #define WX_DEFINE_LOG_CS(name) WX_DEFINE_GLOBAL_VAR(wxCriticalSection, name##CS)
105 // this critical section is used for buffering the messages from threads other
106 // than main, i.e. it protects all accesses to gs_bufferedLogRecords above
107 WX_DEFINE_LOG_CS(BackgroundLog
);
109 // this one is used for protecting TraceMasks() from concurrent access
110 WX_DEFINE_LOG_CS(TraceMask
);
112 // and this one is used for GetComponentLevels()
113 WX_DEFINE_LOG_CS(Levels
);
115 } // anonymous namespace
117 #endif // wxUSE_THREADS
119 // ----------------------------------------------------------------------------
120 // non member functions
121 // ----------------------------------------------------------------------------
123 // define this to enable wrapping of log messages
124 //#define LOG_PRETTY_WRAP
126 #ifdef LOG_PRETTY_WRAP
127 static void wxLogWrap(FILE *f
, const char *pszPrefix
, const char *psz
);
130 // ----------------------------------------------------------------------------
132 // ----------------------------------------------------------------------------
137 // this struct is used to store information about the previous log message used
138 // by OnLog() to (optionally) avoid logging multiple copies of the same message
139 struct PreviousLogInfo
147 // previous message itself
153 // other information about it
154 wxLogRecordInfo info
;
156 // the number of times it was already repeated
157 unsigned numRepeated
;
160 PreviousLogInfo gs_prevLog
;
163 // map containing all components for which log level was explicitly set
165 // NB: all accesses to it must be protected by GetLevelsCS() critical section
166 WX_DEFINE_GLOBAL_VAR(wxStringToNumHashMap
, ComponentLevels
);
168 // ----------------------------------------------------------------------------
169 // wxLogOutputBest: wxLog wrapper around wxMessageOutputBest
170 // ----------------------------------------------------------------------------
172 class wxLogOutputBest
: public wxLog
175 wxLogOutputBest() { }
178 virtual void DoLogText(const wxString
& msg
)
180 wxMessageOutputBest().Output(msg
);
184 wxDECLARE_NO_COPY_CLASS(wxLogOutputBest
);
187 } // anonymous namespace
189 // ============================================================================
191 // ============================================================================
193 // ----------------------------------------------------------------------------
194 // helper global functions
195 // ----------------------------------------------------------------------------
197 void wxSafeShowMessage(const wxString
& title
, const wxString
& text
)
200 ::MessageBox(NULL
, text
.t_str(), title
.t_str(), MB_OK
| MB_ICONSTOP
);
202 wxFprintf(stderr
, wxS("%s: %s\n"), title
.c_str(), text
.c_str());
207 // ----------------------------------------------------------------------------
208 // wxLogFormatter class implementation
209 // ----------------------------------------------------------------------------
212 wxLogFormatter::Format(wxLogLevel level
,
214 const wxLogRecordInfo
& info
) const
216 wxString prefix
= FormatTime(info
.timestamp
);
221 prefix
+= _("Error: ");
225 prefix
+= _("Warning: ");
228 // don't prepend "debug/trace" prefix under MSW as it goes to the debug
229 // window anyhow and so can't be confused with something else
232 // this prefix (as well as the one below) is intentionally not
233 // translated as nobody translates debug messages anyhow
247 wxLogFormatter::FormatTime(time_t t
) const
251 // don't time stamp debug messages under MSW as debug viewers usually
252 // already have an option to do it
254 if ( level
!= wxLOG_Debug
&& level
!= wxLOG_Trace
)
256 wxLog::TimeStamp(&str
, t
);
262 // ----------------------------------------------------------------------------
263 // wxLog class implementation
264 // ----------------------------------------------------------------------------
266 unsigned wxLog::LogLastRepeatIfNeeded()
268 const unsigned count
= gs_prevLog
.numRepeated
;
270 if ( gs_prevLog
.numRepeated
)
274 if ( gs_prevLog
.numRepeated
== 1 )
276 // We use a separate message for this case as "repeated 1 time"
277 // looks somewhat strange.
278 msg
= _("The previous message repeated once.");
282 // Notice that we still use wxPLURAL() to ensure that multiple
283 // numbers of times are correctly formatted, even though we never
284 // actually use the singular string.
285 msg
.Printf(wxPLURAL("The previous message repeated %lu time.",
286 "The previous message repeated %lu times.",
287 gs_prevLog
.numRepeated
),
288 gs_prevLog
.numRepeated
);
291 msg
.Printf(wxS("The previous message was repeated %lu time(s)."),
292 gs_prevLog
.numRepeated
);
294 gs_prevLog
.numRepeated
= 0;
295 gs_prevLog
.msg
.clear();
296 DoLogRecord(gs_prevLog
.level
, msg
, gs_prevLog
.info
);
304 // Flush() must be called before destroying the object as otherwise some
305 // messages could be lost
306 if ( gs_prevLog
.numRepeated
)
308 wxMessageOutputDebug().Printf
313 "Last repeated message (\"%s\", %lu time) wasn't output",
314 "Last repeated message (\"%s\", %lu times) wasn't output",
315 gs_prevLog
.numRepeated
318 wxS("Last repeated message (\"%s\", %lu time(s)) wasn't output"),
321 gs_prevLog
.numRepeated
328 // ----------------------------------------------------------------------------
329 // wxLog logging functions
330 // ----------------------------------------------------------------------------
334 wxLog::OnLog(wxLogLevel level
, const wxString
& msg
, time_t t
)
336 wxLogRecordInfo info
;
339 info
.threadId
= wxThread::GetCurrentId();
340 #endif // wxUSE_THREADS
342 OnLog(level
, msg
, info
);
347 wxLog::OnLog(wxLogLevel level
,
349 const wxLogRecordInfo
& info
)
351 // fatal errors can't be suppressed nor handled by the custom log target
352 // and always terminate the program
353 if ( level
== wxLOG_FatalError
)
355 wxSafeShowMessage(wxS("Fatal Error"), msg
);
367 if ( !wxThread::IsMain() )
369 logger
= wxThreadInfo
.logger
;
374 // buffer the messages until they can be shown from the main
376 wxCriticalSectionLocker
lock(GetBackgroundLogCS());
378 gs_bufferedLogRecords
.push_back(wxLogRecord(level
, msg
, info
));
380 // ensure that our Flush() will be called soon
383 //else: we don't have any logger at all, there is no need to log
388 //else: we have a thread-specific logger, we can send messages to it
392 #endif // wxUSE_THREADS
394 logger
= GetMainThreadActiveTarget();
399 logger
->CallDoLogNow(level
, msg
, info
);
403 wxLog::CallDoLogNow(wxLogLevel level
,
405 const wxLogRecordInfo
& info
)
407 if ( GetRepetitionCounting() )
409 if ( msg
== gs_prevLog
.msg
)
411 gs_prevLog
.numRepeated
++;
413 // nothing else to do, in particular, don't log the
418 LogLastRepeatIfNeeded();
420 // reset repetition counter for a new message
421 gs_prevLog
.msg
= msg
;
422 gs_prevLog
.level
= level
;
423 gs_prevLog
.info
= info
;
426 // handle extra data which may be passed to us by wxLogXXX()
427 wxString prefix
, suffix
;
429 if ( info
.GetNumValue(wxLOG_KEY_SYS_ERROR_CODE
, &num
) )
431 const long err
= static_cast<long>(num
);
433 suffix
.Printf(_(" (error %ld: %s)"), err
, wxSysErrorMsg(err
));
438 if ( level
== wxLOG_Trace
&& info
.GetStrValue(wxLOG_KEY_TRACE_MASK
, &str
) )
440 prefix
= "(" + str
+ ") ";
442 #endif // wxUSE_LOG_TRACE
444 DoLogRecord(level
, prefix
+ msg
+ suffix
, info
);
447 void wxLog::DoLogRecord(wxLogLevel level
,
449 const wxLogRecordInfo
& info
)
451 #if WXWIN_COMPATIBILITY_2_8
452 // call the old DoLog() to ensure that existing custom log classes still
455 // as the user code could have defined it as either taking "const char *"
456 // (in ANSI build) or "const wxChar *" (in ANSI/Unicode), we have no choice
457 // but to call both of them
458 DoLog(level
, (const char*)msg
.mb_str(), info
.timestamp
);
459 DoLog(level
, (const wchar_t*)msg
.wc_str(), info
.timestamp
);
460 #else // !WXWIN_COMPATIBILITY_2_8
462 #endif // WXWIN_COMPATIBILITY_2_8/!WXWIN_COMPATIBILITY_2_8
464 // Use wxLogFormatter to format the message
465 DoLogTextAtLevel(level
, m_formatter
->Format (level
, msg
, info
));
468 void wxLog::DoLogTextAtLevel(wxLogLevel level
, const wxString
& msg
)
470 // we know about debug messages (because using wxMessageOutputDebug is the
471 // right thing to do in 99% of all cases and also for compatibility) but
472 // anything else needs to be handled in the derived class
473 if ( level
== wxLOG_Debug
|| level
== wxLOG_Trace
)
475 wxMessageOutputDebug().Output(msg
+ wxS('\n'));
483 void wxLog::DoLogText(const wxString
& WXUNUSED(msg
))
485 // in 2.8-compatible build the derived class might override DoLog() or
486 // DoLogString() instead so we can't have this assert there
487 #if !WXWIN_COMPATIBILITY_2_8
488 wxFAIL_MSG( "must be overridden if it is called" );
489 #endif // WXWIN_COMPATIBILITY_2_8
492 #if WXWIN_COMPATIBILITY_2_8
494 void wxLog::DoLog(wxLogLevel
WXUNUSED(level
), const char *szString
, time_t t
)
496 DoLogString(szString
, t
);
499 void wxLog::DoLog(wxLogLevel
WXUNUSED(level
), const wchar_t *wzString
, time_t t
)
501 DoLogString(wzString
, t
);
504 #endif // WXWIN_COMPATIBILITY_2_8
506 // ----------------------------------------------------------------------------
507 // wxLog active target management
508 // ----------------------------------------------------------------------------
510 wxLog
*wxLog::GetActiveTarget()
513 if ( !wxThread::IsMain() )
515 // check if we have a thread-specific log target
516 wxLog
* const logger
= wxThreadInfo
.logger
;
518 // the code below should be only executed for the main thread as
519 // CreateLogTarget() is not meant for auto-creating log targets for
520 // worker threads so skip it in any case
521 return logger
? logger
: ms_pLogger
;
523 #endif // wxUSE_THREADS
525 return GetMainThreadActiveTarget();
529 wxLog
*wxLog::GetMainThreadActiveTarget()
531 if ( ms_bAutoCreate
&& ms_pLogger
== NULL
) {
532 // prevent infinite recursion if someone calls wxLogXXX() from
533 // wxApp::CreateLogTarget()
534 static bool s_bInGetActiveTarget
= false;
535 if ( !s_bInGetActiveTarget
) {
536 s_bInGetActiveTarget
= true;
538 // ask the application to create a log target for us
539 if ( wxTheApp
!= NULL
)
540 ms_pLogger
= wxTheApp
->GetTraits()->CreateLogTarget();
542 ms_pLogger
= new wxLogOutputBest
;
544 s_bInGetActiveTarget
= false;
546 // do nothing if it fails - what can we do?
553 wxLog
*wxLog::SetActiveTarget(wxLog
*pLogger
)
555 if ( ms_pLogger
!= NULL
) {
556 // flush the old messages before changing because otherwise they might
557 // get lost later if this target is not restored
561 wxLog
*pOldLogger
= ms_pLogger
;
562 ms_pLogger
= pLogger
;
569 wxLog
*wxLog::SetThreadActiveTarget(wxLog
*logger
)
571 wxASSERT_MSG( !wxThread::IsMain(), "use SetActiveTarget() for main thread" );
573 wxLog
* const oldLogger
= wxThreadInfo
.logger
;
577 wxThreadInfo
.logger
= logger
;
581 #endif // wxUSE_THREADS
583 void wxLog::DontCreateOnDemand()
585 ms_bAutoCreate
= false;
587 // this is usually called at the end of the program and we assume that it
588 // is *always* called at the end - so we free memory here to avoid false
589 // memory leak reports from wxWin memory tracking code
593 void wxLog::DoCreateOnDemand()
595 ms_bAutoCreate
= true;
598 // ----------------------------------------------------------------------------
599 // wxLog components levels
600 // ----------------------------------------------------------------------------
603 void wxLog::SetComponentLevel(const wxString
& component
, wxLogLevel level
)
605 if ( component
.empty() )
611 wxCRIT_SECT_LOCKER(lock
, GetLevelsCS());
613 GetComponentLevels()[component
] = level
;
618 wxLogLevel
wxLog::GetComponentLevel(wxString component
)
620 wxCRIT_SECT_LOCKER(lock
, GetLevelsCS());
622 const wxStringToNumHashMap
& componentLevels
= GetComponentLevels();
623 while ( !component
.empty() )
625 wxStringToNumHashMap::const_iterator
626 it
= componentLevels
.find(component
);
627 if ( it
!= componentLevels
.end() )
628 return static_cast<wxLogLevel
>(it
->second
);
630 component
= component
.BeforeLast('/');
633 return GetLogLevel();
636 // ----------------------------------------------------------------------------
638 // ----------------------------------------------------------------------------
643 // because IsAllowedTraceMask() may be called during static initialization
644 // (this is not recommended but it may still happen, see #11592) we can't use a
645 // simple static variable which might be not initialized itself just yet to
646 // store the trace masks, but need this accessor function which will ensure
647 // that the variable is always correctly initialized before being accessed
649 // notice that this doesn't make accessing it MT-safe, of course, you need to
650 // serialize accesses to it using GetTraceMaskCS() for this
651 wxArrayString
& TraceMasks()
653 static wxArrayString s_traceMasks
;
658 } // anonymous namespace
660 /* static */ const wxArrayString
& wxLog::GetTraceMasks()
662 // because of this function signature (it returns a reference, not the
663 // object), it is inherently MT-unsafe so there is no need to acquire the
669 void wxLog::AddTraceMask(const wxString
& str
)
671 wxCRIT_SECT_LOCKER(lock
, GetTraceMaskCS());
673 TraceMasks().push_back(str
);
676 void wxLog::RemoveTraceMask(const wxString
& str
)
678 wxCRIT_SECT_LOCKER(lock
, GetTraceMaskCS());
680 int index
= TraceMasks().Index(str
);
681 if ( index
!= wxNOT_FOUND
)
682 TraceMasks().RemoveAt((size_t)index
);
685 void wxLog::ClearTraceMasks()
687 wxCRIT_SECT_LOCKER(lock
, GetTraceMaskCS());
689 TraceMasks().Clear();
692 /*static*/ bool wxLog::IsAllowedTraceMask(const wxString
& mask
)
694 wxCRIT_SECT_LOCKER(lock
, GetTraceMaskCS());
696 const wxArrayString
& masks
= GetTraceMasks();
697 for ( wxArrayString::const_iterator it
= masks
.begin(),
709 // ----------------------------------------------------------------------------
710 // wxLog miscellaneous other methods
711 // ----------------------------------------------------------------------------
715 void wxLog::TimeStamp(wxString
*str
)
717 if ( !ms_timestamp
.empty() )
719 *str
= wxDateTime::UNow().Format(ms_timestamp
);
724 void wxLog::TimeStamp(wxString
*str
, time_t t
)
726 if ( !ms_timestamp
.empty() )
728 *str
= wxDateTime(t
).Format(ms_timestamp
);
733 #else // !wxUSE_DATETIME
735 void wxLog::TimeStamp(wxString
*)
739 void wxLog::TimeStamp(wxString
*, time_t)
743 #endif // wxUSE_DATETIME/!wxUSE_DATETIME
747 void wxLog::FlushThreadMessages()
749 // check if we have queued messages from other threads
750 wxLogRecords bufferedLogRecords
;
753 wxCriticalSectionLocker
lock(GetBackgroundLogCS());
754 bufferedLogRecords
.swap(gs_bufferedLogRecords
);
756 // release the lock now to not keep it while we are logging the
757 // messages below, allowing background threads to run
760 if ( !bufferedLogRecords
.empty() )
762 for ( wxLogRecords::const_iterator it
= bufferedLogRecords
.begin();
763 it
!= bufferedLogRecords
.end();
766 CallDoLogNow(it
->level
, it
->msg
, it
->info
);
772 bool wxLog::IsThreadLoggingEnabled()
774 return !wxThreadInfo
.loggingDisabled
;
778 bool wxLog::EnableThreadLogging(bool enable
)
780 const bool wasEnabled
= !wxThreadInfo
.loggingDisabled
;
781 wxThreadInfo
.loggingDisabled
= !enable
;
785 #endif // wxUSE_THREADS
787 wxLogFormatter
*wxLog::SetFormatter(wxLogFormatter
* formatter
)
789 wxLogFormatter
* formatterOld
= m_formatter
;
790 m_formatter
= formatter
? formatter
: new wxLogFormatter
;
797 LogLastRepeatIfNeeded();
801 void wxLog::FlushActive()
803 if ( ms_suspendCount
)
806 wxLog
* const log
= GetActiveTarget();
810 if ( wxThread::IsMain() )
811 log
->FlushThreadMessages();
812 #endif // wxUSE_THREADS
818 // ----------------------------------------------------------------------------
819 // wxLogBuffer implementation
820 // ----------------------------------------------------------------------------
822 void wxLogBuffer::Flush()
826 if ( !m_str
.empty() )
828 wxMessageOutputBest out
;
829 out
.Printf(wxS("%s"), m_str
.c_str());
834 void wxLogBuffer::DoLogTextAtLevel(wxLogLevel level
, const wxString
& msg
)
836 // don't put debug messages in the buffer, we don't want to show
837 // them to the user in a msg box, log them immediately
842 wxLog::DoLogTextAtLevel(level
, msg
);
846 m_str
<< msg
<< wxS("\n");
850 // ----------------------------------------------------------------------------
851 // wxLogStderr class implementation
852 // ----------------------------------------------------------------------------
854 wxLogStderr::wxLogStderr(FILE *fp
)
862 void wxLogStderr::DoLogText(const wxString
& msg
)
864 wxFputs(msg
+ '\n', m_fp
);
867 // under GUI systems such as Windows or Mac, programs usually don't have
868 // stderr at all, so show the messages also somewhere else, typically in
869 // the debugger window so that they go at least somewhere instead of being
871 if ( m_fp
== stderr
)
873 wxAppTraits
*traits
= wxTheApp
? wxTheApp
->GetTraits() : NULL
;
874 if ( traits
&& !traits
->HasStderr() )
876 wxMessageOutputDebug().Output(msg
+ wxS('\n'));
881 // ----------------------------------------------------------------------------
882 // wxLogStream implementation
883 // ----------------------------------------------------------------------------
885 #if wxUSE_STD_IOSTREAM
886 #include "wx/ioswrap.h"
887 wxLogStream::wxLogStream(wxSTD ostream
*ostr
)
890 m_ostr
= &wxSTD cerr
;
895 void wxLogStream::DoLogText(const wxString
& msg
)
897 (*m_ostr
) << msg
<< wxSTD endl
;
899 #endif // wxUSE_STD_IOSTREAM
901 // ----------------------------------------------------------------------------
903 // ----------------------------------------------------------------------------
905 wxLogChain::wxLogChain(wxLog
*logger
)
907 m_bPassMessages
= true;
910 m_logOld
= wxLog::SetActiveTarget(this);
913 wxLogChain::~wxLogChain()
915 wxLog::SetActiveTarget(m_logOld
);
917 if ( m_logNew
!= this )
921 void wxLogChain::SetLog(wxLog
*logger
)
923 if ( m_logNew
!= this )
929 void wxLogChain::Flush()
934 // be careful to avoid infinite recursion
935 if ( m_logNew
&& m_logNew
!= this )
939 void wxLogChain::DoLogRecord(wxLogLevel level
,
941 const wxLogRecordInfo
& info
)
943 // let the previous logger show it
944 if ( m_logOld
&& IsPassingMessages() )
945 m_logOld
->LogRecord(level
, msg
, info
);
947 // and also send it to the new one
950 // don't call m_logNew->LogRecord() to avoid infinite recursion when
951 // m_logNew is this object itself
952 if ( m_logNew
!= this )
953 m_logNew
->LogRecord(level
, msg
, info
);
955 wxLog::DoLogRecord(level
, msg
, info
);
960 // "'this' : used in base member initializer list" - so what?
961 #pragma warning(disable:4355)
964 // ----------------------------------------------------------------------------
966 // ----------------------------------------------------------------------------
968 wxLogInterposer::wxLogInterposer()
973 // ----------------------------------------------------------------------------
974 // wxLogInterposerTemp
975 // ----------------------------------------------------------------------------
977 wxLogInterposerTemp::wxLogInterposerTemp()
984 #pragma warning(default:4355)
987 // ============================================================================
988 // Global functions/variables
989 // ============================================================================
991 // ----------------------------------------------------------------------------
993 // ----------------------------------------------------------------------------
995 bool wxLog::ms_bRepetCounting
= false;
997 wxLog
*wxLog::ms_pLogger
= NULL
;
998 bool wxLog::ms_doLog
= true;
999 bool wxLog::ms_bAutoCreate
= true;
1000 bool wxLog::ms_bVerbose
= false;
1002 wxLogLevel
wxLog::ms_logLevel
= wxLOG_Max
; // log everything by default
1004 size_t wxLog::ms_suspendCount
= 0;
1006 wxString
wxLog::ms_timestamp(wxS("%X")); // time only, no date
1008 #if WXWIN_COMPATIBILITY_2_8
1009 wxTraceMask
wxLog::ms_ulTraceMask
= (wxTraceMask
)0;
1010 #endif // wxDEBUG_LEVEL
1012 // ----------------------------------------------------------------------------
1013 // stdout error logging helper
1014 // ----------------------------------------------------------------------------
1016 // helper function: wraps the message and justifies it under given position
1017 // (looks more pretty on the terminal). Also adds newline at the end.
1019 // TODO this is now disabled until I find a portable way of determining the
1020 // terminal window size (ok, I found it but does anybody really cares?)
1021 #ifdef LOG_PRETTY_WRAP
1022 static void wxLogWrap(FILE *f
, const char *pszPrefix
, const char *psz
)
1024 size_t nMax
= 80; // FIXME
1025 size_t nStart
= strlen(pszPrefix
);
1026 fputs(pszPrefix
, f
);
1029 while ( *psz
!= '\0' ) {
1030 for ( n
= nStart
; (n
< nMax
) && (*psz
!= '\0'); n
++ )
1034 if ( *psz
!= '\0' ) {
1036 for ( n
= 0; n
< nStart
; n
++ )
1039 // as we wrapped, squeeze all white space
1040 while ( isspace(*psz
) )
1047 #endif //LOG_PRETTY_WRAP
1049 // ----------------------------------------------------------------------------
1050 // error code/error message retrieval functions
1051 // ----------------------------------------------------------------------------
1053 // get error code from syste
1054 unsigned long wxSysErrorCode()
1056 #if defined(__WXMSW__) && !defined(__WXMICROWIN__)
1057 return ::GetLastError();
1063 // get error message from system
1064 const wxChar
*wxSysErrorMsg(unsigned long nErrCode
)
1066 if ( nErrCode
== 0 )
1067 nErrCode
= wxSysErrorCode();
1069 #if defined(__WXMSW__) && !defined(__WXMICROWIN__)
1070 static wxChar s_szBuf
[1024];
1072 // get error message from system
1074 if ( ::FormatMessage
1076 FORMAT_MESSAGE_ALLOCATE_BUFFER
| FORMAT_MESSAGE_FROM_SYSTEM
,
1079 MAKELANGID(LANG_NEUTRAL
, SUBLANG_DEFAULT
),
1085 // if this happens, something is seriously wrong, so don't use _() here
1087 wxSprintf(s_szBuf
, wxS("unknown error %lx"), nErrCode
);
1092 // copy it to our buffer and free memory
1093 // Crashes on SmartPhone (FIXME)
1094 #if !defined(__SMARTPHONE__) /* of WinCE */
1097 wxStrlcpy(s_szBuf
, (const wxChar
*)lpMsgBuf
, WXSIZEOF(s_szBuf
));
1099 LocalFree(lpMsgBuf
);
1101 // returned string is capitalized and ended with '\r\n' - bad
1102 s_szBuf
[0] = (wxChar
)wxTolower(s_szBuf
[0]);
1103 size_t len
= wxStrlen(s_szBuf
);
1106 if ( s_szBuf
[len
- 2] == wxS('\r') )
1107 s_szBuf
[len
- 2] = wxS('\0');
1111 #endif // !__SMARTPHONE__
1113 s_szBuf
[0] = wxS('\0');
1119 static wchar_t s_wzBuf
[1024];
1120 wxConvCurrent
->MB2WC(s_wzBuf
, strerror((int)nErrCode
),
1121 WXSIZEOF(s_wzBuf
) - 1);
1124 return strerror((int)nErrCode
);
1126 #endif // __WXMSW__/!__WXMSW__