Skip to content

Commit

Permalink
Improved the logger handling in pds_doi_service.api.__main__
Browse files Browse the repository at this point in the history
  • Loading branch information
Scott Collins committed Apr 13, 2021
1 parent 7b62c10 commit 870c83e
Showing 1 changed file with 21 additions and 5 deletions.
26 changes: 21 additions & 5 deletions pds_doi_service/api/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
# California Institute of Technology.
#

import logging

import connexion
from flask_cors import CORS
from waitress import serve
Expand All @@ -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():
"""
Expand All @@ -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
Expand All @@ -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__':
Expand Down

0 comments on commit 870c83e

Please sign in to comment.