While macOS shares Unix roots with Linux, its logging ecosystem differs significantly. The absence of logrotate
in default installations often surprises Linux migrants. macOS uses a combination of built-in tools and third-party solutions for log management.
macOS provides two primary mechanisms for log rotation:
# 1. newsyslog (the traditional BSD-style utility)
$ man newsyslog
# 2. launchd (macOS's modern service management)
$ man launchd.plist
The /etc/newsyslog.conf
file controls log rotation. Example configuration:
# Example entry format:
# logfilename [owner:group] mode count size when flags [/pid_file] [sig_num]
/var/log/app.log 644 7 * @T00 J
Key parameters:
7
- Keep 7 archived copies*
- Rotate regardless of size@T00
- Rotate daily at midnightJ
- Use bzip2 compression
For more control, create a plist in /Library/LaunchDaemons/
:
<?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>com.example.logrotate</string>
<key>ProgramArguments</key>
<array>
<string>/usr/local/bin/logrotate</string>
<string>/etc/logrotate.conf</string>
</array>
<key>RunAtLoad</key>
<true/>
<key>StartCalendarInterval</key>
<dict>
<key>Hour</key>
<integer>0</integer>
<key>Minute</key>
<integer>0</integer>
</dict>
</dict>
</plist>
For those preferring the Linux approach:
$ brew install logrotate
$ sudo cp /usr/local/etc/logrotate.conf /etc/
$ sudo chown root:wheel /etc/logrotate.conf
Sample configuration:
/var/log/*.log {
daily
missingok
rotate 14
compress
delaycompress
notifempty
create 644 root wheel
}
Test your configuration manually:
# For newsyslog
$ sudo newsyslog -v
# For logrotate
$ sudo logrotate -d /etc/logrotate.conf
While macOS shares Unix roots with Linux, its logging ecosystem differs significantly. The absence of logrotate
in default installations often surprises developers coming from Linux environments. macOS employs its own logging system called asl
(Apple System Logger), though many applications still write directly to log files.
macOS includes several built-in mechanisms for log management:
# View system logs
log show --predicate 'process == "myapp"'
# Configure log rotation via newsyslog
sudo nano /etc/newsyslog.conf
The newsyslog
utility handles basic log rotation through its configuration file. Example entry:
/var/log/myapp.log 644 7 * @T00 J
For developers needing logrotate
-like functionality:
- Homebrew Installation:
brew install logrotate
- Custom Configuration: After installation, configure
/usr/local/etc/logrotate.d/
Sample logrotate
configuration for a Node.js application:
/Users/me/myapp/logs/*.log {
daily
missingok
rotate 14
compress
delaycompress
notifempty
copytruncate
}
To run logrotate automatically on macOS:
# Create LaunchDaemon plist
sudo nano /Library/LaunchDaemons/com.my.logrotate.plist
Label
com.my.logrotate
ProgramArguments
/usr/local/bin/logrotate
/usr/local/etc/logrotate.conf
RunAtLoad
StartCalendarInterval
Hour
2
Minute
0