Skip to content

Commit

Permalink
feat(api): store logging output to file
Browse files Browse the repository at this point in the history
Signed-off-by: Jordan Shatford <[email protected]>
  • Loading branch information
jordanshatford committed Nov 3, 2023
1 parent 3b02e7c commit 0862599
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
1 change: 1 addition & 0 deletions apps/api/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ sessions/
.env
.mypy_cache/
venv/
*.log*
18 changes: 18 additions & 0 deletions apps/api/app/main.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import logging
import os
import tomllib
from logging.handlers import RotatingFileHandler
from typing import Any

from fastapi import FastAPI
Expand All @@ -11,6 +13,22 @@
from .routers import session
from .session import session_manager


handler = RotatingFileHandler(
'output.log',
maxBytes=1024 * 1024 * 5, # 5 MB
backupCount=5,
)
logging.basicConfig(
format='[%(asctime)s] %(levelname)s ' +
' - %(name)s - %(module)s - %(funcName)s: %(message)s',
datefmt='%Y-%m-%d %H:%M:%S',
level=logging.WARNING,
handlers=[handler],
)
logging.getLogger('sse_starlette').setLevel(logging.ERROR)


# Read data from pyproject.toml file
pyproject_data: dict[str, Any] = {}
pyproject_path = os.path.join(
Expand Down

1 comment on commit 0862599

@vercel
Copy link

@vercel vercel bot commented on 0862599 Nov 3, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.