diff options
author | Frederick Muriuki Muriithi | 2023-04-21 05:22:05 +0300 |
---|---|---|
committer | Frederick Muriuki Muriithi | 2023-04-21 05:22:05 +0300 |
commit | 95f067a542424b76022595a74d660a7e84158f38 (patch) | |
tree | 17cf13f89eb58e2758e79c905b5777181d1334e1 /gn3/loggers.py | |
parent | 1fb5633042aa730d9467ad086196df99e60de151 (diff) | |
download | genenetwork3-95f067a542424b76022595a74d660a7e84158f38.tar.gz |
Setup module for logging
During development, we need logging sometimes to help with troubleshooting
problems. This commit provides a module to help set up the logging in a
separate module from the app module.
Diffstat (limited to 'gn3/loggers.py')
-rw-r--r-- | gn3/loggers.py | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/gn3/loggers.py b/gn3/loggers.py new file mode 100644 index 0000000..a74ae7e --- /dev/null +++ b/gn3/loggers.py @@ -0,0 +1,21 @@ +"""Setup loggers""" +import sys +import logging +from logging import StreamHandler + +# ========== Setup formatters ========== +# ========== END: Setup formatters ========== + +def loglevel(app): + """'Compute' the LOGLEVEL from the application.""" + return logging.DEBUG if app.config.get("DEBUG", False) else logging.WARNING + +def setup_app_handlers(app): + """Setup the logging handlers for the application `app`.""" + # ========== Setup handlers ========== + stderr_handler = StreamHandler(stream=sys.stderr) + stderr_handler.setLevel(loglevel(app)) + app.logger.addHandler(stderr_handler) + # ========== END: Setup handlers ========== + root_logger = logging.getLogger() + root_logger.addHandler(stderr_handler) |