diff options
| author | 2018-06-06 21:02:26 +0100 | |
|---|---|---|
| committer | 2018-06-06 21:02:26 +0100 | |
| commit | 813816f8e4f4da62c6fddb6ce16ba5a0b45bdeba (patch) | |
| tree | 3bf1feda9ec847c18d88c377b5e0dbdb85aba8c9 /pysite | |
| parent | [CI] Tag builds with "docker" (diff) | |
Logging changes
* Log to .json file in debug mode, with textual stdout
* Log to .txt in production, with JSON stdout
* No more Papertrail
Diffstat (limited to 'pysite')
| -rw-r--r-- | pysite/__init__.py | 22 | ||||
| -rw-r--r-- | pysite/constants.py | 8 | ||||
| -rw-r--r-- | pysite/logs.py | 10 | 
3 files changed, 11 insertions, 29 deletions
| diff --git a/pysite/__init__.py b/pysite/__init__.py index 98e66630..62f7f906 100644 --- a/pysite/__init__.py +++ b/pysite/__init__.py @@ -1,12 +1,10 @@  import logging  import sys  from logging import Logger, StreamHandler -from logging.handlers import SysLogHandler  from logmatic import JsonFormatter -from pysite.constants import DATADOG_ADDRESS, DATADOG_PORT, PAPERTRAIL_ADDRESS, PAPERTRAIL_PORT -from pysite.logs import NonPicklingSocketHandler +from pysite.constants import DEBUG_MODE  # region Logging  # Get the log level from environment @@ -32,16 +30,18 @@ Logger.trace = monkeypatch_trace  log_level = logging.TRACE  logging_handlers = [] -if PAPERTRAIL_ADDRESS: -    logging_handlers.append(SysLogHandler(address=(PAPERTRAIL_ADDRESS, PAPERTRAIL_PORT))) +if DEBUG_MODE: +    logging_handlers.append(StreamHandler(stream=sys.stdout)) -if DATADOG_ADDRESS: -    datadog_handler = NonPicklingSocketHandler(host=DATADOG_ADDRESS, port=DATADOG_PORT) -    datadog_handler.formatter = JsonFormatter(datefmt="%b %d %H:%M:%S") +    json_handler = logging.FileHandler(filename="log.json", mode="w") +    json_handler.formatter = JsonFormatter() +    logging_handlers.append(json_handler) +else: +    logging_handlers.append(logging.FileHandler(filename="log.txt", mode="w")) -    logging_handlers.append(datadog_handler) - -logging_handlers.append(StreamHandler(stream=sys.stderr)) +    json_handler = logging.StreamHandler(stream=sys.stdout) +    json_handler.formatter = JsonFormatter() +    logging_handlers.append(json_handler)  logging.basicConfig(      format="%(asctime)s pd.beardfist.com Site: | %(name)35s | %(levelname)8s | %(message)s", diff --git a/pysite/constants.py b/pysite/constants.py index 806a6430..3177fe59 100644 --- a/pysite/constants.py +++ b/pysite/constants.py @@ -98,14 +98,6 @@ JAM_QUESTION_TYPES = [      "slider"  ] -# PaperTrail logging -PAPERTRAIL_ADDRESS = environ.get("PAPERTRAIL_ADDRESS") or None -PAPERTRAIL_PORT = int(environ.get("PAPERTRAIL_PORT") or 0) - -# DataDog logging -DATADOG_ADDRESS = environ.get("DATADOG_ADDRESS") or None -DATADOG_PORT = int(environ.get("DATADOG_PORT") or 0) -  # CSRF  CSRF = CSRFProtect() diff --git a/pysite/logs.py b/pysite/logs.py deleted file mode 100644 index e789b1ea..00000000 --- a/pysite/logs.py +++ /dev/null @@ -1,10 +0,0 @@ -from logging.handlers import SocketHandler - - -class NonPicklingSocketHandler(SocketHandler): -    def emit(self, record): -        try: -            s = self.formatter.format(record).encode() + b"\n" -            self.send(s) -        except Exception: -            self.handleError(record) | 
