2. wxLogTextCtrl doesn't use streams any more
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@3008
c3d73ce0-8a6f-49c7-b76d-
6d57e0e08775
// add string trace mask
static void RemoveTraceMask(const wxString& str);
// add string trace mask
static void RemoveTraceMask(const wxString& str);
+ // sets the timestamp string: this is used as strftime() format string
+ // for the log targets which add time stamps to the messages - set it
+ // to NULL to disable time stamping completely.
+ static void SetTimestamp(const wxChar *ts) { ms_timestamp = ts; }
+
// accessors
// gets the verbose status
bool GetVerbose() const { return m_bVerbose; }
// accessors
// gets the verbose status
bool GetVerbose() const { return m_bVerbose; }
static bool IsAllowedTraceMask(const wxChar *mask)
{ return ms_aTraceMasks.Index(mask) != wxNOT_FOUND; }
static bool IsAllowedTraceMask(const wxChar *mask)
{ return ms_aTraceMasks.Index(mask) != wxNOT_FOUND; }
+ // get the current timestamp format string (may be NULL)
+ static const wxChar *GetTimestamp() { return ms_timestamp; }
+
+ // helpers
+ // put the time stamp into the string if ms_timestamp != NULL (don't
+ // change it otherwise)
+ static void TimeStamp(wxString *str);
+
// make dtor virtual for all derived classes
virtual ~wxLog() { }
// make dtor virtual for all derived classes
virtual ~wxLog() { }
static bool ms_doLog; // FALSE => all logging disabled
static bool ms_bAutoCreate; // create new log targets on demand?
static bool ms_doLog; // FALSE => all logging disabled
static bool ms_bAutoCreate; // create new log targets on demand?
+ // format string for strftime(), if NULL, time stamping log messages is
+ // disabled
+ static const wxChar *ms_timestamp;
+
static wxTraceMask ms_ulTraceMask; // controls wxLogTrace behaviour
static wxArrayString ms_aTraceMasks; // more powerful filter for wxLogTrace
};
static wxTraceMask ms_ulTraceMask; // controls wxLogTrace behaviour
static wxArrayString ms_aTraceMasks; // more powerful filter for wxLogTrace
};
// log everything to a text window (GUI only of course)
// log everything to a text window (GUI only of course)
-class WXDLLEXPORT wxLogTextCtrl : public wxLogStream
+class WXDLLEXPORT wxLogTextCtrl : public wxLog
- // we just create an ostream from wxTextCtrl and use it in base class
wxLogTextCtrl(wxTextCtrl *pTextCtrl);
wxLogTextCtrl(wxTextCtrl *pTextCtrl);
+
+private:
+ // implement sink function
+ virtual void DoLogString(const wxChar *szString, time_t t);
+
+ // the control we use
+ wxTextCtrl *m_pTextCtrl;
// ----------------------------------------------------------------------------
// GUI log target, the default one for wxWindows programs
// ----------------------------------------------------------------------------
// GUI log target, the default one for wxWindows programs
+ if ( fclose(m_fp) != 0 )
{
wxLogSysError(_("can't close file '%s'"), m_name.c_str());
{
wxLogSysError(_("can't close file '%s'"), m_name.c_str());
ms_aTraceMasks.Remove((size_t)index);
}
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 ) {
void wxLog::DoLog(wxLogLevel level, const wxChar *szString, time_t t)
{
switch ( level ) {
void wxLogStderr::DoLogString(const wxChar *szString, time_t WXUNUSED(t))
{
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);
fputs(str.mb_str(), m_fp);
fflush(m_fp);
// wxLogTextCtrl implementation
// ----------------------------------------------------------------------------
// wxLogTextCtrl implementation
// ----------------------------------------------------------------------------
wxLogTextCtrl::wxLogTextCtrl(wxTextCtrl *pTextCtrl)
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)
+ wxString msg;
+ TimeStamp(&msg);
+ msg << szString << _T('\n');
+
+ m_pTextCtrl->AppendText(msg);
-#endif // wxUSE_STD_IOSTREAM
// ----------------------------------------------------------------------------
// wxLogGui implementation (FIXME MT-unsafe)
// ----------------------------------------------------------------------------
// wxLogGui implementation (FIXME MT-unsafe)
#ifdef __WXMSW__
// don't prepend debug/trace here: it goes to the
// debug window anyhow, but do put a timestamp
#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"),
#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);
pText->SetSelection(nLen, nLen);
#endif // Windows
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
}
// TODO ensure that the line can be seen
}
wxLog *wxLog::ms_pLogger = (wxLog *)NULL;
bool wxLog::ms_doLog = TRUE;
bool wxLog::ms_bAutoCreate = TRUE;
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;
wxTraceMask wxLog::ms_ulTraceMask = (wxTraceMask)0;
wxArrayString wxLog::ms_aTraceMasks;