aboutsummaryrefslogtreecommitdiffstats
path: root/pysite/__init__.py
diff options
context:
space:
mode:
authorGravatar Leon Sandøy <[email protected]>2018-04-16 19:57:33 +0200
committerGravatar Leon Sandøy <[email protected]>2018-04-16 19:57:33 +0200
commit14727cca8ab857b7893f9a6300218ca2743bcf0b (patch)
tree2d933a5661bca226b3c5aa94c88ddfc880a0bc64 /pysite/__init__.py
parentAdding some trace logging to the table init to figure out what's going wrong. (diff)
Adding the TRACE log level monkey patch from bot
Diffstat (limited to 'pysite/__init__.py')
-rw-r--r--pysite/__init__.py21
1 files changed, 20 insertions, 1 deletions
diff --git a/pysite/__init__.py b/pysite/__init__.py
index 82abf499..5a48c94d 100644
--- a/pysite/__init__.py
+++ b/pysite/__init__.py
@@ -2,7 +2,7 @@
import logging
import os
import sys
-from logging import StreamHandler
+from logging import Logger, StreamHandler
from logging.handlers import SysLogHandler
from logmatic import JsonFormatter
@@ -13,6 +13,25 @@ from pysite.logs import NonPicklingSocketHandler
# region Logging
# Get the log level from environment
+logging.TRACE = 5
+logging.addLevelName(logging.TRACE, "TRACE")
+
+
+def monkeypatch_trace(self, msg, *args, **kwargs):
+ """
+ Log 'msg % args' with severity 'TRACE'.
+
+ To pass exception information, use the keyword argument exc_info with
+ a true value, e.g.
+
+ logger.trace("Houston, we have an %s", "interesting problem", exc_info=1)
+ """
+ if self.isEnabledFor(logging.TRACE):
+ self._log(logging.TRACE, msg, args, **kwargs)
+
+
+Logger.trace = monkeypatch_trace
+
log_level = os.environ.get("LOG_LEVEL", "debug").upper()
if hasattr(logging, log_level):