A small logcli-style command-line tool for querying
Grafana Loki.
- Named profiles (
~/.config/loki-cli/config.json) with an active pointer LOKI_*environment-variable overrides- Pipe-friendly output (stdout = data, stderr = diagnostics,
SIGPIPEhandled) - Shell tab-completion for target names
- Single-file binaries for Linux & Windows (built in CI)
- Docker image usable in Kubernetes
Job/CronJob
Full documentation: https://bruno-laranjo.github.io/loki-cli/
git clone https://github.com/bruno-laranjo/loki-cli
cd loki-cli
make install
source .venv/bin/activate
loki-cli --helpPrebuilt binaries and Docker images are attached to each GitHub Release.
loki-cli login --url https://loki.example.com # or --token / --username
loki-cli labels
loki-cli target --count
loki-cli logs my-host --since 15m
loki-cli logs my-host -f # live tailManage several endpoints with profiles:
loki-cli config set --profile prod --url https://loki.prod --token "$TP"
loki-cli config set --profile dev --url https://loki.dev --token "$TD"
loki-cli config use prod
loki-cli --profile dev target --count # one-off overrideOverride anything via env for scripts / CI:
LOKI_URL=https://loki.example.com LOKI_TOKEN=... loki-cli target --countSee .env.example for all variables and precedence rules.
| Command | Purpose |
|---|---|
config |
set, unset, list, show, use, current, path |
login / logout / whoami |
Convenience wrappers over config |
labels |
List label names |
target |
List targets (values of a host-identifying label) |
logs |
Print or stream logs from a specific target |
Every command accepts -p / --profile NAME (falls back to $LOKI_PROFILE,
then the active profile). Every data command supports -o text|json
where sensible; logs also supports -o raw.
eval "$(_LOKI_CLI_COMPLETE=bash_source loki-cli)" # bash
eval "$(_LOKI_CLI_COMPLETE=zsh_source loki-cli)" # zsh
_LOKI_CLI_COMPLETE=fish_source loki-cli > ~/.config/fish/completions/loki-cli.fishThen loki-cli logs <TAB> completes with your Loki targets (60 s cache).
make install # editable install with dev+build+docs extras
make lint # ruff
make fmt # ruff --fix + format
make test # pytest
make build-binary # PyInstaller single-file exe → dist/
make docs # preview MkDocs site
make docker # build loki-cli:local imagePyInstaller can't cross-compile, so:
- Locally on your OS:
make build-binary - For Windows without a Windows box: push a
v*tag; the CI workflow publishes bothloki-cli-linux-x86_64andloki-cli-windows-x86_64.exeas GitHub Release assets.
See Building binaries.
docker pull <user>/loki-cli:latest
docker run --rm -e LOKI_URL=https://loki.example.com <user>/loki-cli:latest target --countOr build locally: make docker. See
Docker & Kubernetes for the
image tag scheme and how to enable the Docker Hub pipeline (set
DOCKERHUB_USERNAME and DOCKERHUB_TOKEN in repo secrets).
MIT — see LICENSE.