workaround: restore the hypercorn logger config

- quart/hyercorn overwrites the logger config.
  as a workaround we restore the config at the
  beginning of a request
This commit is contained in:
Stefan Allius
2025-05-05 08:23:41 +02:00
parent 4f6764e151
commit 4688e6a75b

View File

@@ -21,6 +21,25 @@ from web.wrapper import url_for
from modbus_tcp import ModbusTcp
class HypercornLogHndl:
access_hndl = []
error_hndl = []
@classmethod
def save(cls):
cls.access_hndl = logging.getLogger(
'hypercorn.access').handlers
cls.error_hndl = logging.getLogger(
'hypercorn.error').handlers
@classmethod
def restore(cls):
logging.getLogger(
'hypercorn.access').handlers = cls.access_hndl
logging.getLogger(
'hypercorn.error').handlers = cls.error_hndl
class ProxyState:
_is_up = False
@@ -74,6 +93,11 @@ async def handle_client(reader: StreamReader, writer: StreamWriter, inv_class):
await inv.local.ifc.server_loop()
@app.before_request
async def startup_app():
HypercornLogHndl.restore()
@app.after_serving
async def handle_shutdown(): # pragma: no cover
'''Close all TCP connections and stop the event loop'''
@@ -155,6 +179,8 @@ def main(): # pragma: no cover
src_dir = os.path.dirname(__file__) + '/'
logging.config.fileConfig(src_dir + 'logging.ini')
HypercornLogHndl.save()
logging.info(f'Server "{serv_name} - {version}" will be started')
logging.info(f'current dir: {os.getcwd()}')
logging.info(f"config_path: {args.config_path}")