In gluon/main.py replace the appfactory function with:

def appfactory(wsgiapp=wsgibase,
               logfilename='httpsever.log',
               profilerfilename='profiler.log',
               web2py_path=web2py_path):
    import thread
    locker=thread.allocate_lock()
    def app_with_logging(environ, responder):
        environ['web2py_path'] = web2py_path
        status_headers = []

        def responder2(s, h):
            status_headers.append(s)
            status_headers.append(h)
            return responder(s, h)

        time_in = time.time()
        ret=[0]
        if not profilerfilename:
            ret[0] = wsgiapp(environ, responder2)
        else:
            import cProfile, pstats
            locker.acquire()
            cProfile.runctx('ret[0] = wsgiapp(environ,
responder2)',globals(),locals(),profilerfilename)
            pstats.Stats(profilerfilename).strip_dirs().sort_stats
(-1).print_stats()
            locker.release()
        try:
            line = '%s, %s, %s, %s, %s, %s, %f\n' % (
                environ['REMOTE_ADDR'],
                datetime.datetime.today().strftime('%Y-%m-%d %H:%M:%S'
                        ),
                environ['REQUEST_METHOD'],
                environ['PATH_INFO'].replace(',', '%2C'),
                environ['SERVER_PROTOCOL'],
                (status_headers[0])[:3],
                time.time() - time_in,
                )
            if logfilename:
                open(logfilename, 'a').write(line)
            else:
                sys.stdout.write(line)
        except:
            pass
        return ret[0]

    return app_with_logging


TODO:

1) add a command line option to specify if profilefilename=None (no
profiling) or else
2) print profile info to a file, not to console
3) add to admin, the ability to read the profile info that is
generated.
4) test on GAE

Can you help?

Massimo
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"web2py Web Framework" group.
To post to this group, send email to web2py@googlegroups.com
To unsubscribe from this group, send email to 
web2py+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/web2py?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to