Page 1 of 1

Unified logging system wxLog

Posted: Sat Jan 25, 2014 6:18 am
by tonto
Hey all
I thought this might be of interest. I created a sort of unified logging system with several wxLog classes, wxLogStderr for logfile, wxLogWindow for logwindow, and wxLogGui for interactive responses

I have a github gist for it here and a blog post ... -wxwidgets

Setup code

Code: Select all

* @brief create log window, logfile, and integrated gui notifications for wxlog settings
* @param parent
* @return
MyMainFrame::MyMainFrame( wxWindow* parent ):
MainFrame( parent )
  wxLog *temp;
  wxFFile *test=new wxFFile("yourLogFile.log","a");
  //create logfile with wxLogStderr. contrary to the name, itll log everything
  temp=new wxLogStderr(test->fp());
  //create wxLogGui and use wxLogChain it
  temp=new wxLogChain(new wxLogGuiMod());
  //create logwindow
  //note:no need to usesetactivetarget or wxlogchain on wxLogWindow
  temp=new wxLogWindow(this, wxS("Log messages"),true);
  //set verbose levels globally (these are static functions)

Modified wxLogGui class to ignore verbose messages

Code: Select all

* @brief subclass of wxLogGui to ignore verbose(wxLOG_INFO) messages
class wxLogGuiMod :public wxLogGui {
  virtual void DoLogRecord(wxLogLevel level,
    const wxString& msg,
    const wxLogRecordInfo& info);
* @brief override default log record from wxLogGui to ignore verbose(wxLOG_INFO) messages
* @param
* @return
void wxLogGuiMod::DoLogRecord(wxLogLevel level,
  const wxString& msg,
  const wxLogRecordInfo& info)
  if(level==wxLOG_Info ) return;
  else wxLogGui::DoLogRecord(level,msg,info);
Test code

Code: Select all

wxLogMessage("Message");//produces messagebox and logs to file/window
wxLogError("Error");//produces error message and logs to file/window
wxLogStatus("Status");//creates message on app status bar and logs to file/window
wxLogVerbose("Verbose");//does not create message (due to wxLogGuiMod) and logs to file/window