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:
@@ -21,6 +21,25 @@ from web.wrapper import url_for
|
|||||||
from modbus_tcp import ModbusTcp
|
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:
|
class ProxyState:
|
||||||
_is_up = False
|
_is_up = False
|
||||||
|
|
||||||
@@ -74,6 +93,11 @@ async def handle_client(reader: StreamReader, writer: StreamWriter, inv_class):
|
|||||||
await inv.local.ifc.server_loop()
|
await inv.local.ifc.server_loop()
|
||||||
|
|
||||||
|
|
||||||
|
@app.before_request
|
||||||
|
async def startup_app():
|
||||||
|
HypercornLogHndl.restore()
|
||||||
|
|
||||||
|
|
||||||
@app.after_serving
|
@app.after_serving
|
||||||
async def handle_shutdown(): # pragma: no cover
|
async def handle_shutdown(): # pragma: no cover
|
||||||
'''Close all TCP connections and stop the event loop'''
|
'''Close all TCP connections and stop the event loop'''
|
||||||
@@ -155,6 +179,8 @@ def main(): # pragma: no cover
|
|||||||
|
|
||||||
src_dir = os.path.dirname(__file__) + '/'
|
src_dir = os.path.dirname(__file__) + '/'
|
||||||
logging.config.fileConfig(src_dir + 'logging.ini')
|
logging.config.fileConfig(src_dir + 'logging.ini')
|
||||||
|
HypercornLogHndl.save()
|
||||||
|
|
||||||
logging.info(f'Server "{serv_name} - {version}" will be started')
|
logging.info(f'Server "{serv_name} - {version}" will be started')
|
||||||
logging.info(f'current dir: {os.getcwd()}')
|
logging.info(f'current dir: {os.getcwd()}')
|
||||||
logging.info(f"config_path: {args.config_path}")
|
logging.info(f"config_path: {args.config_path}")
|
||||||
|
|||||||
Reference in New Issue
Block a user