2016-03-04 13 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) –