Author: tmckay Date: 2011-01-22 23:57:22 +0000 (Sat, 22 Jan 2011) New Revision: 4479
Modified: branches/scale_testing/wooly/python/wooly/server.py Log: Record GET requests to log file, with file-based rollover trigger
Modified: branches/scale_testing/wooly/python/wooly/server.py =================================================================== --- branches/scale_testing/wooly/python/wooly/server.py 2011-01-21 18:48:36 UTC (rev 4478) +++ branches/scale_testing/wooly/python/wooly/server.py 2011-01-22 23:57:22 UTC (rev 4479) @@ -3,7 +3,9 @@ from util import * from wooly import * from wsgiserver import CherryPyWSGIServer +from parsley.loggingex import *
+ log = logging.getLogger("wooly.server")
class WebServer(object): @@ -23,6 +25,11 @@ self.client_sessions_by_id = dict() self.client_session_expire_thread = ClientSessionExpireThread(self)
+ self.link_log_path = os.environ.get("CUMIN_HOME", "/usr/share/cumin") + self.link_log = os.path.join(self.link_log_path, "wooly_server_links.log") + self.link_log_dest = os.path.join(self.link_log_path, "wooly_server_links.dest") + self.link_log_dest_mt = None + def init(self): return # XXX urgh
@@ -71,8 +78,36 @@
return then
+ def log_link(self, link, lastrequested): + import shutil + open_mode = "a+" + if os.path.exists(self.link_log_dest): + #If modification time has changed + if self.link_log_dest_mt == None or \ + os.path.getmtime(self.link_log_dest) > self.link_log_dest_mt: + self.link_log_dest_mt = os.path.getmtime(self.link_log_dest) + + # Read the destination + f = open(self.link_log_dest, "r") + dest = os.path.join(self.link_log_path, f.readline().strip()) + f.close() + + # Copy the file to destination + shutil.copyfile(self.link_log, dest) + + # Make main log truncate before write + open_mode = "w" + + f = open(self.link_log, open_mode) + if lastrequested: + f.write("True,") + else: + f.write("False,") + f.write(link+"\n") + def service_request(self, env, response): log.info("Request %s %s", env["REQUEST_METHOD"], env["REQUEST_URI"]) + self.log_link(env["REQUEST_URI"], self.get_last_requested(env) != None)
page = self.get_page(env)
cumin-developers@lists.fedorahosted.org