From ff3a785e1d0852e9c5f6cbad11a07ff4e5609632 Mon Sep 17 00:00:00 2001 From: jcao219 Date: Thu, 4 Aug 2011 00:49:45 -0500 Subject: [PATCH] forgot to add this important (logging module) file earlier --- wolfgamelogger.py | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 wolfgamelogger.py diff --git a/wolfgamelogger.py b/wolfgamelogger.py new file mode 100644 index 0000000..5e592a0 --- /dev/null +++ b/wolfgamelogger.py @@ -0,0 +1,38 @@ +import botconfig +from datetime import datetime + +class WolfgameLogger(object): + + def __init__(self, outfile, boutfile): + self.outfile = outfile + self.boutfile = boutfile + + self.logged = "" + self.barelogged = "" + + def log(self, message): + self.logged += datetime.utcnow().strftime("%Y-%m-%d %H:%M:%S ") + message + "\n" + + def logBare(self, *args): + self.barelogged += datetime.utcnow().strftime("%Y-%m-%d %H:%M:%S ") + " ".join(args) + "\n" + + def logChannelMessage(self, who, message): + self.logged += datetime.utcnow().strftime("%Y-%m-%d %H:%M:%S ") + "<{0}> {1}\n".format(who, message) + + def logCommand(self, who, cmd, rest): + self.logged += datetime.utcnow().strftime("%Y-%m-%d %H:%M:%S ") + "<{0}> {1}{2} {3}".format(who, botconfig.CMD_CHAR, cmd, rest) + "\n" + + def logMessage(self, message): + self.logged += datetime.utcnow().strftime("%Y-%m-%d %H:%M:%S ") + "<{0}> ".format(botconfig.NICK)+message+"\n" + + def saveToFile(self): + if self.outfile: + with open(self.outfile, "a") as lf: + lf.write(self.logged) + + if self.boutfile: + with open(self.boutfile, "a") as bl: + bl.write(self.barelogged) + + self.logged = "" + self.barelogged = "" \ No newline at end of file