wxCmdLineParser, redirect output Topic is solved

If you are using the main C++ distribution of wxWidgets, Feel free to ask any question related to wxWidgets development here. This means questions regarding to C++ and wxWidgets, not compile problems.
Post Reply
Gnawer
Experienced Solver
Experienced Solver
Posts: 65
Joined: Thu Jun 29, 2006 11:10 am
Location: Ahlen, Germany

wxCmdLineParser, redirect output

Post by Gnawer »

[wxWidgets 3.1.1, Windows 7 64 bit]

Hello all,
in wx documentation I read, that wxCmdLineParser.Parse() can generate messages, that "go to standard wx logging system". That seems not to be true. I defined a new wxLogStream() target at wxApp start. All other messages go there, but not that from wxCmdLineParser().
So it blocks the app and waits for pressing OK.

How to avoid that?
Best regards
Gnawer
PB
Part Of The Furniture
Part Of The Furniture
Posts: 4204
Joined: Sun Jan 03, 2010 5:45 pm

Re: wxCmdLineParser, redirect output

Post by PB »

Cursory source search shows that wxCmdLineParser uses wxMessageOutput for the output.

My guess would be you unfortunately need to take care of it yourself, overriding wxMessageOutput. Testing whethe it works as expected should be really quick though...
Gnawer
Experienced Solver
Experienced Solver
Posts: 65
Joined: Thu Jun 29, 2006 11:10 am
Location: Ahlen, Germany

Re: wxCmdLineParser, redirect output

Post by Gnawer »

So, finally, I solved it.
The solution is to use an undocumented class wxMessageOutputLog.
To redirect all outputs (not only from wxCmdLineParser) to the log target, specify this in your application (for example in MyApp::OnInit()).

Code: Select all

auto oldMsgOutput = wxMessageOutput::Get();
auto newMsgOutput = new wxMessageOutputLog();
wxMessageOutput::Set(newMsgOutput);
To restore previous state use this.

Code: Select all

wxMessageOutput::Set(oldMsgOutput);
delete newMsgOutput;
Issues detected in wx docu:
  • - information that wxCmdLineParser::Parse() prints usage to wx standard logging system, is wrong.
    - class wxMessageOutputLog is not documented.
Best regards
Gnawer
PB
Part Of The Furniture
Part Of The Furniture
Posts: 4204
Joined: Sun Jan 03, 2010 5:45 pm

Re: wxCmdLineParser, redirect output

Post by PB »

Gnawer wrote:Issues detected in wx docu:
  • - information that wxCmdLineParser::Parse() prints usage to wx standard logging system, is wrong.
    - class wxMessageOutputLog is not documented.
wxMessageOutput is a actually a part of the official logging system. I have no idea why it is used there, as opposed to the usual wxLog* functions.

wxWidgets have many undocumented classes and they are usually undocumented for a reason.

In any way, you need to report the issue(s) on the wxTrac instead of here.
User avatar
doublemax
Moderator
Moderator
Posts: 19160
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: wxCmdLineParser, redirect output

Post by doublemax »

What was the purpose of all this anyway? Did you just want to suppress the message?

That can also be accomplished by overriding wxApp::OnInitCmdLine and wxApp::OnCmdLineParsed
Use the source, Luke!
Post Reply