Log rotation in Mac OSX
posted 2022.03.19 by Clark Wilkins
I have recently started exploring log rotation to better handle some of the Amazon EC2 servers I am using. As part of the learning project, I wanted to do some log rotation in my sandbox environment, where I have some Node/Express APIs doing a lot of logging.
I was surprised, at first, to find there is no logrotate binary, but a bit of investigation turned valuable links here and here.
For my sandbox, I need to rotate logfiles in a local directory, triggered when the file size reaches 100KB, keeping the last two archived logs, running at midnight. This is what it looks like:
sh-3.2# cat /private/etc/newsyslog.d/clark.conf# logfilename [owner:group] mode count size when/Users/clark/logs/messagine-api-errors.log clark:staff 644 2 100 $D0
/Users/clark/logs/messagine-api-errors.log clark:staff 644 2 100 $D0
/Users/clark/logs/messagine-api-output.log clark:staff 644 2 100 $D0
/Users/clark/logs/messagine-react-errors.log clark:staff 644 2 100 $D0
/Users/clark/logs/messagine-react-output.log clark:staff 644 2 100 $D0
/Users/clark/logs/simplexable-api-errors.log clark:staff 644 2 100 $D0
/Users/clark/logs/simplexable-api-output.log clark:staff 644 2 100 $D0
/Users/clark/logs/topical-api-errors.log clark:staff 644 2 100 $D0
/Users/clark/logs/topical-api-output.log clark:staff 644 2 100 $D0
/Users/clark/logs/topical-react-errors.log clark:staff 644 2 100 $D0
/Users/clark/logs/topical-react-output.log clark:staff 644 2 100 $D0
Once this is setup, there's nothing more to do. Thanks to the sources cited above.