natefinch / lumberjack

lumberjack is a log rolling package for Go
MIT License
4.81k stars 593 forks source link

lumberjack has chown permission error when using in systemd #208

Closed westofpluto closed 6 months ago

westofpluto commented 6 months ago

I am trying to run my go program on Ubuntu Linux 20.04 and it uses lumberjack and logrus. I am running it using systemd so I have a service file /etc/systemd/system/myservice. Inside there I specify that this should run as user www-data. It does indeed do that. But as soon as I run the service, it creates two log files in my logging folder: /var/log/myservice/myservice.log and /var/log/myservice/myservice-2024-03-28T00-03-55.752.log. The file myservice.log is woned by www-data as expected. The second file with the timestamp is owned by root and the only contents inside are "Failed to write to log, chown /var/log/myservice/myservice.log: operation not permitted". I am assuming that this is a rotated log file but it doesn't seem to be working. How do I fix this?

westofpluto commented 6 months ago

For anyone else who came across this problem, it is actually not lumberjack but the systemd service file that caused the problem. I had these two lines in the service file: StandardOutput=append:/var/log/myserver/myserver.log StandardError=append:/var/log/myserver/myserver.log and these were the lines that caused the problem. Since all output from my program is going through logging commands and not stdout or stderr, there was no reason to have these lines in there. I removed the lines and everything works fine now.