If your program runs as root (which it apparently does not, judging from your “Permission denied” error), either /var/log
or /Library/Logs
is appropriate.
If your program runs as an ordinary user, ~/Library/Logs
is appropriate.
It would be appropriate to create a subdirectory (in whatever log directory you end up using) named after your program, and write your logs in the subdirectory. For example, Apache on macOS writes its logs to /var/log/apache2
by default; the Notes app writes its logs to ~/Library/Logs/com.apple.Notes
.
If your program runs as a system account (not root but not an ordinary user account), then perhaps your installer can create the log subdirectory under /var/log
or /Library/Logs
as root, then chown
it to that system account to make it writable by your program.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…