changeset 2656:c785ad556d44 beta

added extra logging into API calls
author Marcin Kuzminski <marcin@python-works.com>
date Tue, 24 Jul 2012 22:15:47 +0200
parents 5a39eb37edfa
children 001c7e2ae986
files rhodecode/controllers/api/__init__.py
diffstat 1 files changed, 8 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/rhodecode/controllers/api/__init__.py	Sun Jul 22 23:36:48 2012 +0200
+++ b/rhodecode/controllers/api/__init__.py	Tue Jul 24 22:15:47 2012 +0200
@@ -30,6 +30,7 @@
 import types
 import urllib
 import traceback
+import time
 
 from rhodecode.lib.compat import izip_longest, json
 
@@ -43,6 +44,8 @@
 
 from rhodecode.model.db import User
 from rhodecode.lib.auth import AuthUser
+from rhodecode.lib.base import _get_ip_addr, _get_access_path
+from rhodecode.lib.utils2 import safe_unicode
 
 log = logging.getLogger('JSONRPC')
 
@@ -95,6 +98,7 @@
         Parse the request body as JSON, look up the method on the
         controller and if it exists, dispatch to it.
         """
+        start = time.time()
         self._req_id = None
         if 'CONTENT_LENGTH' not in environ:
             log.debug("No Content-Length")
@@ -218,7 +222,10 @@
         headers.append(('Content-Length', str(len(output[0]))))
         replace_header(headers, 'Content-Type', 'application/json')
         start_response(status[0], headers, exc_info[0])
-
+        log.info('IP: %s Request to %s time: %.3fs' % (
+            _get_ip_addr(environ),
+            safe_unicode(_get_access_path(environ)), time.time() - start)
+        )
         return output
 
     def _dispatch_call(self):