-
Notifications
You must be signed in to change notification settings - Fork 0
/
config.py
27 lines (22 loc) · 921 Bytes
/
config.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
import logging
import os
root_logger = logging.getLogger()
LOG_LEVEL = os.environ.get('LOG_LEVEL', 'INFO').upper()
root_logger.setLevel(level=LOG_LEVEL)
# avoid double-logging by only configuring stdout stream handler when executing outside AWS
# why: https://stackoverflow.com/questions/50909824/getting-logs-twice-in-aws-lambda-function
aws_exec_env = os.environ.get('AWS_EXECUTION_ENV', None)
if not aws_exec_env:
handler = logging.StreamHandler()
formatter = logging.Formatter('%(asctime)s %(name)-12s %(levelname)-8s %(message)s')
handler.setFormatter(formatter)
root_logger.addHandler(handler)
def get_stage(environ: dict = os.environ) -> str:
"""
Get the delivery stage for this deployment, calculated from the `STAGE` environment variable.
:return the delivery stage, default 'dev'
"""
stage = environ.get('STAGE')
if not stage:
stage = "dev"
return stage