我有一个使用log4c进行日志记录的应用程序。在过去的几个月的开发中,它一直运行良好。今天,我为这个应用程序写了一个systemd服务文件,让它在启动时运行。现在log4c不会生成任何日志文件。这是我的log4crc文件。我甚至尝试指定日志目录的绝对路径,但也不起作用。
<?xml version="1.0" encoding="ISO-8859-1"?>
<!DOCTYPE log4c SYSTEM "">
<log4c>
<config>
<bufsize>0</bufsize>
<debug level="2"/>
<nocleanup>0</nocleanup>
</config>
<!-- root category ========================================= -->
<category name="root" priority="debug" appender="rolling_appender"/>
<!-- default appenders ===================================== -->
<appender name="rolling_appender" type="rollingfile" logdir="." prefix="foo" layout="basic" rollingpolicy="rolling_policy" />
<!-- default layouts ======================================= -->
<layout name="basic" type="basic"/>
</log4c>下面是我的代码:
#include <log4c.h>
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char** argv)
{
fprintf(stderr, "log4c tester\n");
if (log4c_init())
{
fprintf(stderr, "Failed to start log4c\n");
return -1;
}
log4c_category_log(log4c_category_get("root"), 1, "Testing to log4c");
}下面是我的服务文件:
[Unit]
Description=Logging test
[Service]
ExecStart=/opt/test
[Install]
WantedBy=multi-user.target我甚至让测试应用程序在调用init函数之前更改了它的工作目录。有什么想法吗?
发布于 2020-07-27 20:22:25
这太尴尬了。修复非常简单,只需在服务下添加一个WorkingDirectory:
[Unit]
Description=Logging test
[Service]
ExecStart=/opt/test
WorkingDirectory=/opt/test
[Install]
WantedBy=multi-user.targethttps://stackoverflow.com/questions/63082551
复制相似问题