From 22b4ee68d9f55d28a70c10dce1f9f3fba27dbb7b Mon Sep 17 00:00:00 2001 From: Lili Date: Thu, 24 Nov 2022 16:56:23 +0100 Subject: [PATCH] add gunicorn logging, GUNICORN to config.py --- tlapbot/__init__.py | 9 ++++++++- tlapbot/default_config.py | 3 ++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/tlapbot/__init__.py b/tlapbot/__init__.py index 0e8edb9..5621a3b 100644 --- a/tlapbot/__init__.py +++ b/tlapbot/__init__.py @@ -1,4 +1,5 @@ import os +import logging from flask import Flask from apscheduler.schedulers.background import BackgroundScheduler from tlapbot.db import get_db @@ -7,7 +8,7 @@ from tlapbot.owncast_helpers import is_stream_live, give_points_to_chat def create_app(test_config=None): app = Flask(__name__, instance_relative_config=True) - + # ensure the instance folder exists try: os.makedirs(app.instance_path) @@ -24,6 +25,12 @@ def create_app(test_config=None): app.config.from_pyfile('config.py', silent=True) app.config.from_pyfile('redeems.py', silent=True) + # Make logging work for gunicorn-ran instances of tlapbot. + if app.config['GUNICORN'] is True: + gunicorn_logger = logging.getLogger('gunicorn.error') + app.logger.handlers = gunicorn_logger.handlers + app.logger.setLevel(gunicorn_logger.level) + # prepare webhooks and redeem dashboard blueprints from . import owncast_webhooks from . import owncast_redeem_dashboard diff --git a/tlapbot/default_config.py b/tlapbot/default_config.py index 2871227..f96f4ca 100644 --- a/tlapbot/default_config.py +++ b/tlapbot/default_config.py @@ -3,4 +3,5 @@ OWNCAST_ACCESS_TOKEN='' OWNCAST_INSTANCE_URL='http://localhost:8080' POINTS_CYCLE_TIME=600 POINTS_AMOUNT_GIVEN=10 -LIST_REDEEMS=False \ No newline at end of file +LIST_REDEEMS=False +GUNICORN=False \ No newline at end of file