diff options
author | 2018-02-18 01:59:50 +0100 | |
---|---|---|
committer | 2018-02-18 01:59:50 +0100 | |
commit | dac0822840ebe6672834a41b1065b3cbf17d217e (patch) | |
tree | b288b2772c48cc3ccd0db9a74440f8bda7b49fe6 /pysite/__init__.py | |
parent | Go back to using wss:// for the WS test (diff) |
Simple logging. (#16)
* Simple logging. I don't know if this will show up in the docker logs like inver wanted, so it probably needs testing in prod.
* log level via hasattr/getattr, basicConfig instead of custom handlers
* removing the empty string log call
Diffstat (limited to 'pysite/__init__.py')
-rw-r--r-- | pysite/__init__.py | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/pysite/__init__.py b/pysite/__init__.py index 9bad5790..3e7aad42 100644 --- a/pysite/__init__.py +++ b/pysite/__init__.py @@ -1 +1,18 @@ # coding=utf-8 +import logging +import os + + +# region Logging +# Get the log level from environment +log_level = os.environ.get("LOG_LEVEL", "info").upper() +formatter = logging.Formatter('[%(asctime)s] [%(levelname)s] %(message)s') + +if hasattr(logging, log_level): + log_level = getattr(logging, log_level) +else: + raise RuntimeError("LOG_LEVEL environment variable has an invalid value.") + +# This handler will ensure we log to stdout and stderr +logging.basicConfig(format=formatter, level=log_level) +# endregion |