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

# Logs

Every environment comes pre-installed with its own instance of open source [Loki](https://grafana.com/oss/loki/) and
[Grafana](https://grafana.com/oss/). Grafana will be running on its own URL for each environment and must be used to see
all logs collected from your environment.

*Grafana is simple to use yet very powerful in how you can customize the setup for yourself.*

### Print logs

Your application should be printing logs to STDOUT or STDERR. These logs will be collected automatically by
pre-installed Loki and kept available for you to view inside Grafana dashboard.

### See logs

Grafana dashboard can be opened from Monitoring tab, in Environment page.

Logs are collected and kept organised under a Kubernetes namespace. Your application is hosted in a specific Kubernetes
namespace using which you can filter and see logs under Explore section.

### Tail logs from your terminal

Grafana is the place to search and correlate logs across your environment. When you just want to watch one service as it
runs - during a deploy, or while reproducing a bug - `ops logs` streams the same output straight to your terminal:

```sh theme={null}
ops logs --env staging --svc api
```

`--env` and `--svc` take the environment and service **names** shown in your dashboard, or their ids. The stream stays
open and prints new lines as they arrive - press `Ctrl-C` to stop.

Every ready pod of the service is read at once, and each line is prefixed with the pod it came from so you can tell
replicas apart:

```
[api-7d9f8b6c4-2xk9p] GET /health 200
[api-7d9f8b6c4-mn4vt] GET /orders 201
```

The flags you will reach for most often:

| Flag | Default | Description |
| - | - | - |
| `-n, --tail` | `100` | Number of recent lines to show. `0` shows everything Loki holds |
| `-S, --since` | - | Only show logs newer than this, e.g. `15m` or `2h` |
| `-T, --timestamps` | `false` | Prefix each line with its timestamp |
| `-f, --follow` | `true` | Pass `--follow=false` for a snapshot that prints and exits |

```sh theme={null}
ops logs --env staging --svc api --tail 500 --timestamps
ops logs --env staging --svc api --since 15m
ops logs --env staging --svc api --follow=false
```

Don't have the CLI yet? Install it on [macOS](/cli/install-macos), [Linux](/cli/install-linux) or
[Windows](/cli/install-windows), then run `ops login`.

See [CLI usage](/cli/usage#stream-logs-from-a-service) for the full set of options, including `-i` to pick a single pod.

### Custom dashboards

Grafana installation in each environment comes with pre-built dashboards to see infrastructure/system metrics. You can
create new dashboards to see logs from different deployments/services in your application as needed.

<Info>See [Grafana docs](https://grafana.com/docs/grafana/latest/?pg=oss-graf\&plcmt=resources) to learn more</Info>


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