Search code examples
c++stdoutwt

How to stop wt c++ writing to stdout (console)


Wt is a C++ framework and it, like many others, write the results from events to stdout aka console. While other side of the application what is in use, also writes to it, all this info gets cluttered together and is hard to read. The aim is to write everything from Wt to a logging file.

From source code I found something:

 Wt::WLogger logger; 
 logger.setFile("logging_file.txt");
 logger.configure("* -debug debug:wthttp");

However, I didn't still manage to BLOCK it from writing to std out. What is needed would look like.

 Wt::WLogger logger;
 logger.setFile("logging_file.txt");
 logger.configure("-no_std_out"); //this is a made up argument

Solution

  • Everything that's output by Wt's logger is written to the log file configured in your configuration. The shortest configuration file that redirects logging to a file would be the following:

    <server>
        <application-settings location="*">
            <log-file>/path/to/logfile</log-file>
        </application-settings>
    </server>
    

    There's one exception to this: Wt::Dbo often logs to stderr. We (the Wt developers) may change this in the future to make it a bit more configurable too.

    Your code sample will only configure one specific instance of WLogger, and wouldn't work for the logging of Wt itself, which uses its own logger. You can access that instance with WServer::logger().

    There's also the access log. You can configure where that goes with the --accesslog option.