Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
35 changes: 35 additions & 0 deletions medcat-service/medcat_service/log_config.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
log_config = {
"version": 1,
"disable_existing_loggers": False,
"formatters": {
"access": {
"()": "uvicorn.logging.AccessFormatter",
"fmt": '%(asctime)s [ACCESS] - %(client_addr)s - "%(request_line)s" %(status_code)s',
"use_colors": True,
},
"default": {
"()": "uvicorn.logging.DefaultFormatter",
"fmt": "%(asctime)s [%(levelname)s] %(name)s: %(message)s",
"use_colors": True,
},
},
"handlers": {
"access": {
"class": "logging.StreamHandler",
"formatter": "access",
},
"default": {
"formatter": "default",
"class": "logging.StreamHandler",
},
},
"loggers": {
# "root": {
# "handlers": ["default"],
# "level": settings.app_log_level,
# },
"uvicorn": {"handlers": ["default"], "level": "DEBUG", "propagate": True},
"uvicorn.access": {"handlers": ["access"], "level": "INFO", "propagate": False},
"uvicorn.error": {"level": "INFO", "propagate": False},
},
}
7 changes: 7 additions & 0 deletions medcat-service/medcat_service/main.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,20 @@
import logging
import logging.config

import gradio as gr
from fastapi import FastAPI, Request
from fastapi.responses import JSONResponse

from medcat_service.demo.gradio_demo import io
from medcat_service.dependencies import get_settings
from medcat_service.log_config import log_config
from medcat_service.routers import admin, health, process
from medcat_service.types import HealthCheckFailedException

settings = get_settings()

logging.config.dictConfig(log_config)

app = FastAPI(
title="MedCAT Service",
summary="MedCAT Service",
Expand Down Expand Up @@ -40,4 +46,5 @@ async def healthcheck_failed_exception_handler(request: Request, exc: HealthChec
# Only run this when directly executing `python main.py` for local dev.
import os
import uvicorn

uvicorn.run("medcat_service.main:app", host="0.0.0.0", port=int(os.environ.get("SERVER_PORT", 8000)))
2 changes: 1 addition & 1 deletion medcat-service/start_service_production.sh
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ if [ -z ${SERVER_WORKER_TIMEOUT+x} ]; then
echo "SERVER_WORKER_TIMEOUT is unset -- setting to default (sec): $SERVER_WORKER_TIMEOUT";
fi


# Note - SERVER_ACCESS_LOG_FORMAT is unused when worker-class is set to UvicornWorker
SERVER_ACCESS_LOG_FORMAT="%(t)s [ACCESS] %(h)s \"%(r)s\" %(s)s \"%(f)s\" \"%(a)s\""

# start the server
Expand Down
Loading