diff options
author | Frederick Muriuki Muriithi | 2024-04-24 05:57:53 +0300 |
---|---|---|
committer | Frederick Muriuki Muriithi | 2024-04-24 06:09:03 +0300 |
commit | 06abdb22af872a8b909d53612283a33404359ba7 (patch) | |
tree | 05afa64152e0e2ab666a320dbf79c279d92335bd /gn2 | |
parent | 30879312326e4e0ac9c285c7db55b5c3c6f0e491 (diff) | |
download | genenetwork2-06abdb22af872a8b909d53612283a33404359ba7.tar.gz |
Setup logging
Add logging to genenetwork2
Diffstat (limited to 'gn2')
-rw-r--r-- | gn2/wqflask/__init__.py | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/gn2/wqflask/__init__.py b/gn2/wqflask/__init__.py index c77895c1..b42b45f1 100644 --- a/gn2/wqflask/__init__.py +++ b/gn2/wqflask/__init__.py @@ -1,6 +1,7 @@ """Entry point for flask app""" # pylint: disable=C0413,E0611 import os +import sys import time import logging import datetime @@ -66,8 +67,34 @@ def parse_ssl_key(app: Flask, keyconfig: str): app.config[keyconfig] = JsonWebKey.import_key(_sslkey.read()) +def dev_loggers(appl: Flask) -> None: + """Default development logging.""" + formatter = logging.Formatter( + fmt="[%(asctime)s] %(levelname)s in %(module)s: %(message)s") + stderr_handler = logging.StreamHandler(stream=sys.stderr) + stderr_handler.setFormatter(formatter) + appl.logger.addHandler(stderr_handler) + + root_logger = logging.getLogger() + root_logger.addHandler(stderr_handler) + root_logger.setLevel(appl.config.get("LOGLEVEL", "WARNING")) + + +def gunicorn_loggers(appl: Flask) -> None: + """Logging with gunicorn WSGI server.""" + logger = logging.getLogger("gunicorn.error") + appl.logger.handlers = logger.handlers + appl.logger.setLevel(logger.level) + +def setup_logging(appl: Flask) -> None: + """Setup appropriate logging""" + software, *_version_and_comments = os.environ.get( + "SERVER_SOFTWARE", "").split('/') + gunicorn_loggers(app) if software == "gunicorn" else dev_loggers(app) + app = Flask(__name__) +setup_logging(app) # See http://flask.pocoo.org/docs/config/#configuring-from-files # Note no longer use the badly named WQFLASK_OVERRIDES (nyi) |