Linux – How should I log from a non-root Debian Linux daemon

debianlinuxloggingroot

I'm writing a new daemon, which will be hosted on Debian Linux.

I've found that /var/log has root only write permissions, so my daemon cannot write log files there.

However, if it writes there, it appears it will gain automatic log rotation, and also work as a user might expect.

What is the recommended way for a daemon to write log entries that appear in /var/log, without having to be run as root?

The daemon is a webserver, so the log traffic will be similar to Apache.

Best Answer

You should create a subdirectory like /var/log/mydaemon having the daemon's user ownership