aboutsummaryrefslogtreecommitdiffstats
path: root/bot/__init__.py
diff options
context:
space:
mode:
authorGravatar mathsman5133 <[email protected]>2018-10-12 10:29:11 +1100
committerGravatar mathsman5133 <[email protected]>2018-10-12 10:29:11 +1100
commit010cb21de026cd3021fa29fc38f838b754bd540c (patch)
tree73609ffc131e7aa76dc99dcd53286192696b86a2 /bot/__init__.py
parentFixed docstrings, add blank lines for readibility, method of finding last 10 ... (diff)
parentThe app was logging to the wrong directory. This is now fixed. Also silenced ... (diff)
Merge remote-tracking branch 'upstream/master' into candy-collection
Diffstat (limited to 'bot/__init__.py')
-rw-r--r--bot/__init__.py37
1 files changed, 37 insertions, 0 deletions
diff --git a/bot/__init__.py b/bot/__init__.py
new file mode 100644
index 00000000..c411deb6
--- /dev/null
+++ b/bot/__init__.py
@@ -0,0 +1,37 @@
+import logging.handlers
+import os
+from pathlib import Path
+
+
+# set up logging
+log_dir = Path("bot", "log")
+log_file = log_dir / "hackbot.log"
+os.makedirs(log_dir, exist_ok=True)
+
+# file handler sets up rotating logs every 5 MB
+file_handler = logging.handlers.RotatingFileHandler(
+ log_file, maxBytes=5*(2**20), backupCount=10)
+file_handler.setLevel(logging.DEBUG)
+
+# console handler prints to terminal
+console_handler = logging.StreamHandler()
+console_handler.setLevel(logging.INFO)
+
+# remove old loggers if any
+root = logging.getLogger()
+if root.handlers:
+ for handler in root.handlers:
+ root.removeHandler(handler)
+
+# Silence irrelevant loggers
+logging.getLogger("discord").setLevel(logging.ERROR)
+logging.getLogger("websockets").setLevel(logging.ERROR)
+
+# setup new logging configuration
+logging.basicConfig(
+ format='%(asctime)s - %(name)s %(levelname)s: %(message)s',
+ datefmt="%D %H:%M:%S",
+ level=logging.DEBUG,
+ handlers=[console_handler, file_handler]
+)
+logging.getLogger().info('Logging initialization complete')