Skip to content

Commit

Permalink
refactor: Improve logging in main.py and add request logging middlewa…
Browse files Browse the repository at this point in the history
…re in __init__.py
  • Loading branch information
crushr3sist committed Jun 7, 2024
1 parent ee77f1c commit 6e342ba
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 3 deletions.
5 changes: 4 additions & 1 deletion main.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import logging
import random
import subprocess
import re
import subprocess

import uvicorn


Expand All @@ -24,4 +25,6 @@ def ip_addy():
port=8000,
reload=True,
use_colors=True,
log_level="info",
access_log=True,
)
18 changes: 17 additions & 1 deletion r3almX_backend/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from fastapi import FastAPI
from fastapi import FastAPI, Request, logger
from fastapi.middleware.cors import CORSMiddleware
from loguru import logger
from starlette.middleware.sessions import SessionMiddleware


Expand Down Expand Up @@ -58,3 +59,18 @@ def add_models(self):


r3almX = RealmX()


@r3almX.middleware("http")
async def log_requests(request: Request, call_next):
log_message = (
f"IP Address: {request.client.host} | "
f"User Agent: {request.headers.get('User-Agent')} | "
f"Referrer: {request.headers.get('Referrer')} | "
f"Request Method: {request.method} | "
f"Request URL: {request.url}"
)
logger.info(log_message)

response = await call_next(request)
return response
Binary file modified r3almX_backend/__pycache__/__init__.cpython-312.pyc
Binary file not shown.
4 changes: 3 additions & 1 deletion r3almX_backend/realtime_service/chat_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,10 @@ def get_user_from_token(token: str, db) -> User:


# 1711 south extension road
class MessageDigestion:
class DigestionBroker:
def __init__(self): ...


class RoomManager:
"""
Class to manage rooms and handle messaging between connected clients.
Expand Down

0 comments on commit 6e342ba

Please sign in to comment.