main.py 976 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. # -*- coding: utf-8 -*-
  2. import logging
  3. from functools import lru_cache
  4. from pathlib import Path
  5. import uvicorn
  6. from fastapi import FastAPI, Depends
  7. from loguru import logger
  8. from app.api.routers import targets, equipment, space
  9. from app.core.config import LoggerSettings
  10. from app.core.logger import InterceptHandler
  11. logger_settings = LoggerSettings()
  12. logging.getLogger().handlers = [InterceptHandler()]
  13. logger.add(Path(logger_settings.logs_dir, 'env_fastapi.log'), level='INFO', rotation='00:00', encoding='utf-8')
  14. app = FastAPI()
  15. app.include_router(targets.router, prefix='/target')
  16. app.include_router(space.router, prefix='/room')
  17. app.include_router(equipment.router, prefix='/equip')
  18. @lru_cache()
  19. def get_settings():
  20. return LoggerSettings()
  21. @app.get("/info")
  22. async def info(settings: LoggerSettings = Depends(get_settings)):
  23. return {
  24. 'logs_dir': settings.logs_dir
  25. }
  26. if __name__ == '__main__':
  27. uvicorn.run(app, host='0.0.0.0', port=8000)