>From b51dde987cb0fadfdebbf0ae3f611dd1f737592d Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Mon, 9 Mar 2015 00:53:24 +0100 Subject: [PATCH 2/4] Don't redirect all wxLog messages to stderr, just the debug ones. Correct the changes of r6007 that redirected all wxLog messages to stderr, which was too eager: the goal was to only show the (otherwise not shown at all) debug messages on stderr, but to keep showing the other messages in the normal way. Use wxLogInterposer to "interpose" a custom log target sending only the debug messages to stderr but continuing to display the messages of other severities as usual. Also, only do this under MSW as it is the only platform which has a dedicated "debug output" channel to which debug messages are sent by default, there is no need to send them to stderr under the other platforms as this is already what happens there by default. Finally, remove the actually unneeded check of the debugger presence: now that we only add to, instead of replacing, the default handling of the debug messages, there is no reason to not do it even when being debugged. --- skeleton.cpp | 38 +++++++++++++++++++++++++++++++++----- 1 file changed, 33 insertions(+), 5 deletions(-) diff --git a/skeleton.cpp b/skeleton.cpp index b082a99..2ec2455 100644 --- a/skeleton.cpp +++ b/skeleton.cpp @@ -91,13 +91,13 @@ #include #include #include -#include // wxIsDebuggerRunning() #include #include #include // wxSafeShowMessage() #include // wxRound() #include #include +#include #include #include // wxGetTextFromUser() #include @@ -634,10 +634,38 @@ bool Skeleton::OnInit() { try { - if(!wxIsDebuggerRunning()) - { - wxLog::SetActiveTarget(new wxLogStderr); - } +#if defined __WXMSW__ + // Send log messages of debug (and trace, which are roughly equivalent + // to debug) severity, which are usually not shown at all under MSW, to + // stderr. + // + // The end users wouldn't see them there as they don't run the program + // from a terminal, but they could be potentially valuable to the + // developers. + struct DebugStderrLog : wxLogInterposer + { + virtual void DoLogTextAtLevel(wxLogLevel level, wxString const& msg) + { + switch(level) + { + case wxLOG_FatalError: + case wxLOG_Error: + case wxLOG_Warning: + case wxLOG_Message: + case wxLOG_Status: + case wxLOG_Info: + break; + + case wxLOG_Debug: + case wxLOG_Trace: + wxMessageOutputStderr().Output(msg); + break; + } + } + }; + + wxLog::SetActiveTarget(new DebugStderrLog); +#endif // defined __WXMSW__ if(false == ProcessCommandLine(argc, argv)) { -- 2.1.0