> 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/azure/hivel-on-premises-deployment-guide-azure/log-rotation-setup.md).

# Log Rotation Setup

On-Prem Deployment Guide (Azure)

### Why Log Rotation?

Docker containers generate logs continuously. Without rotation, logs can fill up disk space. Hivel services are configured with automatic log rotation that:

* Creates daily log files with service name and date
* Retains logs for 7 days
* Automatically cleans up old logs

### Setup Log Rotation

**Goal:** enable automatic daily log rotation and 7-day retention on the VM.

**Prerequisites:** hivel-onprem package present on the VM (Project Setup).

**On the VM:**

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

**This script will:**

* Create log directory structure (/var/log/hivel/)
* Add daily cron job (runs at midnight)
* Configure log rotation for all Docker containers

**Expected result:** see Verify Log Rotation Setup below.

**If it fails:** see Log rotation not working in [Troubleshooting](/self-managed-hivel-deployment/virtual-private-cloud/azure/hivel-on-premises-deployment-guide-azure/troubleshooting.md).

### Verify Log Rotation Setup

```
# 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:** sudo crontab -l lists the rotation job; ls -la /var/log/hivel/ shows a directory per service.

### 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

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

**Next step:** Verification and Access - to confirm the deployment actually works end to end.

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

{% column %}

{% endcolumn %}

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