Docs / Server Management / How to Configure Logrotate for Custom Applications

How to Configure Logrotate for Custom Applications

By Admin · Feb 25, 2026 · Updated Apr 23, 2026 · 234 views · 1 min read

What Is Logrotate?

Logrotate is a utility that automatically rotates, compresses, and removes old log files. Without it, log files grow indefinitely and consume all disk space.

Default Configuration

# Global settings
cat /etc/logrotate.conf

# Per-application configs
ls /etc/logrotate.d/

Create a Custom Configuration

Create /etc/logrotate.d/myapp:

/var/log/myapp/*.log {
    daily
    rotate 14
    compress
    delaycompress
    missingok
    notifempty
    create 0640 www-data www-data
    sharedscripts
    postrotate
        systemctl reload myapp > /dev/null 2>&1 || true
    endscript
}

Key Directives

DirectiveMeaning
daily/weekly/monthlyRotation frequency
rotate 14Keep 14 rotated files
compressGzip old log files
delaycompressCompress previous rotation, not current
missingokDon't error if log is missing
notifemptyDon't rotate empty files
createCreate new log file with specified permissions
copytruncateTruncate original file after copy (apps that don't reopen files)
size 100MRotate when file reaches 100 MB

Test Configuration

# Dry run (show what would happen)
sudo logrotate -d /etc/logrotate.d/myapp

# Force rotation
sudo logrotate -f /etc/logrotate.d/myapp

Size-Based Rotation

/var/log/myapp/access.log {
    size 100M
    rotate 5
    compress
    missingok
    copytruncate
}

Was this article helpful?