Anonymous avatar Anonymous committed c8265b4

added log4j to development,

Comments (0)

Files changed (3)

 keys = root, routes, pylons_app, sqlalchemy
 
 [handlers]
-keys = console
+keys = console,chainsaw
 
 [formatters]
-keys = generic
+keys = generic,xmllayout
 
 #############
 ## LOGGERS ##
 #############
 [logger_root]
-level = INFO
+level = NOTSET
 handlers = console
 
 [logger_routes]
 level = NOTSET
 formatter = generic
 
+[handler_chainsaw]
+class = xmllayout.RawSocketHandler
+args = ('localhost', 4448)
+level = NOTSET
+formatter = xmllayout
+
 ################
 ## FORMATTERS ##
 ################
 format = %(asctime)s,%(msecs)03d %(levelname)-5.5s [%(name)s] %(message)s
 datefmt = %H:%M:%S
 
+[formatter_xmllayout]
+class = xmllayout.XMLLayout
+
 
 [web]
 push_ssl = false
-contact = marcin.kuzminski@etelko.pl
+contact = develop@etelko.pl
 allow_archive = gz zip bz2
 allow_push = *
 style = gitweb

pylons_app/lib/profiler.py

+from __future__ import with_statement
+
+import cProfile
+import pstats
+import cgi
+import pprint
+import threading
+
+from StringIO import StringIO
+
+class ProfilingMiddleware(object):
+    def __init__(self, app):
+        self.lock = threading.Lock()
+        self.app = app
+    
+    
+    def __call__(self, environ, start_response):
+        with self.lock:
+            profiler = cProfile.Profile()
+            def run_app(*a, **kw):
+                self.response = self.app(environ, start_response)
+
+            profiler.runcall(run_app, environ, start_response)
+
+            profiler.snapshot_stats()
+
+            stats = pstats.Stats(profiler)
+            stats.sort_stats('cumulative')
+
+            # Redirect output
+            out = StringIO()
+            stats.stream = out
+
+            stats.print_stats()
+
+            resp = ''.join(self.response)
+
+            # Lets at least only put this on html-like responses.
+            if resp.strip().startswith('<'):
+                ## The profiling info is just appended to the response.
+                ##  Browsers don't mind this.
+                resp += '<pre style="text-align:left; border-top: 4px dashed red; padding: 1em;">'
+                resp += cgi.escape(out.getvalue(), True)
+                
+                output = StringIO()
+                pprint.pprint(environ, output, depth=3)
+                
+                resp += cgi.escape(output.getvalue(), True)
+                resp += '</pre>'
+                
+            return resp
+    
+
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.