Skip to content

About

Install logcli + two schema-agnostic shell shortcuts (lt/lg) for querying Grafana Loki from the terminal — plus the Windows VPN split-DNS and PowerShell 5.1 quoting gotchas

Topics

Resources

Code of conduct

Contributing

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

6 Commits

Folders and files

Repository files navigation

logcli-shortcuts

Query Grafana Loki from your terminal instead of the UI — and hand it to a coding agent for
natural-language log search while troubleshooting. A one-command installer for logcli, plus two small shell functions for tailing and grepping logs.


Why

Loki's web UI is fine for exploring, but once you know what you're looking for, round-tripping through a browser for every query is slow. logcli gets you there from the terminal — this repo is the install step plus two tiny ergonomic wrappers (lt for tailing, lg for grepping) so you don't retype logcli query '{...}' --since=... --follow every time.

It's intentionally not tied to any particular label schema. lt/lg take a raw LogQL selector string, because label names (namespace, service_name, app, job, whatever) are entirely deployment-specific. You wire up your own one-word shortcuts for your own labels on top — see Layering your own shortcuts below.

Use it with a coding agent

This is the real reason to have logcli/lt/lg on your PATH rather than only using the Grafana UI: a coding agent with shell access (Claude Code, etc.) can query your logs directly as part of troubleshooting. Ask it something like "check the api service's logs for the last hour for anything related to this timeout" and it runs lg/logcli itself, reads the actual log lines, and reasons about them alongside your code — instead of you tabbing over to Grafana, copying log lines, and pasting them back in. Natural language in, real log context out, no context-switch.

Why this matters

The handful of characters lt and lg save you isn't the point, that's a nice-to-have at best. The real shift is what it unlocks for a coding agent: raw logcli on your PATH means it can go pull the actual log lines itself, mid-debug, instead of you copying them out of Grafana by hand.

One honest caveat: those log lines land in the agent's context right alongside your code. If anything in your logs is sensitive (tokens, customer data, internal hostnames), keep that in mind before pointing an agent at a wide-open selector.


Quick install

The only thing you need from your devops/infra team is your Loki server's URL (to set as LOKI_ADDR) — everything else below is self-serve.

Windows (PowerShell): paste this in a PowerShell window:

irm https://raw.githubusercontent.com/thisismairaj/logcli-shortcuts/master/install.ps1 | iex

It installs logcli to ~\bin, adds that to your PATH, optionally sets LOKI_ADDR, and adds the lt/lg functions to whichever PowerShell profile(s) you have (5.1 and/or 7). Safe to re-run — it skips anything already done. Open a new terminal afterward — PATH/env var changes don't apply to the one you ran it in.

macOS/Linux (bash/zsh):

curl -fsSL https://raw.githubusercontent.com/thisismairaj/logcli-shortcuts/master/install.sh | bash

Installs logcli via Homebrew (or tells you where to grab the binary if you don't have brew), optionally sets LOKI_ADDR, and appends the lt/lg functions to ~/.bashrc and ~/.zshrc.

Test with: logcli labels --since=24h


Usage

lt '<selector>' [since]           # tail: live-follow a selector, default since=5m
lg '<term>' '<selector>' [since]  # grep: search a selector for a term, default since=1h
lt '{namespace="backend-dev", service_name="api"}'
lt '{namespace="backend-dev", service_name="api"}' 15m

lg "error" '{namespace="backend-dev"}'
lg "timeout" '{namespace="backend-dev", service_name="worker"}' 6h

Both are thin wrappers around logcli query — anything logcli itself supports (--limit, --output, etc.) works by passing it straight to logcli query yourself when lt/lg aren't enough.


Layering your own shortcuts

lt/lg are deliberately generic. If you query the same two or three services constantly, wrap them in your own one-word functions, in your own shell config:

# PowerShell profile
function adt { lt '{namespace="myorg-backend-dev", service_name="myorg-api"}' }
function ast { lt '{namespace="myorg-backend-stag", service_name="myorg-api"}' }
# ~/.zshrc / ~/.bashrc
adt() { lt '{namespace="myorg-backend-dev", service_name="myorg-api"}'; }
ast() { lt '{namespace="myorg-backend-stag", service_name="myorg-api"}'; }

Uninstall

Remove the # >>> logcli-shortcuts >>> ... # <<< logcli-shortcuts <<< block from your shell profile(s), and delete ~\bin\logcli.exe (Windows) or brew uninstall logcli (macOS).


License

MIT

About

Install logcli + two schema-agnostic shell shortcuts (lt/lg) for querying Grafana Loki from the terminal — plus the Windows VPN split-DNS and PowerShell 5.1 quoting gotchas

Topics

Resources

Code of conduct

Contributing

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages