Logging Module

The Logging module provides structured JSON logs, automatic request-response duration tracing, and an in-memory ring buffer that feeds live server console output directly to the admin dashboard.

Setup & Basic Usage

Register the LoggingModule with the Vorte application. In development, it prints logs in a human-readable format; in production, it switches automatically to structured JSON strings.

app.py
python
Copied!
1from vorte import Vorte, LoggingModule
2
3app = Vorte()
4app.register(LoggingModule(level="INFO"))

Logging in Controllers

Import and use the shared logger to write context-aware messages inside your API route handlers.

user_controller.py
python
Copied!
1from vorte import Controller, route, success_response
2from vorte.modules.logging import logger
3
4class UserController(Controller):
5 @route.get("/users/{user_id}")
6 async def get_user(self, user_id: str):
7 logger.info(f"Fetching user details", extra={"user_id": user_id})
8
9 user_data = {"id": user_id, "name": "Vorte Developer"}
10
11 logger.debug("User details loaded successfully", extra={"user": user_data})
12 return success_response(data=user_data)

Dashboard Live Console & Ring Buffer

The Logging module maintains an in-memory log buffer via the RingBufferHandler. It intercepts logs produced by the root logger as well as third-party packages, specifically capturing logs from uvicorn, fastapi, and vorte namespace libraries:

  • Ring Buffer Capacity: Holds up to the last 1000 logs in memory by default.
  • Log Interception: Even if the LoggingModule isn't registered, the DashboardModule will lazily attach the RingBufferHandler to Named Python Loggers so logs are still captured.
  • Log Format: Log entries are retained with fields for `timestamp`, `level`, `message`, `logger` name, and `module` name for clean rendering in the logs terminal.

Configuration Options

.env
bash
Copied!
1LOG_LEVEL=INFO
2LOG_FORMAT=json # Options: text, json
3LOG_BUFFER_CAPACITY=1000 # Maximum log lines to buffer for the dashboard
Stay in the loop

Get Vorte release notes, module guides, and developer deep-dives. No spam — unsubscribe anytime.