Skip to content

LogChef CLI

The LogChef CLI is a powerful, high-performance terminal companion for LogChef. Built in Rust, it provides a fast and intuitive way to interact with your logs without leaving your terminal.

Blazing Fast

Written in Rust for minimal overhead and maximum performance when handling large log volumes.

Rich Highlighting

Beautiful syntax highlighting for log levels, dates, IPs, and custom keywords powered by tailspin.

Multi-Context

Manage multiple LogChef instances (dev/staging/prod) with kubectl-style context switching.

Secure Auth

Native support for OIDC PKCE flow, keeping your credentials secure while being easy to use.

Quick Start

Terminal window
# 1. Build the CLI
cd logchef/cli && cargo build --release
# 2. Add to PATH (or copy to /usr/local/bin)
export PATH="$PATH:$(pwd)/target/release"
# 3. Authenticate (auto-creates context from hostname)
logchef auth --server https://logs.example.com
# 4. Rename context to something friendly
logchef config rename logs.example.com prod
# 5. Set defaults so you don't need --team/--source every time
logchef config set team "my-team"
logchef config set source "nginx-logs"
# 6. Query logs
logchef query "level:error" --since 1h

Installation

Download the latest CLI release for your platform from GitHub Releases.

PlatformFile
Linux x86_64logchef-cli_<version>_linux-x86_64-musl.tar.gz
Linux ARM64logchef-cli_<version>_linux-aarch64-musl.tar.gz
macOS Apple Siliconlogchef-cli_<version>_macos-aarch64.tar.gz
macOS Intellogchef-cli_<version>_macos-x86_64.tar.gz
Windows x86_64logchef-cli_<version>_windows-x86_64.zip
Terminal window
# Example: Download and install (replace VERSION with actual version)
VERSION="0.1.2"
# Linux x86_64
curl -LO "https://github.com/mr-karan/logchef/releases/download/cli-v${VERSION}/logchef-cli_${VERSION}_linux-x86_64-musl.tar.gz"
tar xzf logchef-cli_${VERSION}_linux-x86_64-musl.tar.gz
sudo mv logchef /usr/local/bin/
# macOS Apple Silicon
curl -LO "https://github.com/mr-karan/logchef/releases/download/cli-v${VERSION}/logchef-cli_${VERSION}_macos-aarch64.tar.gz"
tar xzf logchef-cli_${VERSION}_macos-aarch64.tar.gz
sudo mv logchef /usr/local/bin/

From Source

If you prefer to build from source (requires Rust):

Terminal window
# Clone the repository
git clone https://github.com/mr-karan/logchef.git
cd logchef/cli
# Build the release binary
cargo build --release
# The binary is at cli/target/release/logchef
# Copy to your PATH:
sudo cp target/release/logchef /usr/local/bin/

Using Just

If you have just installed:

Terminal window
# Build release binary
just build-cli
# Build debug binary (faster compilation for testing)
just build-cli-debug
# Install to ~/.cargo/bin (must be in PATH)
just install-cli

Verify Installation

Terminal window
logchef --version
logchef --help

Authentication

The CLI supports two authentication methods: browser-based OIDC and API tokens.

Server Prerequisite (OIDC)

To use browser-based auth, configure a public OIDC client for the CLI and set it in the server config:

[oidc]
cli_client_id = "logchef-cli"

Your OIDC provider must allow loopback redirects for the CLI: http://127.0.0.1:19876/callback through http://127.0.0.1:19878/callback.

Browser-Based Login (OIDC)

For interactive use, authenticate via your browser:

Terminal window
logchef auth

This opens your browser to complete the OIDC login flow. The token is automatically saved to your config file.

Terminal window
# Check authentication status
logchef auth --status
# Log out (clear stored token)
logchef auth --logout

API Token Authentication

For scripts and automation, use an API token directly:

Terminal window
# Set token via environment variable
export LOGCHEF_AUTH_TOKEN="logchef_1_abc123..."
logchef query ""
# Or pass token as argument
logchef --token "logchef_1_abc123..." query ""
# Or save to config file
logchef config set auth.token "logchef_1_abc123..."

Generate API tokens from the LogChef web UI under your profile settings.

Command Reference

Query Logs

The query command allows you to execute LogChefQL queries directly from your terminal.

Terminal window
logchef query "level:error service:api" --since 1h

Options

OptionShorthandDescriptionDefault
--team-tTeam name (or ID)(from config)
--source-SSource name, database.table_name, or ID(from config)
--since-sTime range (e.g., “15m”, “1h”, “24h”)“15m”
--fromAbsolute start time (ISO 8601)
--toAbsolute end time (ISO 8601)
--limit-lMaximum number of results100
--outputOutput format (text, json, jsonl, table)text
--no-highlightDisable syntax highlightingfalse
--no-timestampHide timestamp from text outputfalse
--show-sqlDisplay the generated SQL queryfalse

