如何阻止wt c ++写入stdout(控制台)

时间:2017-09-28 07:30:15

标签: c++ stdout wt

Wt是一个C ++框架,它和其他许多人一样,将事件的结果写入stdout aka console。虽然应用程序的另一面正在使用中,但也写入了它,所有这些信息都混杂在一起并且难以阅读。目的是将所有内容从Wt写入日志文件。

从源代码我发现了一些东西:

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

然而,我仍然没有设法阻止它从写入std out。需要的是什么。

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

3 个答案:

答案 0 :(得分:1)

如果我已正确理解您的要求:您需要创建一个类型为ofstream的对象,然后按如下方式使用它:

#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;
}

这当然是最基本的东西。例如,可以找到更多详细信息here

答案 1 :(得分:1)

Wt记录器输出的所有内容都将写入配置中配置的日志文件中。将日志记录重定向到文件的最短配置文件如下:

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

有一个例外:Wt :: Dbo经常登录到stderr。我们(Wt开发人员)将来可能会对此进行更改,以使其更具可配置性。

您的代码示例将仅配置WLogger的一个特定实例,并且不能用于记录使用其自己的记录器的Wt本身。您可以使用WServer::logger()访问该实例。

还有访问日志。您可以使用--accesslog选项配置其中的位置。

答案 2 :(得分:0)

How to redirect stdout from wt to some file?

也许pipes can help you

相关问题