Thanks Alice. I wasn't sure how to insert/structure middleware, but
this page helped:
http://wiki.pylonshq.com/display/pylonscookbook/Adding+your+own+middleware

My solution looks roughly like this:

class RequestLogger(object):
    """WSGI middleware to log all requests."""

    def __init__(self, app):
        self.app = app
        self.uris = set()

    def __call__(self, environ, start_response):
        self.uris.add(environ['PATH_INFO'] + "\n")
        open("request_log.txt", "w").writelines(self.uris)
        return self.app(environ, start_response)

With it being registered at the end of middleware.py:

return RequestLogger(app)

Alec

P.S. I know my implementation isn't ideal, but I'm working on that. ;)

On May 10, 10:26 pm, Alice Bevan–McGregor <al...@gothcandy.com> wrote:
> Create a small bit of middleware to log the environ['REQUEST_URI'] (or
> other value, as appropriate) of each GET.  You can then direct that
> logger to output to a file, another handler (i.e. you could write one
> which logs to your database of choice and de-duplicates), etc.
>
> Logging to a file then running 'sort -u' across the resultant file will
> give you all of the unique addresses visited by users during the
> logging period.
>
>         — Alice.
>
> On 2011-05-10 11:59:16 -0700, Alec Munro said:
>
>
>
>
>
>
>
> > D'oh!
>
> > I should have specified that I'm using Pylons 0.96 for this particular
> > application.
>
> > Thanks,
> > Alec
>
> > On May 10, 3:51 pm, Jasper van den Bosch
> > <jap...@gmail.com> wrote:
> >> If you use traversal, perhaps in the constructor of your Root resource?
>
> >> On 10 May 2011 20:40, Alec Munro
> >> <alecmu...@gmail.com> wrote:
>
> >>> Hi list,
>
> >>> I want to create a map of all the requests to an application, to make
> >>> it easier to refactor it without breaking it's interfaces. What's the
> >>> easiest place to add a function to be called for every request?
>
> >>> Thanks,
> >>> Alec
>
> >>> --
> >>> You received this message because you are subscribed to the Google Groups
> >>> "pylons-devel" group.
> >>> To post to this group, send email to
> >>> pylons-devel@googlegroups.com.
> >>> To unsubscribe from this group, send email to
> >>> pylons-devel+unsubscr...@googlegroups.com.
> >>> For more options, visit this group at
> >>>http://groups.google.com/group/pylons-devel?hl=en.

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

Reply via email to