12345678910111213141516171819202122232425262728293031323334353637 |
- # -*- coding: utf-8 -*-
- from pathlib import Path
- from functools import lru_cache
- import logging
- import uvicorn
- from fastapi import FastAPI, Depends
- from loguru import logger
- from app.api.routers import targets
- from app.core.logger import InterceptHandler
- from app.core.config import LoggerSettings
- logger_settings = LoggerSettings()
- logging.getLogger().handlers = [InterceptHandler()]
- logger.add(Path(logger_settings.logs_dir, 'env_fastapi.log'), level='INFO', rotation='00:00', encoding='utf-8')
- app = FastAPI()
- app.include_router(targets.router, prefix='/targets')
- @lru_cache()
- def get_settings():
- return LoggerSettings()
- @app.get("/info")
- async def info(settings: LoggerSettings = Depends(get_settings)):
- return {
- 'logs_dir': settings.logs_dir
- }
- if __name__ == '__main__':
- uvicorn.run(app, host='0.0.0.0', port=8000)
|