> For the complete documentation index, see [llms.txt](https://docs.hivel.ai/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.hivel.ai/self-managed-hivel-deployment/virtual-private-cloud/aws/hivel-on-premises-deployment-guide-aws/log-rotation-setup.md).

# Log Rotation Setup

On-prem Deployment Guide (AWS)

### Purpose

Docker containers generate logs continuously. Without rotation, logs consume disk space. This setup ensures automatic daily rotation and 7-day retention.

### Prerequisites

* SSH access to the VM
* Sudo privileges
* Hivel installation directory: `/opt/hivel-onprem`

## Execution Steps

### **Step 1: Install Log Rotation**

On the VM, run:

```
cd /opt/hivel-onprem
# Run setup script (requires sudo)
sudo ./scripts/setup-log-rotation.sh
```

This script:

* Creates log directory structure (`/var/log/hivel/`)
* Adds a daily cron job (runs at midnight)
* Configures rotation for all Docker containers

### **Step 2: Verify Installation**

Check that the cron job is installed, log directories were created and test rotation.

```
# Check cron job is installed
sudo crontab -l

# Check log directories created
ls -la /var/log/hivel/

# Manually test rotation (optional)
sudo ./scripts/docker-log-rotate.sh

```

**Expected result:** Cron job appears in `sudo crontab -l` output; service directories exist in `/var/log/hivel/`

**If installation fails:** See [Troubleshooting](/self-managed-hivel-deployment/virtual-private-cloud/aws/hivel-on-premises-deployment-guide-aws/troubleshooting.md) documentation.

## Log File Locations

Logs are stored in:

```
/var/log/hivel/<service-name>/<service-name>-YYYY-MM-DD.log
```

Examples:

* /var/log/hivel/auth-svc/auth-svc-2025-01-15.log
* /var/log/hivel/insightly-svc/insightly-svc-2025-01-15.log

## Viewing Logs

```
# View today's logs for a service
cat /var/log/hivel/auth-svc/auth-svc-$(date +%Y-%m-%d).log

# View logs from specific date
cat /var/log/hivel/auth-svc/auth-svc-2025-01-15.log

# Follow logs in real-time
tail -f /var/log/hivel/auth-svc/auth-svc-$(date +%Y-%m-%d).log

# Or use Docker logs command
docker logs -f auth-svc
```

### Log Retention Policy

* **Retention Period:** 7 days
* **Cleanup:** Logs older than 7 days are automatically deleted
* **Rotation:** New log file created daily at midnight

<br>

{% columns %}
{% column %} <a href="/self-managed-hivel-deployment/virtual-private-cloud/aws/hivel-on-premises-deployment-guide-aws/deployment-methods/method-2-deployment-using-docker-compose.md" class="button primary" data-icon="backward">Back to Method 2: Docker Compose</a>
{% endcolumn %}

{% column %}

{% endcolumn %}

{% column %} <a href="/self-managed-hivel-deployment/virtual-private-cloud/aws/hivel-on-premises-deployment-guide-aws/verification-and-access.md" class="button primary" data-icon="forward">Verification and Access</a>
{% endcolumn %}
{% endcolumns %}
