X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/dbf3cd7a2b2774d48eeba02b164714653c6a02cd..1d37e644007e676b82e75426daa1d5118bb76780:/src/common/log.cpp diff --git a/src/common/log.cpp b/src/common/log.cpp index 2f8b2c0a0a..b71af7bd54 100644 --- a/src/common/log.cpp +++ b/src/common/log.cpp @@ -315,6 +315,20 @@ void wxLog::RemoveTraceMask(const wxString& str) ms_aTraceMasks.Remove((size_t)index); } +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 << _T(": "); + } +} + void wxLog::DoLog(wxLogLevel level, const wxChar *szString, time_t t) { switch ( level ) { @@ -377,8 +391,9 @@ wxLogStderr::wxLogStderr(FILE *fp) void wxLogStderr::DoLogString(const wxChar *szString, time_t WXUNUSED(t)) { - wxString str(szString); - str << _T('\n'); + wxString str; + TimeStamp(&str); + str << szString << _T('\n'); fputs(str.mb_str(), m_fp); fflush(m_fp); @@ -405,7 +420,7 @@ wxLogStream::wxLogStream(ostream *ostr) void wxLogStream::DoLogString(const wxChar *szString, time_t WXUNUSED(t)) { - (*m_ostr) << wxConv_libc.cWX2MB(szString) << endl << flush; + (*m_ostr) << wxConvCurrent->cWX2MB(szString) << endl << flush; } #endif // wxUSE_STD_IOSTREAM @@ -415,19 +430,19 @@ void wxLogStream::DoLogString(const wxChar *szString, time_t WXUNUSED(t)) // wxLogTextCtrl implementation // ---------------------------------------------------------------------------- -#if wxUSE_STD_IOSTREAM wxLogTextCtrl::wxLogTextCtrl(wxTextCtrl *pTextCtrl) -#if !defined(NO_TEXT_WINDOW_STREAM) -: wxLogStream(new ostream(pTextCtrl)) -#endif { + m_pTextCtrl = pTextCtrl; } -wxLogTextCtrl::~wxLogTextCtrl() +void wxLogTextCtrl::DoLogString(const wxChar *szString, time_t t) { - delete m_ostr; + wxString msg; + TimeStamp(&msg); + msg << szString << _T('\n'); + + m_pTextCtrl->AppendText(msg); } -#endif // wxUSE_STD_IOSTREAM // ---------------------------------------------------------------------------- // wxLogGui implementation (FIXME MT-unsafe) @@ -533,12 +548,16 @@ void wxLogGui::DoLog(wxLogLevel level, const wxChar *szString, time_t t) #ifdef __WXMSW__ // don't prepend debug/trace here: it goes to the // debug window anyhow, but do put a timestamp - OutputDebugString(wxString(szString) + _T("\n\r")); + wxString str; + TimeStamp(&str); + str << szString << _T("\n\r"); + OutputDebugString(str); #else // send them to stderr wxFprintf(stderr, _T("%s: %s\n"), - level == wxLOG_Trace ? _T("Trace") : _T("Debug"), - szString); + level == wxLOG_Trace ? _T("Trace") + : _T("Debug"), + szString); fflush(stderr); #endif } @@ -832,8 +851,11 @@ void wxLogWindow::DoLogString(const wxChar *szString, time_t WXUNUSED(t)) pText->SetSelection(nLen, nLen); #endif // Windows - pText->WriteText(szString); - pText->WriteText(_T("\n")); // "\n" ok here (_not_ "\r\n") + wxString msg; + TimeStamp(&msg); + msg << szString << _T('\n'); + + pText->AppendText(msg); // TODO ensure that the line can be seen } @@ -873,6 +895,9 @@ wxLogWindow::~wxLogWindow() wxLog *wxLog::ms_pLogger = (wxLog *)NULL; bool wxLog::ms_doLog = TRUE; bool wxLog::ms_bAutoCreate = TRUE; + +const wxChar *wxLog::ms_timestamp = "%X"; // time only, no date + wxTraceMask wxLog::ms_ulTraceMask = (wxTraceMask)0; wxArrayString wxLog::ms_aTraceMasks; @@ -972,7 +997,7 @@ const wxChar *wxSysErrorMsg(unsigned long nErrCode) #else // Unix #if wxUSE_UNICODE static wxChar s_szBuf[LOG_BUFFER_SIZE / 2]; - wxConv_libc.MB2WC(s_szBuf, strerror(nErrCode), WXSIZEOF(s_szBuf) -1); + wxConvCurrent->MB2WC(s_szBuf, strerror(nErrCode), WXSIZEOF(s_szBuf) -1); return s_szBuf; #else return strerror(nErrCode);