将标准输出重定向到syslog [英] Redirecting standard output to syslog
问题描述
我打算为Debian打包 OpenTibia Server 。我想做的事情之一是通过 /etc/init.d
添加启动和 otserv
进程的守护进程。
I'm planning to package OpenTibia Server for Debian. One of the things I want to do is add startup via /etc/init.d
and daemonization of the otserv
process.
事实上,我们应该将输出重定向到syslog。这通常通过 syslog()
函数完成。目前,代码是:
Thing is, we should probably redirect output to syslog. This is usually done via the syslog()
function. Currently, the code is swarmed with:
std::cout << "Stuff to printout" << std::endl;
是否有正确,容易添加的方法将标准输出和标准错误输出重定向到syslog中替换每一个单独的调用到std :: cout和朋友?
Is there a proper, easy to add, way to redirect standard output and standard error output into syslog without replacing every single "call" to std::cout and friends?
推荐答案
不确定直接的C答案是否足够;但在C中,您可以使用底层的stdio功能将(FILE *)直接插入syslog调用,而无需插入记录器进程。查看
http://mischasan.wordpress。 com / 2011/05/25 / redirecting-stderr-to-syslog /
Not sure whether a straight "C" answer suffices; but in "C" you can use underlying stdio features to plug the (FILE*) directly into syslog calls, without an intervening "logger" process. Check out http://mischasan.wordpress.com/2011/05/25/redirecting-stderr-to-syslog/
这篇关于将标准输出重定向到syslog的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!