I use launchd
to configure a service to write logs to the file.
This is the launchd config.
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Label</key>
<string>my.label</string>
<key>ProgramArguments</key>
<array>
<string>/path/to/binary</string>
<string>param</string>
</array>
<key>KeepAlive</key>
<true/>
<key>StandardErrorPath</key>
<string>/path/to/logfile.log</string>
<key>StandardOutPath</key>
<string>/path/to/logfile.log</string>
<key>UserName</key>
<string>root</string>
</dict>
</plist>
And I use the newsyslog to rotate the logs in the directory above. And the following it the newsyslog config line
/path/to/logfile.log 644 10 10000 * Z
newsyslog is able to rotate the logs. However, after rotation, launchd does not to write to the log file anymore. The last log line in the log file is.
newsyslog[2662]: logfile turned over due to -F request.
Is that a bug, or there is something wrong with the usage?
As far as I can tell, launchd just hooks your stdout and stderr to those two files directly, it doesn't run them through syslog or anything. Since you didn't specify the pidfile option in your newsyslog conf file, it sends HUP to syslog, which doesn't do anything. And your program is writing to a deleted file which is still growing on disk and can lead to the very surprising behaviour of a full disk filled by an unlinked but not yet deleted file!
AFAICT, there are two options: