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

John McAleely picture John McAleely · Jan 27, 2009 · Viewed 18.8k times · Source

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.

Answer

WiseTechi picture WiseTechi · Jan 27, 2009

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