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
218 // don't time stamp debug messages under MSW as debug viewers usually
219 // already have an option to do it
221 if ( level
!= wxLOG_Debug
&& level
!= wxLOG_Trace
)
223 prefix
= FormatTime(info
.timestamp
);
228 prefix
+= _("Error: ");
232 prefix
+= _("Warning: ");
235 // don't prepend "debug/trace" prefix under MSW as it goes to the debug
236 // window anyhow and so can't be confused with something else
239 // this prefix (as well as the one below) is intentionally not
240 // translated as nobody translates debug messages anyhow
254 wxLogFormatter::FormatTime(time_t t
) const
257 wxLog::TimeStamp(&str
, t
);
263 // ----------------------------------------------------------------------------
264 // wxLog class implementation
265 // ----------------------------------------------------------------------------
267 unsigned wxLog::LogLastRepeatIfNeeded()
269 const unsigned count
= gs_prevLog
.numRepeated
;
271 if ( gs_prevLog
.numRepeated
)
275 if ( gs_prevLog
.numRepeated
== 1 )
277 // We use a separate message for this case as "repeated 1 time"
278 // looks somewhat strange.
279 msg
= _("The previous message repeated once.");
283 // Notice that we still use wxPLURAL() to ensure that multiple
284 // numbers of times are correctly formatted, even though we never
285 // actually use the singular string.
286 msg
.Printf(wxPLURAL("The previous message repeated %lu time.",
287 "The previous message repeated %lu times.",
288 gs_prevLog
.numRepeated
),
289 gs_prevLog
.numRepeated
);
292 msg
.Printf(wxS("The previous message was repeated %lu time(s)."),
293 gs_prevLog
.numRepeated
);
295 gs_prevLog
.numRepeated
= 0;
296 gs_prevLog
.msg
.clear();
297 DoLogRecord(gs_prevLog
.level
, msg
, gs_prevLog
.info
);
305 // Flush() must be called before destroying the object as otherwise some
306 // messages could be lost
307 if ( gs_prevLog
.numRepeated
)
309 wxMessageOutputDebug().Printf
314 "Last repeated message (\"%s\", %lu time) wasn't output",
315 "Last repeated message (\"%s\", %lu times) wasn't output",
316 gs_prevLog
.numRepeated
319 wxS("Last repeated message (\"%s\", %lu time(s)) wasn't output"),
322 gs_prevLog
.numRepeated
329 // ----------------------------------------------------------------------------
330 // wxLog logging functions
331 // ----------------------------------------------------------------------------
335 wxLog::OnLog(wxLogLevel level
, const wxString
& msg
, time_t t
)
337 wxLogRecordInfo info
;
340 info
.threadId
= wxThread::GetCurrentId();
341 #endif // wxUSE_THREADS
343 OnLog(level
, msg
, info
);
348 wxLog::OnLog(wxLogLevel level
,
350 const wxLogRecordInfo
& info
)
352 // fatal errors can't be suppressed nor handled by the custom log target
353 // and always terminate the program
354 if ( level
== wxLOG_FatalError
)
356 wxSafeShowMessage(wxS("Fatal Error"), msg
);
368 if ( !wxThread::IsMain() )
370 logger
= wxThreadInfo
.logger
;
375 // buffer the messages until they can be shown from the main
377 wxCriticalSectionLocker
lock(GetBackgroundLogCS());
379 gs_bufferedLogRecords
.push_back(wxLogRecord(level
, msg
, info
));
381 // ensure that our Flush() will be called soon
384 //else: we don't have any logger at all, there is no need to log
389 //else: we have a thread-specific logger, we can send messages to it
393 #endif // wxUSE_THREADS
395 logger
= GetMainThreadActiveTarget();
400 logger
->CallDoLogNow(level
, msg
, info
);
404 wxLog::CallDoLogNow(wxLogLevel level
,
406 const wxLogRecordInfo
& info
)
408 if ( GetRepetitionCounting() )
410 if ( msg
== gs_prevLog
.msg
)
412 gs_prevLog
.numRepeated
++;
414 // nothing else to do, in particular, don't log the
419 LogLastRepeatIfNeeded();
421 // reset repetition counter for a new message
422 gs_prevLog
.msg
= msg
;
423 gs_prevLog
.level
= level
;
424 gs_prevLog
.info
= info
;
427 // handle extra data which may be passed to us by wxLogXXX()
428 wxString prefix
, suffix
;
430 if ( info
.GetNumValue(wxLOG_KEY_SYS_ERROR_CODE
, &num
) )
432 const long err
= static_cast<long>(num
);
434 suffix
.Printf(_(" (error %ld: %s)"), err
, wxSysErrorMsg(err
));
439 if ( level
== wxLOG_Trace
&& info
.GetStrValue(wxLOG_KEY_TRACE_MASK
, &str
) )
441 prefix
= "(" + str
+ ") ";
443 #endif // wxUSE_LOG_TRACE
445 DoLogRecord(level
, prefix
+ msg
+ suffix
, info
);
448 void wxLog::DoLogRecord(wxLogLevel level
,
450 const wxLogRecordInfo
& info
)
452 #if WXWIN_COMPATIBILITY_2_8
453 // call the old DoLog() to ensure that existing custom log classes still
456 // as the user code could have defined it as either taking "const char *"
457 // (in ANSI build) or "const wxChar *" (in ANSI/Unicode), we have no choice
458 // but to call both of them
459 DoLog(level
, (const char*)msg
.mb_str(), info
.timestamp
);
460 DoLog(level
, (const wchar_t*)msg
.wc_str(), info
.timestamp
);
461 #else // !WXWIN_COMPATIBILITY_2_8
463 #endif // WXWIN_COMPATIBILITY_2_8/!WXWIN_COMPATIBILITY_2_8
465 // Use wxLogFormatter to format the message
466 DoLogTextAtLevel(level
, m_formatter
->Format (level
, msg
, info
));
469 void wxLog::DoLogTextAtLevel(wxLogLevel level
, const wxString
& msg
)
471 // we know about debug messages (because using wxMessageOutputDebug is the
472 // right thing to do in 99% of all cases and also for compatibility) but
473 // anything else needs to be handled in the derived class
474 if ( level
== wxLOG_Debug
|| level
== wxLOG_Trace
)
476 wxMessageOutputDebug().Output(msg
+ wxS('\n'));
484 void wxLog::DoLogText(const wxString
& WXUNUSED(msg
))
486 // in 2.8-compatible build the derived class might override DoLog() or
487 // DoLogString() instead so we can't have this assert there
488 #if !WXWIN_COMPATIBILITY_2_8
489 wxFAIL_MSG( "must be overridden if it is called" );
490 #endif // WXWIN_COMPATIBILITY_2_8
493 #if WXWIN_COMPATIBILITY_2_8
495 void wxLog::DoLog(wxLogLevel
WXUNUSED(level
), const char *szString
, time_t t
)
497 DoLogString(szString
, t
);
500 void wxLog::DoLog(wxLogLevel
WXUNUSED(level
), const wchar_t *wzString
, time_t t
)
502 DoLogString(wzString
, t
);
505 #endif // WXWIN_COMPATIBILITY_2_8
507 // ----------------------------------------------------------------------------
508 // wxLog active target management
509 // ----------------------------------------------------------------------------
511 wxLog
*wxLog::GetActiveTarget()
514 if ( !wxThread::IsMain() )
516 // check if we have a thread-specific log target
517 wxLog
* const logger
= wxThreadInfo
.logger
;
519 // the code below should be only executed for the main thread as
520 // CreateLogTarget() is not meant for auto-creating log targets for
521 // worker threads so skip it in any case
522 return logger
? logger
: ms_pLogger
;
524 #endif // wxUSE_THREADS
526 return GetMainThreadActiveTarget();
530 wxLog
*wxLog::GetMainThreadActiveTarget()
532 if ( ms_bAutoCreate
&& ms_pLogger
== NULL
) {
533 // prevent infinite recursion if someone calls wxLogXXX() from
534 // wxApp::CreateLogTarget()
535 static bool s_bInGetActiveTarget
= false;
536 if ( !s_bInGetActiveTarget
) {
537 s_bInGetActiveTarget
= true;
539 // ask the application to create a log target for us
540 if ( wxTheApp
!= NULL
)
541 ms_pLogger
= wxTheApp
->GetTraits()->CreateLogTarget();
543 ms_pLogger
= new wxLogOutputBest
;
545 s_bInGetActiveTarget
= false;
547 // do nothing if it fails - what can we do?
554 wxLog
*wxLog::SetActiveTarget(wxLog
*pLogger
)
556 if ( ms_pLogger
!= NULL
) {
557 // flush the old messages before changing because otherwise they might
558 // get lost later if this target is not restored
562 wxLog
*pOldLogger
= ms_pLogger
;
563 ms_pLogger
= pLogger
;
570 wxLog
*wxLog::SetThreadActiveTarget(wxLog
*logger
)
572 wxASSERT_MSG( !wxThread::IsMain(), "use SetActiveTarget() for main thread" );
574 wxLog
* const oldLogger
= wxThreadInfo
.logger
;
578 wxThreadInfo
.logger
= logger
;
582 #endif // wxUSE_THREADS
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 // ----------------------------------------------------------------------------
600 // wxLog components levels
601 // ----------------------------------------------------------------------------
604 void wxLog::SetComponentLevel(const wxString
& component
, wxLogLevel level
)
606 if ( component
.empty() )
612 wxCRIT_SECT_LOCKER(lock
, GetLevelsCS());
614 GetComponentLevels()[component
] = level
;
619 wxLogLevel
wxLog::GetComponentLevel(wxString component
)
621 wxCRIT_SECT_LOCKER(lock
, GetLevelsCS());
623 const wxStringToNumHashMap
& componentLevels
= GetComponentLevels();
624 while ( !component
.empty() )
626 wxStringToNumHashMap::const_iterator
627 it
= componentLevels
.find(component
);
628 if ( it
!= componentLevels
.end() )
629 return static_cast<wxLogLevel
>(it
->second
);
631 component
= component
.BeforeLast('/');
634 return GetLogLevel();
637 // ----------------------------------------------------------------------------
639 // ----------------------------------------------------------------------------
644 // because IsAllowedTraceMask() may be called during static initialization
645 // (this is not recommended but it may still happen, see #11592) we can't use a
646 // simple static variable which might be not initialized itself just yet to
647 // store the trace masks, but need this accessor function which will ensure
648 // that the variable is always correctly initialized before being accessed
650 // notice that this doesn't make accessing it MT-safe, of course, you need to
651 // serialize accesses to it using GetTraceMaskCS() for this
652 wxArrayString
& TraceMasks()
654 static wxArrayString s_traceMasks
;
659 } // anonymous namespace
661 /* static */ const wxArrayString
& wxLog::GetTraceMasks()
663 // because of this function signature (it returns a reference, not the
664 // object), it is inherently MT-unsafe so there is no need to acquire the
670 void wxLog::AddTraceMask(const wxString
& str
)
672 wxCRIT_SECT_LOCKER(lock
, GetTraceMaskCS());
674 TraceMasks().push_back(str
);
677 void wxLog::RemoveTraceMask(const wxString
& str
)
679 wxCRIT_SECT_LOCKER(lock
, GetTraceMaskCS());
681 int index
= TraceMasks().Index(str
);
682 if ( index
!= wxNOT_FOUND
)
683 TraceMasks().RemoveAt((size_t)index
);
686 void wxLog::ClearTraceMasks()
688 wxCRIT_SECT_LOCKER(lock
, GetTraceMaskCS());
690 TraceMasks().Clear();
693 /*static*/ bool wxLog::IsAllowedTraceMask(const wxString
& mask
)
695 wxCRIT_SECT_LOCKER(lock
, GetTraceMaskCS());
697 const wxArrayString
& masks
= GetTraceMasks();
698 for ( wxArrayString::const_iterator it
= masks
.begin(),
710 // ----------------------------------------------------------------------------
711 // wxLog miscellaneous other methods
712 // ----------------------------------------------------------------------------
716 void wxLog::TimeStamp(wxString
*str
)
718 if ( !ms_timestamp
.empty() )
720 *str
= wxDateTime::UNow().Format(ms_timestamp
);
725 void wxLog::TimeStamp(wxString
*str
, time_t t
)
727 if ( !ms_timestamp
.empty() )
729 *str
= wxDateTime(t
).Format(ms_timestamp
);
734 #else // !wxUSE_DATETIME
736 void wxLog::TimeStamp(wxString
*)
740 void wxLog::TimeStamp(wxString
*, time_t)
744 #endif // wxUSE_DATETIME/!wxUSE_DATETIME
748 void wxLog::FlushThreadMessages()
750 // check if we have queued messages from other threads
751 wxLogRecords bufferedLogRecords
;
754 wxCriticalSectionLocker
lock(GetBackgroundLogCS());
755 bufferedLogRecords
.swap(gs_bufferedLogRecords
);
757 // release the lock now to not keep it while we are logging the
758 // messages below, allowing background threads to run
761 if ( !bufferedLogRecords
.empty() )
763 for ( wxLogRecords::const_iterator it
= bufferedLogRecords
.begin();
764 it
!= bufferedLogRecords
.end();
767 CallDoLogNow(it
->level
, it
->msg
, it
->info
);
773 bool wxLog::IsThreadLoggingEnabled()
775 return !wxThreadInfo
.loggingDisabled
;
779 bool wxLog::EnableThreadLogging(bool enable
)
781 const bool wasEnabled
= !wxThreadInfo
.loggingDisabled
;
782 wxThreadInfo
.loggingDisabled
= !enable
;
786 #endif // wxUSE_THREADS
788 wxLogFormatter
*wxLog::SetFormatter(wxLogFormatter
* formatter
)
790 wxLogFormatter
* formatterOld
= m_formatter
;
791 m_formatter
= formatter
? formatter
: new wxLogFormatter
;
798 LogLastRepeatIfNeeded();
802 void wxLog::FlushActive()
804 if ( ms_suspendCount
)
807 wxLog
* const log
= GetActiveTarget();
811 if ( wxThread::IsMain() )
812 log
->FlushThreadMessages();
813 #endif // wxUSE_THREADS
819 // ----------------------------------------------------------------------------
820 // wxLogBuffer implementation
821 // ----------------------------------------------------------------------------
823 void wxLogBuffer::Flush()
827 if ( !m_str
.empty() )
829 wxMessageOutputBest out
;
830 out
.Printf(wxS("%s"), m_str
.c_str());
835 void wxLogBuffer::DoLogTextAtLevel(wxLogLevel level
, const wxString
& msg
)
837 // don't put debug messages in the buffer, we don't want to show
838 // them to the user in a msg box, log them immediately
843 wxLog::DoLogTextAtLevel(level
, msg
);
847 m_str
<< msg
<< wxS("\n");
851 // ----------------------------------------------------------------------------
852 // wxLogStderr class implementation
853 // ----------------------------------------------------------------------------
855 wxLogStderr::wxLogStderr(FILE *fp
)
863 void wxLogStderr::DoLogText(const wxString
& msg
)
865 wxFputs(msg
+ '\n', m_fp
);
868 // under GUI systems such as Windows or Mac, programs usually don't have
869 // stderr at all, so show the messages also somewhere else, typically in
870 // the debugger window so that they go at least somewhere instead of being
872 if ( m_fp
== stderr
)
874 wxAppTraits
*traits
= wxTheApp
? wxTheApp
->GetTraits() : NULL
;
875 if ( traits
&& !traits
->HasStderr() )
877 wxMessageOutputDebug().Output(msg
+ wxS('\n'));
882 // ----------------------------------------------------------------------------
883 // wxLogStream implementation
884 // ----------------------------------------------------------------------------
886 #if wxUSE_STD_IOSTREAM
887 #include "wx/ioswrap.h"
888 wxLogStream::wxLogStream(wxSTD ostream
*ostr
)
891 m_ostr
= &wxSTD cerr
;
896 void wxLogStream::DoLogText(const wxString
& msg
)
898 (*m_ostr
) << msg
<< wxSTD endl
;
900 #endif // wxUSE_STD_IOSTREAM
902 // ----------------------------------------------------------------------------
904 // ----------------------------------------------------------------------------
906 wxLogChain::wxLogChain(wxLog
*logger
)
908 m_bPassMessages
= true;
911 m_logOld
= wxLog::SetActiveTarget(this);
914 wxLogChain::~wxLogChain()
916 wxLog::SetActiveTarget(m_logOld
);
918 if ( m_logNew
!= this )
922 void wxLogChain::SetLog(wxLog
*logger
)
924 if ( m_logNew
!= this )
930 void wxLogChain::Flush()
935 // be careful to avoid infinite recursion
936 if ( m_logNew
&& m_logNew
!= this )
940 void wxLogChain::DoLogRecord(wxLogLevel level
,
942 const wxLogRecordInfo
& info
)
944 // let the previous logger show it
945 if ( m_logOld
&& IsPassingMessages() )
946 m_logOld
->LogRecord(level
, msg
, info
);
948 // and also send it to the new one
951 // don't call m_logNew->LogRecord() to avoid infinite recursion when
952 // m_logNew is this object itself
953 if ( m_logNew
!= this )
954 m_logNew
->LogRecord(level
, msg
, info
);
956 wxLog::DoLogRecord(level
, msg
, info
);
961 // "'this' : used in base member initializer list" - so what?
962 #pragma warning(disable:4355)
965 // ----------------------------------------------------------------------------
967 // ----------------------------------------------------------------------------
969 wxLogInterposer::wxLogInterposer()
974 // ----------------------------------------------------------------------------
975 // wxLogInterposerTemp
976 // ----------------------------------------------------------------------------
978 wxLogInterposerTemp::wxLogInterposerTemp()
985 #pragma warning(default:4355)
988 // ============================================================================
989 // Global functions/variables
990 // ============================================================================
992 // ----------------------------------------------------------------------------
994 // ----------------------------------------------------------------------------
996 bool wxLog::ms_bRepetCounting
= false;
998 wxLog
*wxLog::ms_pLogger
= NULL
;
999 bool wxLog::ms_doLog
= true;
1000 bool wxLog::ms_bAutoCreate
= true;
1001 bool wxLog::ms_bVerbose
= false;
1003 wxLogLevel
wxLog::ms_logLevel
= wxLOG_Max
; // log everything by default
1005 size_t wxLog::ms_suspendCount
= 0;
1007 wxString
wxLog::ms_timestamp(wxS("%X")); // time only, no date
1009 #if WXWIN_COMPATIBILITY_2_8
1010 wxTraceMask
wxLog::ms_ulTraceMask
= (wxTraceMask
)0;
1011 #endif // wxDEBUG_LEVEL
1013 // ----------------------------------------------------------------------------
1014 // stdout error logging helper
1015 // ----------------------------------------------------------------------------
1017 // helper function: wraps the message and justifies it under given position
1018 // (looks more pretty on the terminal). Also adds newline at the end.
1020 // TODO this is now disabled until I find a portable way of determining the
1021 // terminal window size (ok, I found it but does anybody really cares?)
1022 #ifdef LOG_PRETTY_WRAP
1023 static void wxLogWrap(FILE *f
, const char *pszPrefix
, const char *psz
)
1025 size_t nMax
= 80; // FIXME
1026 size_t nStart
= strlen(pszPrefix
);
1027 fputs(pszPrefix
, f
);
1030 while ( *psz
!= '\0' ) {
1031 for ( n
= nStart
; (n
< nMax
) && (*psz
!= '\0'); n
++ )
1035 if ( *psz
!= '\0' ) {
1037 for ( n
= 0; n
< nStart
; n
++ )
1040 // as we wrapped, squeeze all white space
1041 while ( isspace(*psz
) )
1048 #endif //LOG_PRETTY_WRAP
1050 // ----------------------------------------------------------------------------
1051 // error code/error message retrieval functions
1052 // ----------------------------------------------------------------------------
1054 // get error code from syste
1055 unsigned long wxSysErrorCode()
1057 #if defined(__WXMSW__) && !defined(__WXMICROWIN__)
1058 return ::GetLastError();
1064 // get error message from system
1065 const wxChar
*wxSysErrorMsg(unsigned long nErrCode
)
1067 if ( nErrCode
== 0 )
1068 nErrCode
= wxSysErrorCode();
1070 #if defined(__WXMSW__) && !defined(__WXMICROWIN__)
1071 static wxChar s_szBuf
[1024];
1073 // get error message from system
1075 if ( ::FormatMessage
1077 FORMAT_MESSAGE_ALLOCATE_BUFFER
| FORMAT_MESSAGE_FROM_SYSTEM
,
1080 MAKELANGID(LANG_NEUTRAL
, SUBLANG_DEFAULT
),
1086 // if this happens, something is seriously wrong, so don't use _() here
1088 wxSprintf(s_szBuf
, wxS("unknown error %lx"), nErrCode
);
1093 // copy it to our buffer and free memory
1094 // Crashes on SmartPhone (FIXME)
1095 #if !defined(__SMARTPHONE__) /* of WinCE */
1098 wxStrlcpy(s_szBuf
, (const wxChar
*)lpMsgBuf
, WXSIZEOF(s_szBuf
));
1100 LocalFree(lpMsgBuf
);
1102 // returned string is capitalized and ended with '\r\n' - bad
1103 s_szBuf
[0] = (wxChar
)wxTolower(s_szBuf
[0]);
1104 size_t len
= wxStrlen(s_szBuf
);
1107 if ( s_szBuf
[len
- 2] == wxS('\r') )
1108 s_szBuf
[len
- 2] = wxS('\0');
1112 #endif // !__SMARTPHONE__
1114 s_szBuf
[0] = wxS('\0');
1120 static wchar_t s_wzBuf
[1024];
1121 wxConvCurrent
->MB2WC(s_wzBuf
, strerror((int)nErrCode
),
1122 WXSIZEOF(s_wzBuf
) - 1);
1125 return strerror((int)nErrCode
);
1127 #endif // __WXMSW__/!__WXMSW__