我有一个代码为
的c程序 setlogmask (LOG_UPTO (LOG_NOTICE));
openlog ("thelog", LOG_CONS | LOG_PID | LOG_NDELAY, LOG_LOCAL1);
syslog (LOG_NOTICE, "thelog : started by User %d", getuid ());
syslog (LOG_INFO, "thelog: an info is logging");
closelog();
代码工作正常但问题是日志正在记录到文件中 / var / log / messages,我有/etc/rsyslog.conf no和syslog.conf
我希望将日志记录到新文件/var/log/thelog.log文件
如何解决此问题。
答案 0 :(得分:3)
如果您希望将LOCAL1记录到单独的文件
kill -HUP
重新加载其配置。 配置
为local1添加一个特定的行,就像这个
local1.* -/var/log/thelog.log
在
*.*;mail.none;news.none -/var/log/messages
并从local?。*
的配置中删除local1local0.* -/var/log/localmessages
local2,local3.* -/var/log/localmessages
配置文件准备好后
kill -HUP <pid-of-syslogd>
答案 1 :(得分:0)
You need to put this like -
local1.* -/var/log/myfile.log
*.*;auth,authpriv.none -/var/log/syslog
restart syslogd service as
sudo service rsyslog restart