Accessing Loki logs using LogCLI
How does developers like to access logs? common answer is command line with rich filtering capabilities.
This post to show how to access logs from your Loki server if you are using it as your Log solution.
What is Loki?
Loki is prometheus style log solution for cloud native architecture Loki project was started by Grafana Labs and with the intent to co-relate your matrices with log to get best out of it. Loki holds Apache 2 license and originally announced at KubeCon Seattle 2018.
Instructions — to Download and Setup LogCLI
Mac
wget https://github.com/grafana/loki/releases/download/v1.4.1/logcli-darwin-amd64.zipunzip logcli-darwin-amd64.zip mv logcli-darwin-amd64 /usr/local/bin/logcli rm logcli-darwin-amd64.zip
Linux
wget https://github.com/grafana/loki/releases/download/v1.4.1/logcli-linux-amd64.zipunzip logcli-darwin-amd64.zipmv logcli-darwin-amd64 /usr/local/bin/logclirm logcli-darwin-amd64.zip
Set Environment variable
export LOKI_ADDR=<YOUR_LOKI_SERVER_ADDRESS>
Examples — LogCLI Query
Learn more about LogQL here:
LogCLI help
logcli help
Check all available labels you can filter log with
logcli labelsOUTPUT >
__name__clustercontainer_namefilenamehostsourceswarm_serviceswarm_stack
Filter by given label
logcli labels cluster
Filter Log by specific Cluster
logcli query '{cluster="CLUSTER_NAME"}'
Filter Log by Swarm Stack and Tail
logcli query '{cluster="CLUSTER_NAME", swarm_stack="traefik"}' --tail
Filter Log by Swarm Service
logcli query '{swarm_stack="SWARM_STACK_NAME"}'
Check all available query parameters
logcli query --help
Resources
Loki Project Home
Documentation
Loki & LogCLI Releases