2016-07-13 06:31:09 +00:00
|
|
|
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"]
|
2016-07-13 23:42:17 +00:00
|
|
|
data = event.get("data")
|
2016-07-13 06:31:09 +00:00
|
|
|
with open("bot.log", "a") as log_file:
|
2016-07-13 23:42:17 +00:00
|
|
|
log_file.write("%s [%s] %s\n" % (timestamp, log_level,
|
2016-07-13 06:31:09 +00:00
|
|
|
message))
|
2016-07-13 23:42:17 +00:00
|
|
|
if data:
|
|
|
|
log_file.write("%s\n" % data)
|