gpt4 book ai didi

c++ - 将标准输出重定向到系统日志

转载 作者:IT老高 更新时间:2023-10-28 22:33:36 24 4
gpt4 key购买 nike

我打算打包OpenTibia Server对于 Debian。我想做的一件事是通过 /etc/init.d 添加启动和 otserv 进程的守护进程。

问题是,我们可能应该将输出重定向到 syslog。这通常通过 syslog() 函数完成。目前,代码蜂拥而至:

std::cout << "Stuff to printout" << std::endl;

是否有一种适当的、易于添加的方法将标准输出和标准错误输出重定向到 syslog,而不用替换每个对 std::cout 和 friend 的“调用”?

最佳答案

您可以使用 logger 命令将您的 stdout 传送到 syslog:

NAME

 logger - a shell command interface to the syslog(3) system log module

SYNOPSIS

 logger [-isd] [-f file] [-p pri] [-t tag] [-u socket] [message ...]

DESCRIPTION

 Logger makes entries in the system log.  It provides a shell command
interface to the syslog(3) system log module.

如果你没有在命令行上提供一条消息,它会读取 stdin

关于c++ - 将标准输出重定向到系统日志,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/665509/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com