aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Gareth Coles <[email protected]>2018-03-10 19:07:10 +0000
committerGravatar Gareth Coles <[email protected]>2018-03-10 19:07:10 +0000
commitaea7afadaeba32fda6b383e11bc5b0917248867f (patch)
tree44f3148ab4f73bfc7c7fbe71a3235c4718bfb27b
parentUpdate bot.py (#31) (diff)
Logging with papertrail
-rw-r--r--bot/__init__.py21
-rw-r--r--bot/constants.py4
2 files changed, 25 insertions, 0 deletions
diff --git a/bot/__init__.py b/bot/__init__.py
index 95ea77d96..f17404572 100644
--- a/bot/__init__.py
+++ b/bot/__init__.py
@@ -1,8 +1,29 @@
# coding=utf-8
import ast
+import logging
+import sys
+from logging import StreamHandler
+from logging.handlers import SysLogHandler
import discord.ext.commands.view
+from bot.constants import PAPERTRAIL_ADDRESS, PAPERTRAIL_PORT
+
+
+logging_handlers = []
+
+if PAPERTRAIL_ADDRESS:
+ logging_handlers.append(SysLogHandler(address=(PAPERTRAIL_ADDRESS, PAPERTRAIL_PORT)))
+
+logging_handlers.append(StreamHandler(stream=sys.stderr))
+
+logging.basicConfig(
+ format="%(asctime)s pd.beardfist.com Bot: | %(name)15s | %(levelname)8s | %(message)s",
+ datefmt="%b %d %H:%M:%S",
+ level=logging.INFO,
+ handlers=logging_handlers
+)
+
def _skip_string(self, string: str) -> bool:
"""
diff --git a/bot/constants.py b/bot/constants.py
index 3c8fcc266..9878eb716 100644
--- a/bot/constants.py
+++ b/bot/constants.py
@@ -48,3 +48,7 @@ TAG_COOLDOWN = 60 # Per channel, per tag
GREEN_CHEVRON = "<:greenchevron:418104310329769993>"
RED_CHEVRON = "<:redchevron:418112778184818698>"
WHITE_CHEVRON = "<:whitechevron:418110396973711363>"
+
+# PaperTrail logging
+PAPERTRAIL_ADDRESS = os.environ.get("PAPERTRAIL_ADDRESS")
+PAPERTRAIL_PORT = int(os.environ.get("PAPERTRAIL_PORT", 0))