> ## Documentation Index
> Fetch the complete documentation index at: https://docs.lagerdata.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Logs

> Manage Lager Box logs

Check the size of log files on Lager Boxes, and remove old ones.

## Syntax

```bash theme={null}
lager logs COMMAND [OPTIONS]
```

## Commands

| Command | Description |
| - | - |
| `size` | Check log file sizes on Lager Box(es) |
| `clean` | Clean old log files from Lager Box |
| `docker` | Check Docker container log sizes |

> [!NOTE]
>
> These commands measure and delete log files. They do not print log content. To
> read the logs of the box services, see the Reading Service Logs section below.

***

## Command Reference

### `size`

Check the size of `~/box/logs` on one Lager Box, or on every saved Lager Box.

```bash theme={null}
lager logs size [--box BOX] [--verbose]
```

**Options:**

* `--box BOX` - Specific Lager Box (if not specified, checks all)
* `--verbose` / `-v` - Show individual log files

**Examples:**

```bash theme={null}
# Check all Lager Boxes
lager logs size

# Check specific Lager Box
lager logs size --box my-lager-box

# Show individual files
lager logs size --box my-lager-box --verbose
```

Output:

```
my-lager-box (100.64.1.42):
  Total logs: 620M
  Warning: Logs are large, consider cleaning
```

### `clean`

Delete the `*.log` files in `~/box/logs` that are older than a number of days.

```bash theme={null}
lager logs clean --box BOX [--older-than DAYS] [--yes]
```

**Options:**

* `--box BOX` (required) - Lager Box to clean
* `--older-than DAYS` - Remove logs more than N full days old (default: 1). The age counts whole days only, so `--older-than 1` removes files that are at least 48 hours old ([#851](https://github.com/lagerdata/lager/issues/851))
* `--yes` - Skip confirmation prompt

**Examples:**

```bash theme={null}
# Clean logs older than 1 day (default)
lager logs clean --box my-lager-box

# Clean logs older than 7 days
lager logs clean --box my-lager-box --older-than 7

# Clean without confirmation
lager logs clean --box my-lager-box --yes
```

Output:

```
Cleaning logs on my-lager-box... OK
Current logs size: 48M
```

### `docker`

Check the size of the Docker log file of each running container. A Lager Box
runs one container, `lager`.

```bash theme={null}
lager logs docker --box BOX [--container NAME]
```

**Options:**

* `--box BOX` (required) - Lager Box to check
* `--container NAME` - Specific container (default: all)

**Examples:**

```bash theme={null}
# Check all containers
lager logs docker --box my-lager-box

# Check specific container
lager logs docker --box my-lager-box --container lager
```

Output:

```
Docker logs on my-lager-box (100.64.1.42):

Container: lager
  Size: 8.2M Path: /var/lib/docker/containers/<id>/<id>-json.log

Note: Docker logs are automatically rotated with max-size=10m, max-file=3
Total maximum per container: ~30MB
```

The command reads the log file with `sudo -n` over a non-interactive SSH session.
If `sudo` asks for a password on the box, the size line says `unknown`. The
command then tells you to allow `sudo -n ls` for the login user of the box.

***

## Log Rotation

Docker containers use automatic log rotation:

* **Maximum size**: 10 MB per file
* **Maximum files**: 3 (rotates oldest)

This means Docker logs are self-managing and do not grow without a limit.

***

## Size Thresholds

The `size` command uses warning thresholds:

| Size | Status |
| - | - |
| 500 MB or less | Normal |
| More than 500 MB | `Warning: Logs are large, consider cleaning` |
| 1 GB or more | `ERROR: Logs are very large! Clean immediately:`, followed by the `clean` command |

***

## What Gets Cleaned

The `clean` command removes:

* Files that match `*.log` in `~/box/logs` on the box host, and that are more than `--older-than` full days old

It does **not** remove:

* System logs in `/var/log/`
* Docker container logs (managed separately)
* The service logs inside the container
* Files newer than `--older-than` threshold

***

## Reading Service Logs

The box services write their logs inside the `lager` container:

| Service | Log file |
| - | - |
| Python execution service | `/tmp/lager-python-service.log` |
| Hardware service | `/tmp/lager-hardware-service.log` |
| Debug service | `/tmp/lager-debug-service.log` |
| Box HTTP server (port 9000) | `/tmp/lager-http-server.log` |
| MCP server | `/tmp/lager-mcp-server.log` |

To read the last lines of a log, run `docker exec` on the box:

```bash theme={null}
lager ssh --box my-lager-box -- docker exec lager tail -n 200 /tmp/lager-hardware-service.log
```

***

## Automation

Schedule regular log cleaning:

```bash theme={null}
# In crontab or CI/CD
lager logs clean --box my-lager-box --older-than 7 --yes
```

***

## Examples

```bash theme={null}
# Daily maintenance workflow
for box in gw1 gw2 gw3; do
    echo "Checking $box..."
    lager logs size --box $box
    lager logs clean --box $box --older-than 3 --yes
done

# Monitor log growth
lager logs size  # Check all Lager Boxes
lager logs docker --box my-lager-box  # Check Docker logs
```

***

## Notes

* `--box` takes the name of a saved Lager Box. An IP address is not accepted.
* These commands connect over SSH as the user that you stored with `lager boxes add --user`, or as `lagerdata` if you stored none. They use key authentication only: the `lager_box` key first, then your own SSH keys.
* Docker logs are automatically rotated
* Use `--verbose` to identify large log files
* Regular cleaning prevents disk space issues


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.