Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move logging setup outside lifespan and db initialisation logic #309

Merged
merged 5 commits into from
Jun 4, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Move logging setup into its own module
Chiara Rasi committed Jun 4, 2024
commit c80d6d7265954a4a91dbda26ac3d368a3148a76e
14 changes: 14 additions & 0 deletions src/chanjo2/logger.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import logging

import uvicorn

LOG = logging.getLogger("uvicorn.access")


console_formatter = uvicorn.logging.ColourizedFormatter(
"{levelprefix} {asctime} : {message}", style="{", use_colors=True
)
if LOG.handlers:
LOG.handlers[0].setFormatter(console_formatter)
else:
logging.basicConfig()
13 changes: 1 addition & 12 deletions src/chanjo2/main.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,17 @@
import logging
import os
from contextlib import asynccontextmanager
from typing import List, Tuple

import uvicorn
from fastapi import FastAPI, status
from fastapi.staticfiles import StaticFiles

from chanjo2 import __version__
from chanjo2.dbutil import engine
from chanjo2.endpoints import cases, coverage, intervals, overview, report, samples
from chanjo2.logger import LOG
from chanjo2.models.sql_models import Base
from chanjo2.populate_demo import load_demo_data

LOG = logging.getLogger("uvicorn.access")
APP_ROUTER_TAGS: List[Tuple] = [
(intervals.router, "intervals"),
(coverage.router, "coverage"),
@@ -23,15 +21,6 @@
(overview.router, "overview"),
]

# Configure logging
console_formatter = uvicorn.logging.ColourizedFormatter(
"{levelprefix} {asctime} : {message}", style="{", use_colors=True
)
if LOG.handlers:
LOG.handlers[0].setFormatter(console_formatter)
else:
logging.basicConfig()


def create_db_and_tables():
Base.metadata.create_all(engine)