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: 54
Joined: Thu Jun 29, 2006 11:10 am
Location: Ahlen, Germany

wxCmdLineParser, redirect output

Post by Gnawer » Mon Aug 13, 2018 1:16 pm

[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: 2057
Joined: Sun Jan 03, 2010 5:45 pm

Re: wxCmdLineParser, redirect output

Post by PB » Mon Aug 13, 2018 2:10 pm

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: 54
Joined: Thu Jun 29, 2006 11:10 am
Location: Ahlen, Germany

Re: wxCmdLineParser, redirect output

Post by Gnawer » Tue Aug 14, 2018 7:14 am

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: 2057
Joined: Sun Jan 03, 2010 5:45 pm

Re: wxCmdLineParser, redirect output

Post by PB » Tue Aug 14, 2018 9:43 am

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: 14079
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: wxCmdLineParser, redirect output

Post by doublemax » Tue Aug 14, 2018 10:13 am

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