2016-03-04 51 views
1

我无法更改wxLog功能的LogLevel。更改wxWidgets LogLevel

我想达到什么目的:将所有内容记录到日志文件中。

在下面的示例代码日志记录基本上可行,但我只看到LogLevel为WarningError的消息。我认为使用wxLog::SetLogLevel(wxLOG_Info);来设置logLevel应该够了,但显然我错过了一些东西。任何提示?

#include <wx/wxprec.h> 
#ifndef WX_PRECOMP 
#include <wx/wx.h> 
#endif 
#include <wx/stdpaths.h> 

class TestApp : public wxApp 
{ 
public: 

    virtual bool OnInit(); 

private: 

    FILE* m_pLogFile; 
}; 


bool TestApp::OnInit() 
{ 
    m_pLogFile = fopen("c:\\tmp\\foo.txt", "a+"); 
    if (m_pLogFile == NULL) 
    { 
     return false; 
    } 

    wxLogStderr* pFileLogger = new wxLogStderr(m_pLogFile); 
    delete wxLog::SetActiveTarget(pFileLogger); 

    wxLog::SetLogLevel(wxLOG_Info); 

    wxLogError(L"Error"); 
    wxLogWarning(L"Warning"); 
    wxLogInfo(L"Info"); 
    wxLogVerbose(L"Verbose"); 
    wxLogDebug(L"Debug"); 

    wxFrame* pFrame = new wxFrame(NULL, wxID_ANY, L"Title"); 
    pFrame->Show(); 

    return true; 
} 

wxIMPLEMENT_APP(TestApp); 

回答

2

由于不幸的历史原因wxLogInfo()实际上是完全一样wxLogVerbose()和同样不幸向后兼容的原因,详细记录必须通过显式调用wxLog::SetVerbose(true)启用,所以没有它既不是“信息”,也不是“放牧”是记录(并与它都会)。

其实我们可能应该在wxWidgets 3.2中最终解决这个问题,所以希望它在下一个版本中不会像这样工作。但现在您需要拨打SetVerbose()以启用这些消息另外来设置日志级别。

+0

另请参阅[此提交](https://github.com/wxWidgets/wxWidgets/commit/da7388c9c8f875c4136b79c547e7663fe9bc41f7) –