7

As this answer suggested, I activated logging of a .plist file I have generated.

<key>StandardOutPath</key>
<string>/path/to/logfile.log</string>
<key>StandardErrorPath</key>
<string>/path/to/another_logfile.log</string>

However, the log files are slowly getting larger, and I was wondering if there was a way to limit how large the logs can get within the .plist file?

Rekovni
  • 211
  • 1
  • 8

2 Answers2

4

I couldn't find a way to do this within the .plist file, however using newsyslog (rotate log files) instead seems to be the way forward.

Steps:

  • Edit /etc/newsyslog.conf
  • Add the following syntax:
<log filename>   [owner:group]  mode count size when flags [/pid_file] [sig_num]
  • Verify that the configuration file is correct with sudo newsyslog -nvv

So for example from the question, I'll add the following to /etc/newsyslog.conf:

/path/to/logfile.log               644  2     1000 *     J
/path/to/another_logfile.log       644  2     1000 *     J
  • mode: 644 (root can change it, everyone else can read it)
  • count: 2 (maximum number of archive files which may exist)
  • size: 1000 (max log file size of 1000 kilobytes)
  • when: * (log rotation solely depends on the size)
  • flags: J (newsyslog should attempt to save disk space by compressing the rotated log file using bzip)

See the newsyslog manual for more information.

Rekovni
  • 211
  • 1
  • 8
  • 2
    I tried this and it mostly worked. It rotated the log and wrote "Jul 22 07:30:02 macmini newsyslog[1768]: logfile turned over due to size>1000K" in the new log at that's it. What happened? The process being logged by launchd is still running, but not writing to the new log. Is it launchd's fault or the process'? If I unload and load the `.plist`, it starts logging again. – brock Jul 23 '20 at 03:37
0

I just ended up blanking the files from the job itself :)

> /path/to/logfile.log
Bax
  • 111
  • 3