From: zonidjan Date: Tue, 13 Sep 2016 13:24:52 +0000 (-0500) Subject: log to file instead of stdout; logfile rotation X-Git-Url: https://jfr.im/git/erebus.git/commitdiff_plain/24b74bb30ce43c47dae6a7b93452012b07c505d6?hp=00ccae727aee9c6e5781c54d732c0dafd7cecb85 log to file instead of stdout; logfile rotation --- diff --git a/bot.py b/bot.py index 697638f..c753fe1 100644 --- a/bot.py +++ b/bot.py @@ -236,6 +236,7 @@ class BotConnection(object): #TODO: rewrite send() to queue def send(self, line): print "%05.3f %s [O] %s" % (time.time() % 100000, self.parent.nick, line) + sys.stdout.flush() # print (time.time() % 1466400000), self.parent.nick, '[O]', str(line) self._write(line) @@ -249,6 +250,7 @@ class BotConnection(object): while "\r\n" in self.buffer: pieces = self.buffer.split("\r\n", 1) print "%05.3f %s [I] %s" % (time.time() % 100000, self.parent.nick, pieces[0]) + sys.stdout.flush() # print (time.time() % 1460000000), self.parent.nick, '[I]', pieces[0] lines.append(pieces[0]) self.buffer = pieces[1] diff --git a/erebus.py b/erebus.py index 1c62a44..e6c0459 100644 --- a/erebus.py +++ b/erebus.py @@ -284,5 +284,9 @@ def loop(): main.fd(fileno).parse(line) if __name__ == '__main__': + try: os.rename('logfile', 'oldlogs/%s' % (time.time())) + except: pass + sys.stdout = open('logfile', 'w') + sys.stderr = sys.stdout setup() while True: loop()