-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
dc9a555
commit f52c6ac
Showing
3 changed files
with
113 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
2024-09-09 09:28:30,608 - fastapi_app - INFO - GET /docs - Status: 200 - Time: 0.00s | ||
2024-09-09 09:28:44,955 - fastapi_app - INFO - GET /openapi.json - Status: 200 - Time: 0.04s | ||
2024-09-09 09:28:53,444 - fastapi_app - INFO - Handling root request | ||
2024-09-09 09:28:53,446 - fastapi_app - INFO - GET / - Status: 200 - Time: 0.00s | ||
2024-09-09 09:57:13,426 - fastapi_app - INFO - Uploading file with filename: amazon.pdf with file_id: Ren and metadata: {"source":"Earnings report"} | ||
2024-09-09 09:59:21,254 - fastapi_app - INFO - Uploading file with filename: amazon.pdf with file_id: Ren and metadata: {"source":"Earnings report"} | ||
2024-09-09 09:59:28,892 - fastapi_app - INFO - Processing list of documents of length: 38 | ||
2024-09-09 09:59:28,892 - fastapi_app - INFO - Sending batch 0 to 20 / 38 | ||
2024-09-09 09:59:28,892 - fastapi_app - INFO - Sending batch 20 to 38 / 38 | ||
2024-09-09 09:59:30,171 - fastapi_app - INFO - POST /document - Status: 200 - Time: 9.09s | ||
2024-09-09 10:02:43,033 - fastapi_app - INFO - Uploading list of links with metadata: | ||
2024-09-09 10:02:43,034 - fastapi_app - INFO - Uploading link(0/2: https://www.desiringgod.org/interviews/the-pitfalls-of-being-a-thinker with file_id: FirstID metadata: | ||
2024-09-09 10:02:48,930 - fastapi_app - INFO - Uploading link(1/2: https://www.desiringgod.org/interviews/teens-and-screens with file_id: 2ndID metadata: | ||
2024-09-09 10:02:49,247 - fastapi_app - INFO - Processing list of documents of length: 15 | ||
2024-09-09 10:02:49,247 - fastapi_app - INFO - Sending batch 0 to 15 / 15 | ||
2024-09-09 10:02:49,247 - fastapi_app - INFO - Processing list of documents of length: 29 | ||
2024-09-09 10:02:49,247 - fastapi_app - INFO - Sending batch 0 to 20 / 29 | ||
2024-09-09 10:02:49,248 - fastapi_app - INFO - Sending batch 20 to 29 / 29 | ||
2024-09-09 10:02:50,198 - fastapi_app - INFO - POST /links - Status: 200 - Time: 7.17s | ||
2024-09-09 10:04:14,144 - fastapi_app - INFO - Uploading list of links with metadata: | ||
2024-09-09 10:04:14,144 - fastapi_app - INFO - Uploading link(2/2: https://www.desiringgod.org/interviews/the-pitfalls-of-being-a-thinker with file_id: metadata: | ||
2024-09-09 10:04:14,875 - fastapi_app - INFO - Processing list of documents of length: 15 | ||
2024-09-09 10:04:14,876 - fastapi_app - INFO - Sending batch 0 to 15 / 15 | ||
2024-09-09 10:07:44,493 - fastapi_app - INFO - Uploading multiple files with metadata: | ||
2024-09-09 10:07:44,493 - fastapi_app - INFO - Uploading file in group of files (1/1) with filename: superbowl.txt | ||
2024-09-09 10:07:44,498 - fastapi_app - INFO - Processing list of documents of length: 39 | ||
2024-09-09 10:07:44,498 - fastapi_app - INFO - Sending batch 0 to 20 / 39 | ||
2024-09-09 10:07:44,499 - fastapi_app - INFO - Sending batch 20 to 39 / 39 | ||
2024-09-09 10:07:45,370 - fastapi_app - INFO - POST /documents - Status: 200 - Time: 0.95s | ||
2024-09-09 10:11:45,178 - fastapi_app - INFO - Uploading multiple files with metadata: | ||
2024-09-09 10:11:45,180 - fastapi_app - INFO - Uploading file in group of files (1/1) with filename: superbowl.txt | ||
2024-09-09 10:11:45,184 - fastapi_app - INFO - Processing list of documents of length: 39 | ||
2024-09-09 10:11:45,185 - fastapi_app - INFO - Sending batch 0 to 20 / 39 | ||
2024-09-09 10:11:45,185 - fastapi_app - INFO - Sending batch 20 to 39 / 39 | ||
2024-09-09 10:11:45,984 - fastapi_app - INFO - POST /documents - Status: 200 - Time: 0.88s | ||
2024-09-09 10:15:20,763 - fastapi_app - INFO - Uploading multiple files with metadata: | ||
2024-09-09 10:15:20,764 - fastapi_app - INFO - Uploading file in group of files (1/1) with filename: superbowl.txt | ||
2024-09-09 10:15:20,769 - fastapi_app - INFO - Processing list of documents of length: 39 | ||
2024-09-09 10:15:20,769 - fastapi_app - INFO - Sending batch 0 to 20 / 39 | ||
2024-09-09 10:15:20,769 - fastapi_app - INFO - Sending batch 20 to 39 / 39 | ||
2024-09-09 10:15:21,592 - fastapi_app - INFO - POST /documents - Status: 200 - Time: 0.90s | ||
2024-09-09 10:51:20,979 - fastapi_app - INFO - Uploading multiple files with metadata: | ||
2024-09-09 10:51:20,981 - fastapi_app - INFO - Uploading file in group of files (1/1) with filename: superbowl.txt | ||
2024-09-09 10:51:20,986 - fastapi_app - INFO - Processing list of documents of length: 39 | ||
2024-09-09 10:51:20,986 - fastapi_app - INFO - Sending batch 0 to 20 / 39 | ||
2024-09-09 10:51:20,987 - fastapi_app - INFO - Sending batch 20 to 39 / 39 | ||
2024-09-09 10:51:21,793 - fastapi_app - INFO - POST /documents - Status: 200 - Time: 0.88s |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import logging | ||
from fastapi import Request, Response | ||
from starlette.middleware.base import BaseHTTPMiddleware | ||
import time, os | ||
|
||
|
||
def setup_logger(name: str, level=logging.INFO): | ||
logger = logging.getLogger(name) | ||
env = os.getenv("DEBUG_MODE","false") | ||
if env.lower() == "true": | ||
logger.setLevel(level) | ||
else: | ||
logger.setLevel(0) | ||
formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s') | ||
|
||
console_handler = logging.StreamHandler() | ||
console_handler.setFormatter(formatter) | ||
logger.addHandler(console_handler) | ||
|
||
file_handler = logging.FileHandler(f"{name}.log") | ||
file_handler.setFormatter(formatter) | ||
logger.addHandler(file_handler) | ||
|
||
return logger | ||
def get_env_variable(var_name: str, default_value: str = None, required: bool = False) -> str: | ||
value = os.getenv(var_name) | ||
if value is None: | ||
if default_value is None and required: | ||
raise ValueError(f"Environment variable '{var_name}' not found.") | ||
return default_value | ||
return value | ||
|
||
class LogMiddleware(BaseHTTPMiddleware): | ||
def __init__(self, app, logger): | ||
super().__init__(app) | ||
self.logger = logger | ||
|
||
async def dispatch(self, request: Request, call_next): | ||
start_time = time.time() | ||
response = await call_next(request) | ||
process_time = time.time() - start_time | ||
self.logger.info(f"{request.method} {request.url.path} - Status: {response.status_code} - Time: {process_time:.2f}s") | ||
return response |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters