Buidl Log Query - capture and query build/test logs with DuckDB
Project description
blq - Build Log Query
A CLI tool for capturing, querying, and analyzing build/test logs using DuckDB and
the duck_hunt extension. We pronouce
blq like "bleak", as in we have bleak outlook on the outcome of our hunt through the logs.
Features
- Capture logs from commands, files, or stdin
- Query directly with SQL or simple filter syntax
- Structured output in JSON, CSV, or Markdown for agent integration
- Event references for drilling into specific errors
- Command registry for reusable build/test commands
- Run metadata - captures git, environment, system, and CI context
- MCP server for AI agent integration
- 60+ log formats supported via duck_hunt extension
Installation
pip install blq-cli
Initialize in your project (installs duck_hunt extension):
blq init # Basic init
blq init --mcp # Also create .mcp.json for AI agents
blq init --detect --yes # Auto-detect and register build/test commands
blq init --project myapp --namespace myorg # Override project identification
Quick Start
# Query a log file directly
blq q build.log
blq q -s file_path,line_number,message build.log
# Filter with simple syntax
blq f severity=error build.log
blq f severity=error,warning file_path~main build.log
# Run and capture a command
blq run make -j8
blq run --json make test
# View recent errors
blq errors
# Drill into a specific error
blq event 1:3
blq context 1:3
Commands
Querying
| Command | Description |
|---|---|
blq query / blq q |
Query log files or stored events |
blq filter / blq f |
Filter with simple key=value syntax |
blq sql <query> |
Run arbitrary SQL |
blq shell |
Interactive SQL shell |
Capturing
| Command | Description |
|---|---|
blq run <cmd> |
Run registered command and capture output |
blq exec <cmd> |
Execute ad-hoc command and capture output |
blq import <file> |
Import existing log file |
blq capture |
Capture from stdin |
Viewing
| Command | Description |
|---|---|
blq errors |
Show recent errors |
blq warnings |
Show recent warnings |
blq event <ref> |
Show event details (e.g., blq event 1:3) |
blq context <ref> |
Show log context around event |
blq status |
Show status of all sources |
blq history |
Show run history |
CI Integration
| Command | Description |
|---|---|
blq ci check |
Compare errors against baseline, exit 0/1 for CI gates |
blq ci comment |
Post error summary as GitHub PR comment |
blq report |
Generate markdown report of build/test results |
blq watch |
Watch for file changes and auto-run commands |
Management
| Command | Description |
|---|---|
blq init |
Initialize .lq directory |
blq register |
Register a reusable command |
blq unregister |
Remove a registered command |
blq commands |
List registered commands |
blq prune |
Remove old logs |
blq formats |
List available log formats |
blq completions |
Generate shell completions (bash/zsh/fish) |
Query Examples
# Select specific columns
blq q -s file_path,line_number,severity,message build.log
# Filter with SQL WHERE clause
blq q -f "severity='error' AND file_path LIKE '%main%'" build.log
# Order and limit results
blq q -o "line_number" -n 10 build.log
# Output as JSON (great for agents)
blq q --json build.log
# Output as CSV
blq q --csv build.log
# Query stored events (no file argument)
blq q -f "severity='error'"
Filter Syntax
The blq filter command provides grep-like simplicity:
# Exact match
blq f severity=error build.log
# Multiple values (OR)
blq f severity=error,warning build.log
# Contains (LIKE)
blq f file_path~main build.log
# Not equal
blq f severity!=info build.log
# Invert match (like grep -v)
blq f -v severity=error build.log
# Count matches
blq f -c severity=error build.log
# Case insensitive
blq f -i message~undefined build.log
Structured Output for Agents
# JSON output with errors
blq run --json make
# Markdown summary
blq run --markdown make
# Quiet mode (no streaming, just results)
blq run --quiet --json make
Output includes event references for drill-down:
{
"run_id": 1,
"status": "FAIL",
"errors": [
{
"ref": "1:1",
"file_path": "src/main.c",
"line_number": 15,
"message": "undefined variable 'foo'"
}
]
}
Command Registry
Register frequently-used commands:
# Auto-detect commands from build files (Makefile, package.json, etc.)
blq init --detect --yes
# Or register manually
blq register build "make -j8" --description "Build project"
blq register test "pytest -v" --timeout 600
blq register format "black ." --no-capture # Skip log capture for fast commands
# Run by name
blq run build
blq run test
# Run without log capture (fast mode for CI/pre-commit)
blq run --no-capture format
# List registered commands
blq commands
Auto-detected build systems: Makefile, package.json (npm/yarn), pyproject.toml, Cargo.toml, go.mod, CMakeLists.txt, configure, build.gradle, pom.xml, Dockerfile, docker-compose.yml
Format auto-detection: When registering commands, blq automatically detects the appropriate log format based on the command (e.g., mypy → mypy_text, pytest → pytest_text).
CI Integration
blq provides commands for CI/CD pipeline integration:
# Check for new errors vs baseline (exits 1 if new errors found)
blq ci check # Auto-detect baseline from main/master
blq ci check --baseline main # Compare against specific branch
blq ci check --baseline 42 # Compare against run ID
blq ci check --fail-on-any # Fail if any errors (no baseline)
# Post error summary as PR comment (requires GITHUB_TOKEN)
blq ci comment # Create new comment
blq ci comment --update # Update existing blq comment
blq ci comment --diff --baseline main # Include diff vs baseline
# Generate markdown report
blq report # Report on latest run
blq report --baseline main # Include comparison
blq report --output report.md # Save to file
blq report --summary-only # Summary without error details
GitHub Actions Example
- name: Run tests
run: blq run test
- name: Check for regressions
run: blq ci check --baseline main
- name: Post results
if: github.event_name == 'pull_request'
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: blq ci comment --update --diff
Watch Mode
Automatically run commands when files change:
blq watch build # Watch and run 'build' on changes
blq watch test --debounce 500 # Custom debounce (ms)
blq watch lint --exclude "*.log,dist/*" # Exclude patterns
blq watch --once build # Run once then exit (for CI)
Run Metadata
Each blq run automatically captures execution context:
| Field | Description |
|---|---|
hostname |
Machine name |
platform |
OS (Linux, Darwin, Windows) |
arch |
Architecture (x86_64, arm64) |
git_commit |
Current commit SHA |
git_branch |
Current branch |
git_dirty |
Uncommitted changes present |
environment |
Captured env vars (PATH, VIRTUAL_ENV, etc.) |
ci |
CI provider info (auto-detected) |
Query metadata with SQL:
blq sql "SELECT hostname, git_branch, environment['VIRTUAL_ENV'] FROM blq_load_events()"
MCP Server
blq includes an MCP server for AI agent integration:
blq serve # stdio transport (Claude Desktop)
blq serve --transport sse # HTTP/SSE transport
Tools available: run, exec, query, errors, warnings, event, context, status, history, diff, register_command, unregister_command, list_commands
See MCP Guide for details.
Global Options
| Flag | Description |
|---|---|
-V, --version |
Show version number |
-F, --log-format |
Log format hint (default: auto) |
Python API
blq provides a fluent Python API for programmatic access:
from blq import LogStore, LogQuery
# Open the repository
store = LogStore.open()
# Query errors with chaining
errors = (
store.errors()
.filter(file_path="%main%")
.select("file_path", "line_number", "message")
.order_by("line_number")
.limit(10)
.df()
)
# Filter patterns
store.events().filter(severity="error") # exact match
store.events().filter(severity=["error", "warning"]) # IN clause
store.events().filter(file_path="%test%") # LIKE pattern
store.events().filter("line_number > 100") # raw SQL
# Query a log file directly (without storing)
events = (
LogQuery.from_file("build.log")
.filter(severity="error")
.df()
)
# Aggregations
store.events().group_by("file_path").count()
store.events().value_counts("severity")
See Python API Guide for full documentation.
Storage
Logs are stored as Hive-partitioned parquet files (zstd compressed):
.lq/
├── blq.duckdb # Database with pre-loaded SQL macros
├── logs/
│ └── date=2024-01-15/
│ └── source=build/
│ └── 001_make_103000.parquet
├── raw/ # Optional raw logs (--keep-raw)
├── commands.yaml # Registered commands
└── schema.sql # SQL schema reference
SQL Macros (blq_ prefix)
All SQL macros use the blq_ prefix:
# Direct DuckDB access
duckdb .lq/blq.duckdb "SELECT * FROM blq_status()"
duckdb .lq/blq.duckdb "SELECT * FROM blq_errors(20)"
duckdb .lq/blq.duckdb "SELECT * FROM blq_load_events() WHERE severity='error'"
| Macro | Description |
|---|---|
blq_load_events() |
All events from parquet files |
blq_load_runs() |
Aggregated run statistics |
blq_status() |
Quick status overview |
blq_errors(n) |
Recent errors (default: 10) |
blq_warnings(n) |
Recent warnings (default: 10) |
blq_history(n) |
Run history (default: 20) |
blq_diff(run1, run2) |
Compare errors between runs |
Documentation
See docs/ for detailed documentation:
License
MIT
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file blq_cli-0.3.0.tar.gz.
File metadata
- Download URL: blq_cli-0.3.0.tar.gz
- Upload date:
- Size: 160.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4ee462751ea7a4637fe77e91f2ef0c30db0378fe1bb095b84986ec8c8fdd0966
|
|
| MD5 |
bdf9bfb7c77155c73ee525dba082bdb1
|
|
| BLAKE2b-256 |
885316886882873dbb28ea0139e7df2c4ddb8cc426b36ee0d28c0fc32b7ab144
|
Provenance
The following attestation bundles were made for blq_cli-0.3.0.tar.gz:
Publisher:
publish.yml on teaguesterling/blq-cli
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
blq_cli-0.3.0.tar.gz -
Subject digest:
4ee462751ea7a4637fe77e91f2ef0c30db0378fe1bb095b84986ec8c8fdd0966 - Sigstore transparency entry: 779917575
- Sigstore integration time:
-
Permalink:
teaguesterling/blq-cli@9585736df088a9d0c7bc27351493bbf1ec160781 -
Branch / Tag:
refs/tags/v0.3.0 - Owner: https://github.com/teaguesterling
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@9585736df088a9d0c7bc27351493bbf1ec160781 -
Trigger Event:
release
-
Statement type:
File details
Details for the file blq_cli-0.3.0-py3-none-any.whl.
File metadata
- Download URL: blq_cli-0.3.0-py3-none-any.whl
- Upload date:
- Size: 85.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
571087bdab8490bc3a0b182a94d12d10f7e235a26d13f56f36beb04af4feb146
|
|
| MD5 |
2e9ff91e1e136d98cd6db11bef9fce88
|
|
| BLAKE2b-256 |
aa8170559a79c9e5624fc1039d74c84f1d48914f3b2885bed8243471ca9d24ec
|
Provenance
The following attestation bundles were made for blq_cli-0.3.0-py3-none-any.whl:
Publisher:
publish.yml on teaguesterling/blq-cli
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
blq_cli-0.3.0-py3-none-any.whl -
Subject digest:
571087bdab8490bc3a0b182a94d12d10f7e235a26d13f56f36beb04af4feb146 - Sigstore transparency entry: 779917577
- Sigstore integration time:
-
Permalink:
teaguesterling/blq-cli@9585736df088a9d0c7bc27351493bbf1ec160781 -
Branch / Tag:
refs/tags/v0.3.0 - Owner: https://github.com/teaguesterling
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@9585736df088a9d0c7bc27351493bbf1ec160781 -
Trigger Event:
release
-
Statement type: