Initial commit: LogHive centralized log management system

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
v6ole
2026-05-09 14:55:14 +08:00
commit abfd07331e
54 changed files with 3816 additions and 0 deletions
+65
View File
@@ -0,0 +1,65 @@
"""LogHive — Centralized Log Management System.
FastAPI application that receives, stores, searches and analyzes logs
from multiple Python projects.
"""
import logging
from contextlib import asynccontextmanager
from fastapi import FastAPI
from fastapi.middleware.cors import CORSMiddleware
from app.config import settings
from app.database import init_db, close_db
from app.api import logs, projects, alerts, dashboard
# ── Logging ────────────────────────────────────────────────────
logging.basicConfig(
level=logging.INFO if not settings.DEBUG else logging.DEBUG,
format="%(asctime)s [%(levelname)s] %(name)s: %(message)s",
)
logger = logging.getLogger(__name__)
# ── Lifecycle ──────────────────────────────────────────────────
@asynccontextmanager
async def lifespan(app: FastAPI):
"""Startup and shutdown lifecycle."""
logger.info("🚀 LogHive starting up...")
await init_db()
yield
logger.info("🛑 LogHive shutting down...")
await close_db()
# ── App ────────────────────────────────────────────────────────
app = FastAPI(
title="LogHive API",
description="Centralized log management system — ingest, search, monitor, and alert on logs from your Python services.",
version="0.1.0",
lifespan=lifespan,
)
app.add_middleware(
CORSMiddleware,
allow_origins=settings.CORS_ORIGINS,
allow_credentials=True,
allow_methods=["*"],
allow_headers=["*"],
)
# ── Routes ─────────────────────────────────────────────────────
app.include_router(logs.router)
app.include_router(projects.router)
app.include_router(alerts.router)
app.include_router(dashboard.router)
@app.get("/api/health")
async def health():
return {"status": "ok", "service": settings.SERVICE_NAME, "version": "0.1.0"}