diff --git a/pds_doi_service/api/__main__.py b/pds_doi_service/api/__main__.py index 07b0824c..178f91c3 100755 --- a/pds_doi_service/api/__main__.py +++ b/pds_doi_service/api/__main__.py @@ -6,6 +6,8 @@ # California Institute of Technology. # +import logging + import connexion from flask_cors import CORS from waitress import serve @@ -14,6 +16,8 @@ from pds_doi_service.core.util.config_parser import DOIConfigUtil from pds_doi_service.core.util.general_util import get_logger +logging.basicConfig(level=logging.INFO) + def main(): """ @@ -22,8 +26,18 @@ def main(): The API connexion application is created using the swagger definition and fed to a waitress server instance. """ + logger = logging.getLogger(__name__) + + logger.info('Starting PDS DOI Service API') + config = DOIConfigUtil().get_config() + # Now that we've parsed config, we can fully set up logging + logger = get_logger(__name__) + logging_level = config.get('OTHER', 'logging_level', fallback='info') + + logger.info(f'Logging system configured at level {logging_level}') + app = connexion.App(__name__, specification_dir='swagger/') CORS(app.app) app.app.json_encoder = encoder.JSONEncoder @@ -39,13 +53,15 @@ def main(): pythonic_params=True) # Set the log level of waitress to match the configured level - logging_level = config.get('OTHER', 'logging_level', fallback='info') - logger = get_logger('waitress') + get_logger('waitress') logger.info(f'Waitress logging configured at level {logging_level}') - serve(app, - host=config.get('OTHER', 'api_host', fallback='0.0.0.0'), - port=config.get('OTHER', 'api_port', fallback=8080)) + try: + serve(app, + host=config.get('OTHER', 'api_host', fallback='0.0.0.0'), + port=config.get('OTHER', 'api_port', fallback=8080)) + except KeyboardInterrupt: + logger.info('Stopping PDS DOI Service API') if __name__ == '__main__':