I have an application that uses log4c for logging. It has been working well for the last few months of development. Today I wrote a systemd service file for this application to run on startup. Now log4c doesn't generate any log files. Here is my log4crc file. I even tried to specify an absolute path to the logging directory, but that didn't work either.
<?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>
Below is my code:
#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");
}
And here is my services file:
[Unit]
Description=Logging test
[Service]
ExecStart=/opt/test
[Install]
WantedBy=multi-user.target
I have even had the test app change it's working directory prior to calling the init function. Any ideas out there?
This is embarrassing. The fix was extremely simple, just add a WorkingDirectory under service: