+class Log:
+
+ def __init__(self, chandir, nickname, username, channel, rmlogs):
+ self.nickname = nickname
+ self.username = username
+ self.channel = channel
+ self.chandir = chandir
+ self.rmlogcycle = rmlogs
+ self.rawlogdir = chandir + "raw_logs/"
+ self.logdir = chandir + "logs/"
+ if not os.path.exists(self.logdir):
+ os.makedirs(self.logdir)
+ if not os.path.exists(self.rawlogdir):
+ os.makedirs(self.rawlogdir)
+
+ def log(self, line, sent=False):
+ identity = ""
+ separator = " > "
+ if sent:
+ separator = " < "
+ line = Line(line)
+ line.sender = self.nickname
+ identity = self.username + "@localhost"
+ else:
+ if type(line) == str:
+ line = Line(line)
+ now = datetime.datetime.utcnow()
+ form = "%Y-%m-%d %H:%M:%S UTC"
+ write_to_file(self.rawlogdir + now.strftime("%Y-%m-%d") + ".txt", "a",
+ now.strftime(form) + separator + line.line + "\n")
+ to_log = irclog.format_logline(line, self.channel, identity)
+ if to_log != None:
+ write_to_file(self.logdir + now.strftime("%Y-%m-%d") + ".txt", "a",
+ now.strftime(form) + " " + to_log + "\n")
+
+ def rmlogs(self):
+ if self.rmlogcycle > 0:
+ for f in os.listdir(self.logdir):
+ f = os.path.join(self.logdir, f)
+ if os.path.isfile(f) and \
+ os.stat(f).st_mtime < time.time() - self.rmlogcycle:
+ os.remove(f)
+
+ def separator_line(self):
+ now = datetime.datetime.utcnow()
+ write_to_file(self.logdir + now.strftime("%Y-%m-%d") + ".txt", "a",
+ "-----------------------\n")
+
+