I have a small programm that writes someting to a log file on a event. When i run my programm via comandline ./main it works all fine. But when use systemctl Alarm.service no file is created.
main.cpp
void initLogger(){
log4cpp::PatternLayout* myLayout = new log4cpp::PatternLayout();
//myLayout->setConversionPattern("%d [%p] %m%n");
myLayout->setConversionPattern("%d{[%a] [%d-%m-%G] [%H:%M:%S]} [%c] %m%n"); //[Tue] [25-07-2023] [18:33:08]
log4cpp::Appender *console = new log4cpp::OstreamAppender("console", &std::cout);
console->setLayout(myLayout);
log4cpp::Appender *file = new log4cpp::FileAppender("default", "program.log");
file->setLayout(myLayout);
Log.setPriority(log4cpp::Priority::INFO);
Log.addAppender(console);
Log.addAppender(file);
MotionLogger.setPriority(log4cpp::Priority::INFO);
//MotionLogger.addAppender(appender1);
//MotionLogger.addAppender(appender2);
}
..
..
..
..
..
MotionLogger.info("Test");
Alarm.service
[Unit]
Description=Alarmanlage
[Service]
Type=simple
StandardOutput=journal
ExecStart=/home/kali/cpp_test/fuchs_alarmanlage/main
[Install]
WantedBy=multi-user.target
I would expect a file created at /home/kali/cpp_test/fuchs_alarmanlage/
Chaning to ExecStart=sudo /home/kali/cpp_test/fuchs_alarmanlage/main
has no effect.