Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(113)

Unified Diff: third_party/boto/boto/requestlog.py

Issue 698893003: Update checked in version of gsutil to version 4.6 (Closed) Base URL: http://dart.googlecode.com/svn/third_party/gsutil/
Patch Set: Created 6 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « third_party/boto/boto/regioninfo.py ('k') | third_party/boto/boto/roboto/awsqueryservice.py » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: third_party/boto/boto/requestlog.py
===================================================================
--- third_party/boto/boto/requestlog.py (revision 0)
+++ third_party/boto/boto/requestlog.py (revision 0)
@@ -0,0 +1,39 @@
+
+from datetime import datetime
+from threading import Thread
+import Queue
+
+from boto.utils import RequestHook
+
+class RequestLogger(RequestHook):
+ """
+ This class implements a request logger that uses a single thread to
+ write to a log file.
+ """
+ def __init__(self, filename='/tmp/request_log.csv'):
+ self.request_log_file = open(filename, 'w')
+ self.request_log_queue = Queue.Queue(100)
+ Thread(target=self._request_log_worker).start()
+
+
+ def handle_request_data(self, request, response, error=False):
+ len = 0 if error else response.getheader('Content-Length')
+ now = datetime.now()
+ time = now.strftime('%Y-%m-%d %H:%M:%S')
+ td = (now - request.start_time)
+ duration = (td.microseconds + long(td.seconds + td.days*24*3600) * 1e6) / 1e6
+
+ # write output including timestamp, status code, response time, response size, request action
+ self.request_log_queue.put("'%s', '%s', '%s', '%s', '%s'\n" % (time, response.status, duration, len, request.params['Action']))
+
+
+ def _request_log_worker(self):
+ while True:
+ try:
+ item = self.request_log_queue.get(True)
+ self.request_log_file.write(item)
+ self.request_log_file.flush()
+ self.request_log_queue.task_done()
+ except:
+ import traceback; traceback.print_exc(file=sys.stdout)
+
Property changes on: third_party/boto/boto/requestlog.py
___________________________________________________________________
Added: svn:eol-style
+ LF
« no previous file with comments | « third_party/boto/boto/regioninfo.py ('k') | third_party/boto/boto/roboto/awsqueryservice.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698