Skip to content

Commit

Permalink
changed to json config file for logging and background async task now…
Browse files Browse the repository at this point in the history
… closes within the lifetime of app
  • Loading branch information
SparrowSurya committed Aug 25, 2024
1 parent e847a9c commit 4155893
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 35 deletions.
3 changes: 2 additions & 1 deletion api/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,10 @@ async def lifespan(app: FastAPI):
logger.info("Application lifespan started!")
interval = float(get_settings().interval)
db = SessionLocal()
asyncio.create_task(delete_expired_paste_task(interval, db))
delete_task = asyncio.create_task(delete_expired_paste_task(interval, db))
yield
db.close()
delete_task.cancel()
logger.info("Application lifespan ended!")


Expand Down
41 changes: 41 additions & 0 deletions log_config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
{
"version": 1,
"disable_existing_loggers": false,
"formatters": {
"default": {
"format": "%(asctime)s - %(name)s - %(levelname)s - %(message)s"
},
"access": {
"format": "%(asctime)s - %(name)s - %(levelname)s - %(message)s"
}
},
"handlers": {
"default": {
"formatter": "default",
"class": "logging.StreamHandler",
"stream": "ext://sys.stderr"
},
"access": {
"formatter": "access",
"class": "logging.StreamHandler",
"stream": "ext://sys.stdout"
}
},
"loggers": {
"uvicorn.error": {
"level": "INFO",
"handlers": ["default"],
"propagate": false
},
"uvicorn.access": {
"level": "INFO",
"handlers": ["access"],
"propagate": false
}
},
"root": {
"level": "DEBUG",
"handlers": ["default"],
"propagate": false
}
}
34 changes: 0 additions & 34 deletions log_config.yaml

This file was deleted.

12 changes: 12 additions & 0 deletions run.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import uvicorn

from api.main import app


def main():
log_config_file = "log_config.json"
uvicorn.run(app, log_config=log_config_file)


if __name__ == "__main__":
main()

0 comments on commit 4155893

Please sign in to comment.