-3

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
Brad Larson
  • 170,088
  • 45
  • 397
  • 571
Levi
  • 141
  • 1
  • 9
  • Could you be a bit more specific? – harper Sep 28 '17 at 07:31
  • To be more specific about what exactly? Wt writes events to std out aka console e.g: 127.0.0.1 - - blabla POST /?etcetc Can it be redirected to a file instead of flooding stdout. – Levi Sep 28 '17 at 07:34

3 Answers3

2

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.

RockinRoel
  • 308
  • 1
  • 8
  • Thank you, that log file works well. However, is it possible to also redirect GET/POST message to log file? e.g: " 127.0.0.1 - - [2017-Sep-29 11:01:37.664611] "GET /?_=/test HTTP/1.1" 200 2901 " – Levi Sep 29 '17 at 08:10
  • 1
    That's the `--accesslog` option I was talking about. Just provide that option to the Wt executable next to all of the other options (`--docroot`, etc.). – RockinRoel Oct 01 '17 at 13:23
1

If I have properly understood what you are asking: you need to create an object of the type ofstream and then use it as follows:

#include <iostream>
#include <fstream> // needed for file operation
int main () {
std::ofstream file; 
file.open ("hello.txt");
// now do your calculation, other stuff...
// write to the file
file << "Text here\n";
file.close();
return 0;
}

This is, of course, the most basic stuff. More details can be found here, for example.

anotherone
  • 680
  • 1
  • 8
  • 23
0

How to redirect stdout from wt to some file?

Maybe pipes can help you

Quentin Laillé
  • 125
  • 1
  • 12