A drop-in replacement for Graylog using your existing SQL database.
Project description
SQL LogFire 🔥
A lightweight, self-hosted logging system built on top of your existing SQL database.
SQL LogFire is a drop-in alternative to tools like Graylog or Datadog for small teams and startups. It stores logs using SQLAlchemy (sync engine only) and provides an embedded FastAPI dashboard to view and search logs in real time.
✨ Features
- ✅ Uses your existing SQL database (PostgreSQL, MySQL, SQLite)
- ✅ Non-blocking logging via background worker thread
- ✅ Zero external services (no Elasticsearch, Kafka, agents)
- ✅ Embedded FastAPI dashboard
- ✅ Simple API:
logfire.log("message") - ✅ Automatic table creation
- ✅ Search & time-based filtering
- ❌ No async engine (by design, for stability)
📦 Installation
pip install sql-logfire
Optional (PostgreSQL support)
pip install sql-logfire[postgres]
⚠️ Important Design Note
SQL LogFire supports ONLY synchronous SQLAlchemy engines
Async engines (asyncpg, create_async_engine) are not supported and will raise errors.
This is intentional:
- Logging happens in a background thread
- Sync engines are thread-safe and stable
- No
greenlet/ async context issues
🚀 Quick Start (FastAPI)
1️⃣ Create the Database Engine (SYNC)
from sqlalchemy import create_engine
DATABASE_URL = "postgresql+psycopg2://postgres:password@localhost:5432/postgres"
engine = create_engine(
DATABASE_URL,
pool_pre_ping=True,
future=True
)
2️⃣ Initialize LogFire
from sql_logfire.core import LogFire
logfire = LogFire(engine)
This will:
- Automatically create required tables
- Start a background worker thread
- Prepare the dashboard
3️⃣ Mount the Dashboard in FastAPI
from fastapi import FastAPI
from sql_logfire.integrations.fastapi import create_logfire_router
app = FastAPI()
app.include_router(
create_logfire_router(logfire),
prefix="/logfire",
tags=["LogFire"]
)
📍 Dashboard available at:
http://localhost:8000/logfire
4️⃣ Start Logging 🎉
@app.get("/")
def root():
logfire.log("User accessed root endpoint", level="INFO")
return {"status": "ok"}
@app.get("/error")
def error():
logfire.log("Critical payment failure detected!", level="ERROR")
return {"status": "error"}
🔍 Dashboard Features
-
View latest logs
-
Filter by:
- Log level
- Time window (last N minutes)
- Search query
-
Auto-refresh
-
Clean, minimal UI
No Swagger. No setup. Just /logfire.
🗄️ Supported Databases
| Database | Supported |
|---|---|
| SQLite | ✅ |
| PostgreSQL | ✅ |
| MySQL | ✅ |
| Async DBs | ❌ |
🧠 Why Sync Only?
Logging systems must be:
- Reliable
- Non-blocking
- Thread-safe
Async engines require an event loop and break in:
- Background threads
- WSGI / hybrid environments
- Sync frameworks
SQL LogFire chooses correctness over complexity.
🧹 Graceful Shutdown (Optional)
@app.on_event("shutdown")
def shutdown():
logfire.shutdown()
This ensures all queued logs are flushed before exit.
📚 Example Database URLS
SQLite
sqlite:///./logfire.db
PostgreSQL
postgresql+psycopg2://user:password@localhost:5432/db
MySQL
mysql+pymysql://user:password@localhost:3306/db
🧪 When Should You Use SQL LogFire?
✅ Internal tools ✅ MVPs & startups ✅ Self-hosted environments ✅ Compliance-sensitive data ✅ Teams avoiding SaaS logging costs
❌ Massive distributed tracing ❌ Billions of logs/day ❌ Fully async logging pipelines
🛣️ Roadmap
- Log retention policies
- Export logs (CSV / JSON)
- Auth for dashboard
- Metrics aggregation
- Alert rules
🧑💻 Author
Bittu Singh 📧 bittusinghtech@gmail.com 🔗 https://github.com/Bittu2903
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 sql_logfire-0.1.1.tar.gz.
File metadata
- Download URL: sql_logfire-0.1.1.tar.gz
- Upload date:
- Size: 6.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
94a706244874af417cc1b98a158a23ab3fbb31400e5ee128f716be39e24fefc2
|
|
| MD5 |
fea80995f01cb6c2a012155aabf5cef5
|
|
| BLAKE2b-256 |
8339d386eae1c59fa46aea1b8a792d1d10ce623d1180364e2004fad4acea267e
|
File details
Details for the file sql_logfire-0.1.1-py3-none-any.whl.
File metadata
- Download URL: sql_logfire-0.1.1-py3-none-any.whl
- Upload date:
- Size: 7.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2f88bda05c9d517951e4a144b1aa45e11c84ffc52284000d1591e7970016c393
|
|
| MD5 |
833b96b2ca518ec8837d2955d83ce327
|
|
| BLAKE2b-256 |
53f3bee32fa930384ece54d303e1e4b99450ce071ea2a573366a89bcc4964ed9
|