From 76247aef538c35e1791239b912f7900495d3cc8d Mon Sep 17 00:00:00 2001 From: Sukhichev <143028979+Sukhichev@users.noreply.github.com> Date: Wed, 30 Aug 2023 08:38:28 +0300 Subject: [PATCH] Bugfixes (#806) * Fix fails on Python 3.7 The "encoding" argument of logging.basicConfig() was added in Python 3.9 This fix don't change any features. * Fix translation in _scaffold app The function T() must get translated string BEFORE any string interpolations. --- apps/_scaffold/controllers.py | 2 +- py4web/server_adapters.py | 25 +++++++++++-------------- 2 files changed, 12 insertions(+), 15 deletions(-) diff --git a/apps/_scaffold/controllers.py b/apps/_scaffold/controllers.py index cbce5087d..05e2d09a4 100644 --- a/apps/_scaffold/controllers.py +++ b/apps/_scaffold/controllers.py @@ -34,6 +34,6 @@ @action.uses("index.html", auth, T) def index(): user = auth.get_user() - message = T("Hello {first_name}".format(**user) if user else "Hello") + message = T("Hello {first_name}").format(**user) if user else T("Hello") actions = {"allowed_actions": auth.param.allowed_actions} return dict(message=message, actions=actions) diff --git a/py4web/server_adapters.py b/py4web/server_adapters.py index 2c8623a72..1b0953054 100644 --- a/py4web/server_adapters.py +++ b/py4web/server_adapters.py @@ -50,21 +50,18 @@ def logging_conf(level, log_file="server-py4web.log"): log_dir = os.environ.get("PY4WEB_LOGS", None) - log_param = ( - { - "filename": os.path.join(log_dir, log_file), - "filemode": "w", - "format": "%(message)s > %(threadName)s", - "encoding": "utf-8", - "level": check_level(level), + log_param = { + "format":"%(threadName)s | %(message)s", + "level":check_level(level), } - if log_dir - else { - "format": "%(message)s > %(threadName)s", - "encoding": "utf-8", - "level": check_level(level), - } - ) + + if log_dir: + h = logging.FileHandler( + os.path.join( log_dir, log_file), + mode = "w", + encoding = "utf-8" + ) + log_param.update( {"handlers": [h]} ) logging.basicConfig(**log_param)