From af666612123073ae835dc8f52905e4268741a3b0 Mon Sep 17 00:00:00 2001 From: Aldo Cortesi Date: Sun, 31 May 2015 17:25:36 +1200 Subject: [PATCH] Add timestamps to logs by everywhere --- libpathod/log.py | 7 +++++++ libpathod/pathod.py | 5 ++--- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/libpathod/log.py b/libpathod/log.py index 67898dd18..568d4d66e 100644 --- a/libpathod/log.py +++ b/libpathod/log.py @@ -1,9 +1,13 @@ +import datetime + import netlib.utils import netlib.tcp import netlib.http class Log: + TIMEFMT = '%d-%m-%y %H:%M:%S' + def __init__(self, fp, hex, rfile, wfile): self.lines = [] self.fp = fp @@ -38,6 +42,9 @@ class Log: self("Disconnected") elif exc_type == netlib.http.HttpError: self("HTTP Error: %s" % exc_value.message) + self.fp.write( + "%s: "%datetime.datetime.now().strftime(self.TIMEFMT) + ) self.fp.write("\n".join(self.lines)) self.fp.write("\n") self.fp.flush() diff --git a/libpathod/pathod.py b/libpathod/pathod.py index 7e318ca12..a3f32ce74 100644 --- a/libpathod/pathod.py +++ b/libpathod/pathod.py @@ -106,16 +106,15 @@ class PathodHandler(tcp.BaseHandler): lr = self.rfile if self.server.logreq else None lw = self.wfile if self.server.logresp else None with log.Log(self.logfp, self.server.hexdump, lr, lw) as lg: - while 1: + while True: try: frm = websockets.Frame.from_file(self.rfile) break except tcp.NetLibTimeout: pass - print frm.human_readable() + lg(frm.human_readable()) return self.handle_websocket, None - def handle_http_request(self): """ Returns a (handler, log) tuple.