Changed wxLog DoLogXXX() callbacks and introduced wxLogRecordInfo.
The main logging callback is now DoLogRecord() with DoLogTextAtLevel() and DoLogText() provided for convenience. The old DoLog() and DoLogString() are still called but deprecated and their overloads taking wxString which were only added in 2.9.0 are removed. wxLogRecordInfo allows associating more information than just the time stamp with the log record; for now only the logging thread id was added but more fields will make their appearance soon. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@61346 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -21,15 +21,18 @@
|
||||
#include "wx/log.h"
|
||||
#endif // WX_PRECOMP
|
||||
|
||||
#include "wx/scopeguard.h"
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// test logger
|
||||
// test loggers
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
// simple log sink which just stores the messages logged for each level
|
||||
class TestLog : public wxLog
|
||||
// base class for all test loggers which simply store all logged messages for
|
||||
// future examination in the test code
|
||||
class TestLogBase : public wxLog
|
||||
{
|
||||
public:
|
||||
TestLog() { }
|
||||
TestLogBase() { }
|
||||
|
||||
wxString GetLog(wxLogLevel level) const
|
||||
{
|
||||
@@ -43,19 +46,83 @@ public:
|
||||
}
|
||||
|
||||
protected:
|
||||
virtual void DoLog(wxLogLevel level, const wxString& str, time_t WXUNUSED(t))
|
||||
wxString m_logs[wxLOG_Trace + 1];
|
||||
|
||||
wxDECLARE_NO_COPY_CLASS(TestLogBase);
|
||||
};
|
||||
|
||||
// simple log sink which just stores the messages logged for each level
|
||||
class TestLog : public TestLogBase
|
||||
{
|
||||
public:
|
||||
TestLog() { }
|
||||
|
||||
protected:
|
||||
virtual void DoLogRecord(wxLogLevel level,
|
||||
const wxString& msg,
|
||||
const wxLogRecordInfo& WXUNUSED(info))
|
||||
{
|
||||
m_logs[level] = msg;
|
||||
}
|
||||
|
||||
private:
|
||||
wxDECLARE_NO_COPY_CLASS(TestLog);
|
||||
};
|
||||
|
||||
#if WXWIN_COMPATIBILITY_2_8
|
||||
|
||||
// log sink overriding the old DoLogXXX() functions should still work too
|
||||
|
||||
// this one overrides DoLog(char*)
|
||||
class CompatTestLog : public TestLogBase
|
||||
{
|
||||
public:
|
||||
CompatTestLog() { }
|
||||
|
||||
protected:
|
||||
virtual void DoLog(wxLogLevel level, const char *str, time_t WXUNUSED(t))
|
||||
{
|
||||
m_logs[level] = str;
|
||||
}
|
||||
|
||||
wxSUPPRESS_DOLOG_HIDE_WARNING()
|
||||
// get rid of the warning about hiding the other overload
|
||||
virtual void DoLog(wxLogLevel WXUNUSED(level),
|
||||
const wchar_t *WXUNUSED(str),
|
||||
time_t WXUNUSED(t))
|
||||
{
|
||||
}
|
||||
|
||||
private:
|
||||
wxString m_logs[wxLOG_Trace + 1];
|
||||
|
||||
wxDECLARE_NO_COPY_CLASS(TestLog);
|
||||
wxDECLARE_NO_COPY_CLASS(CompatTestLog);
|
||||
};
|
||||
|
||||
// and this one overload DoLogString(wchar_t*)
|
||||
class CompatTestLog2 : public wxLog
|
||||
{
|
||||
public:
|
||||
CompatTestLog2() { }
|
||||
|
||||
const wxString& Get() const { return m_msg; }
|
||||
|
||||
protected:
|
||||
virtual void DoLogString(const wchar_t *msg, time_t WXUNUSED(t))
|
||||
{
|
||||
m_msg = msg;
|
||||
}
|
||||
|
||||
// get rid of the warning
|
||||
virtual void DoLogString(const char *WXUNUSED(msg), time_t WXUNUSED(t))
|
||||
{
|
||||
}
|
||||
|
||||
private:
|
||||
wxString m_msg;
|
||||
|
||||
wxDECLARE_NO_COPY_CLASS(CompatTestLog2);
|
||||
};
|
||||
|
||||
#endif // WXWIN_COMPATIBILITY_2_8
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// test class
|
||||
// ----------------------------------------------------------------------------
|
||||
@@ -75,6 +142,10 @@ private:
|
||||
#if wxDEBUG_LEVEL
|
||||
CPPUNIT_TEST( Trace );
|
||||
#endif // wxDEBUG_LEVEL
|
||||
#if WXWIN_COMPATIBILITY_2_8
|
||||
CPPUNIT_TEST( CompatLogger );
|
||||
CPPUNIT_TEST( CompatLogger2 );
|
||||
#endif // WXWIN_COMPATIBILITY_2_8
|
||||
CPPUNIT_TEST_SUITE_END();
|
||||
|
||||
void Functions();
|
||||
@@ -82,6 +153,10 @@ private:
|
||||
#if wxDEBUG_LEVEL
|
||||
void Trace();
|
||||
#endif // wxDEBUG_LEVEL
|
||||
#if WXWIN_COMPATIBILITY_2_8
|
||||
void CompatLogger();
|
||||
void CompatLogger2();
|
||||
#endif // WXWIN_COMPATIBILITY_2_8
|
||||
|
||||
TestLog *m_log;
|
||||
wxLog *m_logOld;
|
||||
@@ -159,3 +234,27 @@ void LogTestCase::Trace()
|
||||
}
|
||||
|
||||
#endif // wxDEBUG_LEVEL
|
||||
|
||||
#if WXWIN_COMPATIBILITY_2_8
|
||||
|
||||
void LogTestCase::CompatLogger()
|
||||
{
|
||||
CompatTestLog log;
|
||||
wxLog * const logOld = wxLog::SetActiveTarget(&log);
|
||||
wxON_BLOCK_EXIT1( wxLog::SetActiveTarget, logOld );
|
||||
|
||||
wxLogError("Old error");
|
||||
CPPUNIT_ASSERT_EQUAL( "Old error", log.GetLog(wxLOG_Error) );
|
||||
}
|
||||
|
||||
void LogTestCase::CompatLogger2()
|
||||
{
|
||||
CompatTestLog2 log;
|
||||
wxLog * const logOld = wxLog::SetActiveTarget(&log);
|
||||
wxON_BLOCK_EXIT1( wxLog::SetActiveTarget, logOld );
|
||||
|
||||
wxLogWarning("Old warning");
|
||||
CPPUNIT_ASSERT_EQUAL( "Old warning", log.Get() );
|
||||
}
|
||||
|
||||
#endif // WXWIN_COMPATIBILITY_2_8
|
||||
|
Reference in New Issue
Block a user