Skip to content

Commit

Permalink
tweak
Browse files Browse the repository at this point in the history
  • Loading branch information
ckuhtz committed Jul 16, 2024
1 parent 0a87ab6 commit 17d9e89
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 12 deletions.
26 changes: 17 additions & 9 deletions api/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,6 @@
from routers.test.operations import router as test_router


# logger = logging.getLogger('uvicorn.error')

logger = logging.getLogger(__name__)
# logger.setLevel(logging.DEBUG)
stream_handler = logging.StreamHandler(sys.stdout)
log_formatter = logging.Formatter("%(asctime)s [%(processName)s: %(process)d] [%(threadName)s: %(thread)d] [%(levelname)s] %(name)s: %(message)s")
stream_handler.setFormatter(log_formatter)
logger.addHandler(stream_handler)

# Define API app as 'api'

Expand All @@ -31,9 +23,25 @@

# see https://fastapi.tiangolo.com/deployment/docker/#replication-number-of-processes for comment on worker counts

# logger = logging.getLogger('uvicorn.error')

logger = logging.getLogger(__name__)
stream_handler = logging.StreamHandler(sys.stdout)
log_formatter = logging.Formatter("%(asctime)s [%(processName)s: %(process)d] [%(threadName)s: %(thread)d] [%(levelname)s] %(name)s: %(message)s")
stream_handler.setFormatter(log_formatter)
logger.addHandler(stream_handler)

# check env and use defaults if not present

env = check_env_vars(logger=logger)
env = check_env_vars()

# set logger level based on what we got back

logger.setLevel(env['LOG_LEVEL'])

# dump environment we care about

logger.info(env)

# add REST routes

Expand Down
4 changes: 1 addition & 3 deletions api/tooling/check_env_vars.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from logging import Logger


def check_env_vars(logger: Logger) -> Dict:
def check_env_vars() -> Dict:
"""
Checks if environment variables we care about are present.
If so, accept them.
Expand Down Expand Up @@ -41,9 +41,7 @@ def check_env_vars(logger: Logger) -> Dict:
for var in vars:
if var in all_env_vars:
env[var] = all_env_vars[var]
logger.info(f'{var} = \'{env[var]}\'')
else:
env[var] = var_defaults[var]
logger.info(f'{var} = \'{env[var]}\' (default)')

return env

0 comments on commit 17d9e89

Please sign in to comment.