aboutsummaryrefslogtreecommitdiff
path: root/modules
diff options
context:
space:
mode:
authorGravatar jesopo2016-07-13 07:31:09 +0100
committerGravatar jesopo2016-07-13 07:31:09 +0100
commit369b784a0d35485a18a8dbced758d1740f9421ee (patch)
tree4cf620c92ad03701258434fd2ccbbf1b2ed4cc7d /modules
parentMerge branch 'master' of github.com:jesopo/bitbot (diff)
added logs.py and changed EventHook objects to know their name.
Diffstat (limited to 'modules')
-rw-r--r--modules/logs.py16
1 files changed, 16 insertions, 0 deletions
diff --git a/modules/logs.py b/modules/logs.py
new file mode 100644
index 00000000..5f58cbf3
--- /dev/null
+++ b/modules/logs.py
@@ -0,0 +1,16 @@
+import datetime
+
+class Module(object):
+ def __init__(self, bot):
+ bot.events.on("log").on("info", "warn", "error").hook(self.log)
+
+ def timestamp(self):
+ return datetime.datetime.utcnow().isoformat()+"Z"
+
+ def log(self, event):
+ log_level = event.name
+ timestamp = self.timestamp()
+ message = event["message"]
+ with open("bot.log", "a") as log_file:
+ log_file.write("%s [%s] %s" % (timestamp, log_level,
+ message))