# Log rotation configuration for Overseas Appointment System

# API application logs
/var/log/app/*.log {
    daily
    rotate 14
    compress
    delaycompress
    missingok
    notifempty
    create 0640 nodejs nodejs
    sharedscripts
    postrotate
        # Signal the application to reopen log files if needed
        # docker kill -s USR1 overseas-appointment-api 2>/dev/null || true
    endscript
}

# Nginx access logs
/var/log/nginx/access.log {
    daily
    rotate 14
    compress
    delaycompress
    missingok
    notifempty
    create 0640 nginx adm
    sharedscripts
    postrotate
        [ -f /var/run/nginx.pid ] && kill -USR1 $(cat /var/run/nginx.pid) 2>/dev/null || true
    endscript
}

# Nginx error logs
/var/log/nginx/error.log {
    daily
    rotate 14
    compress
    delaycompress
    missingok
    notifempty
    create 0640 nginx adm
    sharedscripts
    postrotate
        [ -f /var/run/nginx.pid ] && kill -USR1 $(cat /var/run/nginx.pid) 2>/dev/null || true
    endscript
}

# MySQL slow query logs
/var/log/mysql/slow.log {
    daily
    rotate 7
    compress
    delaycompress
    missingok
    notifempty
    create 0640 mysql mysql
    sharedscripts
    postrotate
        # Flush MySQL logs
        docker exec overseas-appointment-mysql mysqladmin flush-logs 2>/dev/null || true
    endscript
}
