use logger from flask

This commit is contained in:
Simon Pirkelmann 2022-02-04 22:40:14 +01:00
parent 856a72b0cc
commit 4470d2fb82

View File

@ -63,40 +63,15 @@ def create_super_admins(app, db, user_datastore, logger):
db.session.commit()
def setup_logging(app):
# set up logging for the web app
logger = logging.getLogger('webapp')
logger.setLevel(logging.INFO)
if app.config['LOG_FILE'] is not None:
ch = logging.FileHandler(app.config['LOG_FILE'])
ch.setLevel(logging.INFO)
else:
# create console handler and set level to debug
ch = logging.StreamHandler()
ch.setLevel(logging.DEBUG)
# create formatter
formatter = logging.Formatter(
'%(asctime)s - %(name)s - %(levelname)s - %(message)s')
# add formatter to ch
ch.setFormatter(formatter)
# add ch to logger
logger.addHandler(ch)
return logger
def create_app():
app = Flask(__name__)
app.config.from_object('imaginaerraum_door_admin.default_app_config.DefaultConfig')
app.config.from_envvar('APPLICATION_SETTINGS')
logger = setup_logging(app)
token_file = Path(app.config.get('TOKEN_FILE'))
if not token_file.exists():
logger.warning(
app.logger.warning(
f"Token file not found at {token_file.absolute()}. "
"An empty token file will be created."
)
@ -106,7 +81,7 @@ def create_app():
# door state via MQTT
app.door = DoorHandle(
token_file=token_file, mqtt_host=app.config['MQTT_HOST'],
nfc_socket=app.config['NFC_SOCKET'], logger=logger
nfc_socket=app.config['NFC_SOCKET'], logger=app.logger
)
# Mail Config