Skip to content

Commit

Permalink
Logging issue fix
Browse files Browse the repository at this point in the history
  • Loading branch information
sureshhewabi committed Nov 30, 2023
1 parent 63ebcb8 commit 22e9381
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 17 deletions.
3 changes: 3 additions & 0 deletions app/config/logging.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import logging.config

logging.config.fileConfig("logging.ini", disable_existing_loggers=False)
2 changes: 2 additions & 0 deletions app/routes/pdb.py
Original file line number Diff line number Diff line change
Expand Up @@ -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/<project_id>/sequences', methods=['GET'])
def sequences(project_id):
Expand Down
7 changes: 3 additions & 4 deletions app/routes/pride.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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
Expand Down Expand Up @@ -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'}


Expand Down
60 changes: 47 additions & 13 deletions logging.ini
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 22e9381

Please sign in to comment.