aboutsummaryrefslogtreecommitdiffstats
path: root/pysite/__init__.py
diff options
context:
space:
mode:
authorGravatar Gareth Coles <[email protected]>2018-03-13 15:08:54 +0000
committerGravatar Gareth Coles <[email protected]>2018-03-13 15:08:54 +0000
commit5fe8d6061b73e17ccf4feed85c71fcac0960c119 (patch)
tree569b781a135f39fdbc76d32338d150fa649eadaf /pysite/__init__.py
parentRemove unused import (diff)
Datadog TCP logging
Diffstat (limited to 'pysite/__init__.py')
-rw-r--r--pysite/__init__.py14
1 files changed, 12 insertions, 2 deletions
diff --git a/pysite/__init__.py b/pysite/__init__.py
index f807eaf4..cc80b075 100644
--- a/pysite/__init__.py
+++ b/pysite/__init__.py
@@ -5,22 +5,32 @@ from logging import StreamHandler
from logging.handlers import SysLogHandler
import sys
-from pysite.constants import PAPERTRAIL_ADDRESS, PAPERTRAIL_PORT
+from logmatic import JsonFormatter
+
+from pysite.constants import DATADOG_ADDRESS, DATADOG_PORT, PAPERTRAIL_ADDRESS, PAPERTRAIL_PORT
+from pysite.logs import NonPicklingSocketHandler
# region Logging
# Get the log level from environment
+
log_level = os.environ.get("LOG_LEVEL", "info").upper()
if hasattr(logging, log_level):
log_level = getattr(logging, log_level)
else:
- raise RuntimeError("LOG_LEVEL environment variable has an invalid value.")
+ raise RuntimeError(f"LOG_LEVEL environment variable has invalid value: {log_level}")
logging_handlers = []
if PAPERTRAIL_ADDRESS:
logging_handlers.append(SysLogHandler(address=(PAPERTRAIL_ADDRESS, PAPERTRAIL_PORT)))
+if DATADOG_ADDRESS:
+ datadog_handler = NonPicklingSocketHandler(host=DATADOG_ADDRESS, port=DATADOG_PORT)
+ datadog_handler.formatter = JsonFormatter(datefmt="%b %d %H:%M:%S")
+
+ logging_handlers.append(datadog_handler)
+
logging_handlers.append(StreamHandler(stream=sys.stderr))
logging.basicConfig(