diff --git a/app/config/logging.py b/app/config/logging.py new file mode 100644 index 0000000..cc84d01 --- /dev/null +++ b/app/config/logging.py @@ -0,0 +1,3 @@ +import logging.config + +logging.config.fileConfig("logging.ini", disable_existing_loggers=False) diff --git a/app/routes/pdb.py b/app/routes/pdb.py index 41ef0b1..2fce743 100644 --- a/app/routes/pdb.py +++ b/app/routes/pdb.py @@ -4,7 +4,9 @@ import json from xi_web_api import get_db_connection from xi_web_api.pdbdev import bp +from app.config.logging import logging +app_logger = logging.getLogger(__name__) @bp.route('/ws/projects//sequences', methods=['GET']) def sequences(project_id): diff --git a/app/routes/pride.py b/app/routes/pride.py index 8a4b49e..f84cac9 100644 --- a/app/routes/pride.py +++ b/app/routes/pride.py @@ -11,12 +11,12 @@ from sqlalchemy.orm import Session, joinedload import os import requests -import logging.config +from app.config.logging import logging import configparser from fastapi import FastAPI, HTTPException, Security from fastapi.security import APIKeyHeader -app_logger = logging.getLogger("uvicorn") # unify the uvicorn logging with fast-api logging +app_logger = logging.getLogger(__name__) api_key_header = APIKeyHeader(name="X-API-Key", auto_error=False) pride_router = APIRouter() config = configparser.ConfigParser() @@ -28,7 +28,6 @@ API_KEY = config.get('security', 'apikey') - def get_api_key(key: str = Security(api_key_header)) -> str: if key == API_KEY: return key @@ -243,7 +242,7 @@ def health(): A quick simple endpoint to test the API is working :return: Response with OK """ - app_logger.debug('Health check endpoint accessed') + app_logger.info('Health check endpoint accessed') return {'status': 'OK'} diff --git a/logging.ini b/logging.ini index a022ec2..0687788 100644 --- a/logging.ini +++ b/logging.ini @@ -1,27 +1,61 @@ +;[loggers] +;keys=root +; +;[handlers] +;keys=fileHandler, console_handler +; +;[formatters] +;keys=simpleFormatter +; +;[logger_root] +;level=DEBUG +;handlers=fileHandler, console_handler +; +;[handler_fileHandler] +;class=FileHandler +;level=DEBUG +;formatter=simpleFormatter +;args=('logs/xi_mzidentml_converter.log',) +; +;[handler_console_handler] +;class = StreamHandler +;level=DEBUG +;formatter = simpleFormatter +;args = (sys.stdout,) +; +;[formatter_simpleFormatter] +;format=%(asctime)s %(name)s - %(levelname)s:%(message)s + [loggers] -keys=root +keys=root,sampleLogger [handlers] -keys=fileHandler, console_handler +keys=consoleHandler,fileHandler [formatters] -keys=simpleFormatter +keys=sampleFormatter [logger_root] level=DEBUG -handlers=fileHandler, console_handler +handlers=consoleHandler,fileHandler -[handler_fileHandler] -class=FileHandler +[logger_sampleLogger] level=DEBUG -formatter=simpleFormatter -args=('logs/xi_mzidentml_converter.log',) +handlers=consoleHandler,fileHandler +qualname=sampleLogger +propagate=0 -[handler_console_handler] -class = StreamHandler +[handler_consoleHandler] +class=StreamHandler level=DEBUG -formatter = simpleFormatter -args = (sys.stdout,) +formatter=sampleFormatter +args=(sys.stdout,) + +[handler_fileHandler] +class=handlers.TimedRotatingFileHandler +level=DEBUG +formatter=sampleFormatter +args=('logs/xi_mzidentml_converter.log',) -[formatter_simpleFormatter] +[formatter_sampleFormatter] format=%(asctime)s %(name)s - %(levelname)s:%(message)s \ No newline at end of file