-{
- // flush the old messages before changing
- if ( ms_pLogger != NULL )
- ms_pLogger->Flush();
-
- ms_bInitialized = TRUE;
-
- wxLog *pOldLogger = ms_pLogger;
- ms_pLogger = pLogger;
- return pOldLogger;
-}
-
-void wxLog::DoLog(Level level, const char *szString)
-{
- char szBuf[128];
- time_t timeNow;
- struct tm *ptmNow;
-
- time(&timeNow);
- ptmNow = localtime(&timeNow);
-
- strftime(szBuf, WXSIZEOF(szBuf), ms_szTimeFormat, ptmNow);
- wxString str = szBuf;
-
- switch ( level ) {
- case FatalError:
- DoLogString(str << _("Fatal error: ") << szString);
- DoLogString(_("Program aborted."));
- Flush();
- abort();
- break;
-
- case Error:
- DoLogString(str << _("Error: ") << szString);
- break;
-
- case Warning:
- DoLogString(str << _("Warning: ") << szString);
- break;
-
- case Info:
- if ( GetVerbose() )
- case Message:
- DoLogString(str + szString);
- // fall through
-
- case Status:
- // nothing to do
- break;
-
- case Trace:
- case Debug:
- #ifdef __DEBUG__
- #ifdef __WIN32__
- // in addition to normal logging, also send the string to debugger
- // (don't prepend "Debug" here: it will go to debug window anyhow)
- ::OutputDebugString(str + szString + "\n\r");
- #endif //Win32
- DoLogString(str << (level == Trace ? _("Trace") : _("Debug"))
- << ": " << szString);
- #endif
-
- break;
-
- default:
- wxFAIL_MSG("unknown log level in wxLog::DoLog");
- }
+{
+ if ( ms_pLogger != NULL ) {
+ // flush the old messages before changing because otherwise they might
+ // get lost later if this target is not restored
+ ms_pLogger->Flush();
+ }
+
+ wxLog *pOldLogger = ms_pLogger;
+ ms_pLogger = pLogger;
+
+ return pOldLogger;
+}
+
+void wxLog::DontCreateOnDemand()
+{
+ ms_bAutoCreate = false;
+
+ // this is usually called at the end of the program and we assume that it
+ // is *always* called at the end - so we free memory here to avoid false
+ // memory leak reports from wxWin memory tracking code
+ ClearTraceMasks();
+}
+
+void wxLog::RemoveTraceMask(const wxString& str)
+{
+ int index = ms_aTraceMasks.Index(str);
+ if ( index != wxNOT_FOUND )
+ ms_aTraceMasks.RemoveAt((size_t)index);
+}
+
+void wxLog::ClearTraceMasks()
+{
+ ms_aTraceMasks.Clear();
+}
+
+void wxLog::TimeStamp(wxString *str)
+{
+ if ( ms_timestamp )
+ {
+ wxChar buf[256];
+ time_t timeNow;
+ (void)time(&timeNow);
+ wxStrftime(buf, WXSIZEOF(buf), ms_timestamp, localtime(&timeNow));
+
+ str->Empty();
+ *str << buf << wxT(": ");
+ }
+}
+
+void wxLog::DoLog(wxLogLevel level, const wxChar *szString, time_t t)
+{
+ switch ( level ) {
+ case wxLOG_FatalError:
+ DoLogString(wxString(_("Fatal error: ")) + szString, t);
+ DoLogString(_("Program aborted."), t);
+ Flush();
+#ifdef __WXWINCE__
+ ExitThread(3);
+#else
+ abort();
+#endif
+ break;
+
+ case wxLOG_Error:
+ DoLogString(wxString(_("Error: ")) + szString, t);
+ break;
+
+ case wxLOG_Warning:
+ DoLogString(wxString(_("Warning: ")) + szString, t);
+ break;
+
+ case wxLOG_Info:
+ if ( GetVerbose() )
+ case wxLOG_Message:
+ case wxLOG_Status:
+ default: // log unknown log levels too
+ DoLogString(szString, t);
+ break;
+
+ case wxLOG_Trace:
+ case wxLOG_Debug:
+#ifdef __WXDEBUG__
+ {
+ wxString msg = level == wxLOG_Trace ? wxT("Trace: ")
+ : wxT("Debug: ");
+ msg << szString;
+ DoLogString(msg, t);
+ }
+#endif // Debug
+ break;
+ }