Grafana LogCLI
$ logcli Official Low RiskGrafana LogCLI (logcli) queries Grafana Loki and Grafana Cloud Logs instances using LogQL directly from the command line. Its --output=jsonl / -o raw modes, --quiet flag, and LOKI_* environment variables make it reliable for automated SRE log triage.
brew install logcli Use logcli for streaming or piping large LogQL results (-o jsonl / -o raw) into UNIX filters; Grafana MCP is helpful when agents also need dashboard or Prometheus correlation.
Agent-Readiness Checklist
Static evaluation (not yet probed on this host). Run npm run data:probe locally to capture live verification.
FCRS-1.0 6-Dimension Breakdown
Supports --output=jsonl, -o raw, --quiet, and --limit alongside LOKI_* env vars for headless queries.
--output=jsonlemits Loki API payloads as JSON Lines-q/--quietsuppresses query progress noise on stderr/stdout
Strictly read-only query tool with explicit LOKI_ORG_ID tenant isolation and --limit bounds.
- Read-only query interface against Loki HTTP API
- Supports read-only bearer tokens and basic auth env vars
Single Go binary installable via Homebrew, go install, Docker, or GitHub releases.
brew install logcliand cross-platform Loki release binaries
Ideal for LogQL verification, label discovery, and piping logs into jq or rg.
- Supports instant queries, range queries, and label/series inspection
Official Grafana Labs tool shipped inside the grafana/loki repository under AGPL-3.0-only.
- Maintained alongside Loki core releases
Documented in Grafana Loki docs, though flag details occasionally require checking logcli query --help.
- Official docs at grafana.com/docs/loki/latest/query/logcli/
Security, Auth & Guardrails
Reads LOKI_ADDR, LOKI_USERNAME, LOKI_PASSWORD, LOKI_BEARER_TOKEN, and LOKI_ORG_ID from environment variables or CLI flags; local self-hosted Loki may require no auth.
CLI is free (AGPL-3.0-only); Grafana Cloud Logs includes a free tier with volume-based pricing beyond quota.
# Grafana LogCLI Agent Rules - Always pass `--limit=N` and `--since` (default `1h`) on `logcli query` to avoid dumping massive log streams. - Use `-o jsonl --quiet` (or `-o raw --quiet`) for clean stdout parsing. - Do not invoke `logcli query --tail` synchronously without a bounded timeout.
Agent-Ready Command Recipes
Safe Read-Only Queries
logcli labels --quiet
Lists available log label keys from the configured Loki endpoint.
logcli query --output=jsonl --quiet --limit=50 '{app="api"} |= "error"' Fetches up to 50 matching log entries from the api app in machine-parseable JSONL.
Strengths for Agents
- + Strictly read-only query surface minimizes operational risk for SRE triage agents.
- +
--output=jsonl --quietand-o rawstream cleanly intojqor UNIX pipelines. - + Pure environment-variable configuration (
LOKI_ADDR,LOKI_BEARER_TOKEN) works seamlessly in CI.
Caveats & Pitfalls
- !
logcli query --tailblocks indefinitely until terminated. - ! AGPL-3.0-only licensing applies if redistributed as part of modified network services.