main.py 856 B

12345678910111213141516171819202122232425262728293031323334353637
  1. # -*- coding: utf-8 -*-
  2. from pathlib import Path
  3. from functools import lru_cache
  4. import logging
  5. import uvicorn
  6. from fastapi import FastAPI, Depends
  7. from loguru import logger
  8. from app.api.routers import targets
  9. from app.core.logger import InterceptHandler
  10. from app.core.config import LoggerSettings
  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='/targets')
  16. @lru_cache()
  17. def get_settings():
  18. return LoggerSettings()
  19. @app.get("/info")
  20. async def info(settings: LoggerSettings = Depends(get_settings)):
  21. return {
  22. 'logs_dir': settings.logs_dir
  23. }
  24. if __name__ == '__main__':
  25. uvicorn.run(app, host='0.0.0.0', port=8000)