aboutsummaryrefslogtreecommitdiffstats
path: root/bot/__init__.py
diff options
context:
space:
mode:
Diffstat (limited to 'bot/__init__.py')
-rw-r--r--bot/__init__.py30
1 files changed, 30 insertions, 0 deletions
diff --git a/bot/__init__.py b/bot/__init__.py
new file mode 100644
index 00000000..8cbcd121
--- /dev/null
+++ b/bot/__init__.py
@@ -0,0 +1,30 @@
+import os
+import logging.handlers
+
+# set up logging
+
+log_dir = 'log'
+log_file = log_dir + os.sep + '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)
+
+# 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.info('Logging Process Started') \ No newline at end of file