I can't believe I couldn't find anything in the forums about this.... it seems to me that you might want to do this fairly often, but I digress...
My application uses a wxLogChain coupled with both a wxLogStderr and a wxLogTextCtrl so that I can control what is shown to the users but still have a full log for all debugging or other messages to reference if the program crashes. We've all been there, give the user too much info and they squawk to you about nothing (worry-wort) But inevitably there will be a misconfiguration, the user will do the wrong thing, or you'll find you missed something and you need to somehow track down where it went squirrely so you need a full log to be able to trace the issue.
Anyway, I want to get the file output setup as quickly as possible, but I don't have all the filenames and other configuration during the application phase. Instead, I have to wait until the constructor of the main window to open the file, create the logchain, assign the target for the text control, etc.
MY QUESTION: I call wxLog::Suspend() at the very start of it all (literally first statement of MyApp::OnInit()) to try to suppress any log messages until after the log control/file are ready. Then I call Resume. But my test wxLogMessage statements all do the big popup to show me the log statements before the main window is up. So I'm assuming the suspend isn't working? Or am I doing something wrong? I just don't want to lose the messages, but just hide them until the other log targets are ready and THEN let them output (using Resume()).
Suspend Logging until file output is complete Topic is solved
-
- Earned some good credits
- Posts: 149
- Joined: Fri Dec 14, 2007 3:40 pm
- Location: Midland, TX
- Contact:
Suspend Logging until file output is complete
John A. Mason
Midland, TX
Midland, TX
Re: Suspend Logging until file output is complete
I have never used the log chaining or classes you have, but doesn't it have something to do with
Well, while that may be the cause, I'm sorry but I don't have a solution.
For example, when running an app listed below the errors are displayed in the error log dialog only after the message box is shown, as expected. If the line creating wxLogWindow is uncommented, when the message box pops up the errors are already displayed in the log window .wxWidgets documentation for wxLog::Suspend() wrote:Note that suspending the logging means that the log sink won't be flushed periodically, it doesn't have any effect if the current log target does the logging immediately without waiting for Flush() to be called (the standard GUI log target only shows the log dialog when it is flushed, so Suspend() works as expected with it).
Code: Select all
#include <wx/wx.h>
class MyFrame : public wxFrame
{
public:
MyFrame()
: wxFrame(NULL, wxID_ANY, _("Test"))
{
// wxLogWindow* log = new wxLogWindow(this, _("Log"));
wxLogError("Error 1");
wxLogError("Error 2");
Centre();
}
};
class MyApp : public wxApp
{
public:
virtual bool OnInit()
{
wxLog::Suspend();
MyFrame* frame = new MyFrame();
frame->Show();
wxMessageBox("This is not an error, just a message box right after showing the main frame");
wxLog::Resume();
return true;
}
};
IMPLEMENT_APP(MyApp)
-
- Earned some good credits
- Posts: 149
- Joined: Fri Dec 14, 2007 3:40 pm
- Location: Midland, TX
- Contact:
Re: Suspend Logging until file output is complete
Well you are absolutely right. Turns out that the wxLogGUI controlls (wxLogMessage in the message box, etc.) wait on the flush. But if you have a wxLogTextCtrl or other device, there is no internal buffer that messages goto before they are posted. In fact, in my case (using a wxLogTextCtrl) the buffer is the actual wxTextCtrl itself... so it doesn't matter if i suspend it or not. So I'll just have to rethink my schedule of when I do what. Perhaps I can get the file to open in the OnInit() of the application instead of waiting until I make the text controls and all that in the main frame.
Thanks
Thanks
John A. Mason
Midland, TX
Midland, TX