Merge pull request 'The log format of the central storage has been adjusted so that it can actively write corresponding logs to the log files.' (#67) from Nicolas_service_hub into dev

Reviewed-on: freeleaps/freeleaps-service-hub#67
Reviewed-by: jingyao1991 <jingyao1991@noreply.gitea.freeleaps.mathmast.com>
This commit is contained in:
icecheng 2025-09-24 04:14:08 +00:00
commit 2a517fae34
5 changed files with 33 additions and 5 deletions

View File

@ -1,4 +1,4 @@
FROM python:3.10-slim-bullseye FROM python:3.12-slim
# docker settings # docker settings
ARG CONTAINER_APP_ROOT="/app" ARG CONTAINER_APP_ROOT="/app"

View File

@ -1,4 +1,4 @@
FROM python:3.10-slim-buster FROM python:3.12-slim
# docker settings # docker settings
ARG CONTAINER_APP_ROOT="/app" ARG CONTAINER_APP_ROOT="/app"

View File

@ -1,6 +1,7 @@
from backend.business.document_manager import ( from backend.business.document_manager import (
DocumentManager, DocumentManager,
) )
from common.log.module_logger import ModuleLogger
class DocumentHub: class DocumentHub:
@ -8,15 +9,22 @@ class DocumentHub:
self, self,
): ):
self.document_manager = DocumentManager() self.document_manager = DocumentManager()
self.module_logger = ModuleLogger(sender_id="DocumentHub")
return return
async def retrieve_document_info(self, document_id: str): async def retrieve_document_info(self, document_id: str):
return await self.document_manager.retrieve_document_info(document_id) await self.module_logger.log_info(f"Retrieving document info for ID: {document_id}")
result = await self.document_manager.retrieve_document_info(document_id)
await self.module_logger.log_info(f"Document info retrieved successfully for ID: {document_id}")
return result
async def read_document_file_as_http_media_data(self, document_id: str): async def read_document_file_as_http_media_data(self, document_id: str):
return await self.document_manager.read_document_file_as_http_media_data( await self.module_logger.log_info(f"Reading document as HTTP media for ID: {document_id}")
result = await self.document_manager.read_document_file_as_http_media_data(
document_id document_id
) )
await self.module_logger.log_info(f"Document media data read successfully for ID: {document_id}")
return result
async def upload_document( async def upload_document(
self, associated_with: str, file_name: str, file_data: bytes self, associated_with: str, file_name: str, file_data: bytes
@ -26,11 +34,16 @@ class DocumentHub:
file_name: the name of the file file_name: the name of the file
file (bytes): the file to be uploaded file (bytes): the file to be uploaded
""" """
return await self.document_manager.upload_file( await self.module_logger.log_info(f"Uploading document {file_name} for user {associated_with}")
result = await self.document_manager.upload_file(
associated_with, file_name, file_data associated_with, file_name, file_data
) )
await self.module_logger.log_info(f"Document upload completed for {file_name}, result: {result}")
return result
async def delete_documents(self, document_ids: list): async def delete_documents(self, document_ids: list):
await self.module_logger.log_info(f"Deleting documents: {document_ids}")
for document_id in document_ids: for document_id in document_ids:
await self.document_manager.delete_document(document_id) await self.document_manager.delete_document(document_id)
await self.module_logger.log_info(f"Documents deleted successfully: {document_ids}")
return return

View File

@ -1,10 +1,12 @@
from backend.services.document_service import DocumentService from backend.services.document_service import DocumentService
from backend.models.models import MediaType, DataFormat from backend.models.models import MediaType, DataFormat
from common.log.module_logger import ModuleLogger
class DocumentManager: class DocumentManager:
def __init__(self) -> None: def __init__(self) -> None:
self.document_service = DocumentService() self.document_service = DocumentService()
self.module_logger = ModuleLogger(sender_id="DocumentManager")
async def retrieve_document_info(self, document_id: str): async def retrieve_document_info(self, document_id: str):
await self.document_service.load_document(document_id=document_id) await self.document_service.load_document(document_id=document_id)

View File

@ -12,6 +12,7 @@ from webapi.providers import probes
from webapi.providers import metrics from webapi.providers import metrics
from .freeleaps_app import FreeleapsApp from .freeleaps_app import FreeleapsApp
from common.config.app_settings import app_settings from common.config.app_settings import app_settings
from common.log.module_logger import ModuleLogger
def create_app() -> FastAPI: def create_app() -> FastAPI:
@ -20,6 +21,10 @@ def create_app() -> FastAPI:
app = FreeleapsApp() app = FreeleapsApp()
register_logger() register_logger()
# Create application logger for startup logging
app_logger = ModuleLogger(sender_id="ApplicationBootstrap")
register(app, exception_handler) register(app, exception_handler)
register(app, database) register(app, database)
register(app, router) register(app, router)
@ -37,6 +42,14 @@ def create_app() -> FastAPI:
if app_settings.METRICS_ENABLED: if app_settings.METRICS_ENABLED:
register(app, metrics) register(app, metrics)
# Log application startup completion
import asyncio
async def log_startup():
await app_logger.log_info("Central Storage application initialized successfully")
# Run the async logging
asyncio.create_task(log_startup())
return app return app