Interactive Mode

When you run logchef query without specifying team, source, or query, and you’re in a terminal, the CLI enters interactive mode:

Terminal window
# Launch interactive mode
logchef query
# Prompts:
# ? Select team: [production, staging, dev]
# ? Select source: [nginx-logs, app-logs, api-logs]
# ? LogChefQL query: level:error

This is useful for quick exploration without remembering exact team/source names.

Query Examples

Terminal window
# Get all logs from the last 15 minutes
logchef query "" --team "production" --source "nginx-logs"
# Use database.table_name format (copy from UI)
logchef query "" --team "production" --source "logs.nomad_apps"
# Filter by field value
logchef query "status:500" --team "production" --source "nginx-logs"
# Multiple conditions (AND)
logchef query "method:POST status:403" --team "production" --source "nginx-logs"
# Search within a time range
logchef query "level:error" --since 1h --limit 50
# Hide timestamp from output
logchef query "level:error" --no-timestamp
# Output as JSON (returns object with logs, stats, columns)
logchef query "status:500" --output json | jq '.logs[] | .host'
# Output as JSON Lines (one JSON object per line, great for jq)
logchef query "" --output jsonl | jq '.msg'
# JSON output is jq-friendly - stats are included in the object
logchef query "" --output json | jq '{count: .count, time_ms: .stats.execution_time_ms}'
# Show the SQL that will be executed
logchef query "method:GET" --show-sql
# Use absolute time range
logchef query "" --from "2026-01-14T00:00:00Z" --to "2026-01-14T12:00:00Z"

Raw SQL Queries

The sql command lets you execute raw ClickHouse SQL directly. Unlike query, you have full control over the SQL—including time filters, aggregations, and joins.

Terminal window
logchef sql "SELECT * FROM logs.app WHERE level='error' LIMIT 10"

Options

OptionShorthandDescriptionDefault
--team-tTeam name (or ID)(from config)
--source-SSource name, database.table_name, or ID(from config)
--timeoutQuery timeout in seconds30
--outputOutput format (text, json, jsonl, table)text
--no-highlightDisable syntax highlightingfalse
--no-timestampHide timestamp from text outputfalse

Interactive Mode

Similar to query, the sql command supports interactive mode:

Terminal window
# Launch interactive mode
logchef sql
# Prompts:
# ? Select team: [production, staging, dev]
# ? Select source: [nginx-logs, app-logs, api-logs]
# ? SQL query: SELECT * FROM logs.app LIMIT 10

SQL Examples

Terminal window
# Simple query with time filter
logchef sql "SELECT * FROM logs.app WHERE _timestamp > now() - INTERVAL 1 HOUR LIMIT 100"
# Aggregation query
logchef sql "SELECT level, count() as cnt FROM logs.app WHERE _timestamp > now() - INTERVAL 1 DAY GROUP BY level"
# Read SQL from stdin (useful for complex queries)
cat query.sql | logchef sql -
# Or use heredoc
logchef sql - <<'EOF'
SELECT
toStartOfHour(_timestamp) as hour,
count() as requests,
countIf(status >= 500) as errors
FROM logs.nginx
WHERE _timestamp > now() - INTERVAL 24 HOUR
GROUP BY hour
ORDER BY hour
EOF
# Output as JSON
logchef sql "SELECT * FROM logs.app LIMIT 5" --output json
# Pipe to jq for processing
logchef sql "SELECT host, count() as cnt FROM logs.app GROUP BY host" --output jsonl | jq -s 'sort_by(.cnt) | reverse'

Example Output

When running a query, you’ll see highlighted output with colors:

2026-01-14T07:16:06.149Z host=172.100.86.236 method=PATCH status=410 bytes=45112
2026-01-14T07:16:06.049Z host=156.89.90.123 method=PATCH status=200 bytes=42092
2026-01-14T07:16:05.949Z host=217.33.68.177 method=POST status=403 bytes=10709

The highlighting includes:

  • Timestamps in magenta
  • IP addresses in cyan
  • URLs with protocol highlighting
  • Key=value pairs with dimmed keys
  • Numbers in cyan
  • Log levels color-coded (ERROR=red, WARN=yellow, INFO=green, DEBUG=blue)

Collections

The collections command lets you list and run saved collections (saved queries) from the LogChef web UI.

Terminal window
# List all collections for a source
logchef collections --team "production" --source "nginx-logs"
# Run a collection by name
logchef collections "Error Dashboard" --team "production" --source "nginx-logs"

Options

OptionShorthandDescriptionDefault
--team-tTeam name (or ID)(from config)
--source-SSource name, database.table_name, or ID(from config)
--since-sOverride time range (e.g., “15m”, “1h”, “24h”)(from collection)
--fromOverride absolute start time (ISO 8601)
--toOverride absolute end time (ISO 8601)
--limit-lOverride maximum number of results(from collection)
--varSet variable value (format: name=value)
--outputOutput format (text, json, jsonl, table)text
--no-highlightDisable syntax highlightingfalse
--no-timestampHide timestamp from text outputfalse
--show-sqlDisplay the generated SQL queryfalse

Interactive Mode

When run without arguments, enters interactive mode to select team, source, and collection:

Terminal window
# Launch interactive mode
logchef collections
# Prompts:
# ? Select team: [production, staging, dev]
# ? Select source: [nginx-logs, app-logs, api-logs]
# ? Select collection: [Error Dashboard, Slow Requests, Daily Summary]

Collection Examples

Terminal window
# List all collections
logchef collections -t "production" -S "nginx-logs"
# ID NAME TYPE DESCRIPTION
# 1 Error Dashboard logchefql Track 5xx errors
# 2 Slow Requests logchefql Requests > 1s
# Run a collection with default settings
logchef collections "Error Dashboard" -t "production" -S "nginx-logs"
# Override time range
logchef collections "Error Dashboard" -t 1 -S 1 --since 1h
# Set variables defined in the collection
logchef collections "Service Logs" --var service=api --var level=error
# Output as JSON
logchef collections "Error Dashboard" --output json | jq '.count'

Configuration

Manage your CLI settings using the config command.

Terminal window
# List all contexts
logchef config list
# Switch to a different context
logchef config use prod
# Show current context configuration
logchef config show
# Set configuration values for current context
logchef config set team 2
logchef config set source 2
logchef config set limit 50
logchef config set since "1h"
# Rename a context
logchef config rename logs.example.com prod
# Delete a context
logchef config delete old-server

Multi-Context Workflow

The CLI supports managing multiple LogChef instances (dev/staging/prod):

Terminal window
# Authenticate with prod (context auto-created from hostname)
logchef auth --server https://logs.company.com
logchef config rename logs.company.com prod
# Authenticate with dev
logchef auth --server http://localhost:8125
logchef config rename localhost dev
# List contexts
logchef config list
# CONTEXT SERVER AUTH
# * prod https://logs.company.com yes
# dev http://localhost:8125 yes
# Switch contexts
logchef config use dev
logchef query "level:debug"
# One-off query to different context
logchef --context prod query "level:error"

After authenticating, set your defaults to avoid typing --team and --source every time:

Terminal window
# Set defaults using team and source names
logchef config set team "my-team"
logchef config set source "nginx-logs"
# Now you can just run:
logchef query "level:error"

Configuration File

The configuration is stored at ~/.config/logchef/logchef.json:

{
"current_context": "prod",
"contexts": {
"prod": {
"server_url": "https://logs.example.com",
"timeout_secs": 30,
"token": "logchef_1_...",
"token_expires_at": "2026-02-14T00:00:00Z",
"defaults": {
"team": "production",
"source": "nginx-logs",
"limit": 100,
"since": "15m"
}
},
"dev": {
"server_url": "http://localhost:8125",
"timeout_secs": 30,
"token": "logchef_1_...",
"defaults": {}
}
},
"highlights": {
"custom_keywords": ["MYAPP", "CRITICAL"],
"disable_builtin": false,
"disabled_groups": [],
"custom_regexes": [
{
"pattern": "trace_id=[a-f0-9]+",
"color": "cyan",
"bold": false,
"italic": false
}
]
}
}

Configuration Options

SectionKeyDescription
current_contextActive contextName of the context to use by default
contexts.<name>.server_urlServer URLLogChef server address for this context
contexts.<name>.timeout_secsTimeoutHTTP request timeout in seconds
contexts.<name>.defaults.teamDefault teamTeam name (or ID) to use when --team is omitted
contexts.<name>.defaults.sourceDefault sourceSource name (or ID) to use when --source is omitted
contexts.<name>.defaults.limitDefault limitNumber of results when --limit is omitted
contexts.<name>.defaults.sinceDefault time rangeTime range when --since is omitted
highlights.custom_keywordsCustom keywordsWords to highlight in magenta
highlights.disable_builtinDisable defaultsTurn off built-in log level highlighting
highlights.disabled_groupsDisabled groupsList of highlighter groups to disable
highlights.custom_regexesCustom patternsRegex patterns with custom colors

Syntax Highlighting

LogChef CLI provides automatic syntax highlighting for common log patterns, powered by tailspin.

Built-in Highlighting

CategoryWhat’s HighlightedColors
Log LevelsERROR, FATAL, CRITICALRed (bold)
WARN, WARNINGYellow
INFOGreen
DEBUG, TRACEBlue
HTTP MethodsGETGreen (bold)
POSTYellow (bold)
PUT, PATCHMagenta (bold)
DELETERed (bold)
IdentifiersIPs, UUIDs, URLsCyan/Blue
TemporalDates, timestampsMagenta
DataNumbers, key=value pairsCyan
Booleanstrue, false, nullCyan

Ad-hoc Highlighting

Highlight specific words on-the-fly without changing your config:

Terminal window
# Highlight words in specific colors
logchef query "" --highlight red:ERROR,FAIL --highlight green:SUCCESS,OK
# Available colors: red, green, yellow, blue, magenta, cyan, white, black
# Also: bright_red, bright_green, bright_yellow, etc.

Disable Highlighters

Turn off specific highlighting groups for cleaner output:

Terminal window
# Disable date/time and number highlighting
logchef query "" --disable-highlight dates --disable-highlight numbers
# Available groups: dates, numbers, uuids, ips, urls, paths,
# pointers, keyvalue, quotes, json, keywords

Custom Regex Patterns

Add custom regex patterns in your config file:

{
"highlights": {
"custom_regexes": [
{
"pattern": "user_id=(\\d+)",
"color": "cyan",
"bold": true
},
{
"pattern": "request_id=[a-f0-9-]+",
"color": "magenta"
}
]
}
}

Disable All Highlighting

For piping to other tools or file output:

Terminal window
logchef query "" --no-highlight > logs.txt
logchef query "" --no-highlight | grep "ERROR"

Output Formats

JSON Format (--output json)

Returns a single JSON object containing logs, stats, and metadata:

{
"logs": [
{ "_timestamp": "2026-01-20T10:30:00Z", "level": "error", "msg": "..." },
{ "_timestamp": "2026-01-20T10:29:59Z", "level": "info", "msg": "..." }
],
"count": 2,
"stats": {
"execution_time_ms": 45,
"rows_read": 2,
"bytes_read": 1024
},
"query_id": "abc123-...",
"generated_sql": "SELECT * FROM ...",
"columns": [
{ "name": "_timestamp", "type": "DateTime64(3)" },
{ "name": "level", "type": "String" }
]
}

JSON Lines Format (--output jsonl)

Each log entry is output as a separate JSON object on its own line:

{"_timestamp":"2026-01-20T10:30:00Z","level":"error","msg":"Connection failed"}
{"_timestamp":"2026-01-20T10:29:59Z","level":"info","msg":"Request completed"}

Smart Output Detection

The CLI automatically detects if output is going to a terminal (TTY) or being piped:

  • Terminal: Shows stats summary (3 logs | 45ms | 3 rows read)
  • Piped: Suppresses stats for clean output to grep, jq, etc.
Terminal window
# Stats shown (terminal)
logchef query ""
# Output: [logs...]
# 3 logs | 45ms | 3 rows read
# Stats suppressed (piped)
logchef query "" | grep "error"
# Output: [matching lines only, no stats]

Global Options

The following options can be used with any command:

OptionEnvironment VariableDescription
--context / -cLOGCHEF_CONTEXTUse a specific context
--serverLOGCHEF_SERVER_URLOverride server URL (ephemeral)
--tokenLOGCHEF_AUTH_TOKENOverride API token
--debug / -dEnable detailed debug output

Environment Variables

For CI/CD pipelines and automation, you can configure the CLI entirely via environment variables:

Terminal window
# Option 1: Use a saved context
export LOGCHEF_CONTEXT="prod"
logchef query "level:error" --team "production" --source "app-logs"
# Option 2: Ephemeral mode (no saved context needed)
export LOGCHEF_SERVER_URL="https://logs.example.com"
export LOGCHEF_AUTH_TOKEN="logchef_1_abc123..."
logchef query "level:error" --team "production" --source "app-logs"

Scripting Examples

Export logs to file

Terminal window
logchef query "status:500" --output jsonl > errors.jsonl

Count errors with jq

Terminal window
logchef query "level:error" --output json | jq '.count'

Extract specific fields with jq

Terminal window
# Get all unique hosts from JSON output
logchef query "status:500" --output json | jq -r '.logs[].host' | sort -u
# Get all unique hosts from JSONL output
logchef query "status:500" --output jsonl | jq -r '.host' | sort -u
# Pretty print messages
logchef query "level:error" --output jsonl | jq '.msg'
# Get query stats
logchef query "" --output json | jq '.stats'

Pipe to grep for filtering

Terminal window
logchef query "" --no-highlight | grep -i "database"

Clean output without timestamps

Terminal window
logchef query "level:error" --no-timestamp --no-highlight > errors.txt

Loop through multiple sources

Terminal window
for source in "nginx-logs" "app-logs" "api-logs"; do
echo "=== Source: $source ==="
logchef query "level:error" --source "$source" --limit 5
done