librelist archives

« back to archive

Passing Information Between before_req and after_req.

Passing Information Between before_req and after_req.

From:
Abhishek K
Date:
2011-12-22 @ 10:40
Hi

I want to log the time it took to serve each request in my Flask App.

So I plan to measure start-time in
@app.before_request
And log the difference in
@app.after_request

I have a few questions :

   - How can I pass information between before and after Methods.
   - How can I log the times. How can I access the logger configured for
   the Flask App (as given in Error Handling tutorial).


Regards
-Abhishek Kona
Software Engineer - Platform.
Flipkart.com

Re: [flask] Passing Information Between before_req and after_req.

From:
Simon Sapin
Date:
2011-12-22 @ 10:57
Le 22/12/2011 11:40, Abhishek K a écrit :
> Hi
>
> I want to log the time it took to serve each request in my Flask App.
>
> So I plan to measure start-time in
> @app.before_request
> And log the difference in
> @app.after_request
>
> I have a few questions :
>
>   * How can I pass information between before and after Methods.
>   * How can I log the times. How can I access the logger configured for
>     the Flask App (as given in Error Handling tutorial).

Hi,

You can add attributes to the "g" object, they will stay there for the 
life-time of the request. The configured logger is in app.logger.

http://flask.pocoo.org/docs/api/#flask.g
http://flask.pocoo.org/docs/api/#flask.Flask.logger

Regards,
-- 
Simon Sapin

Re: [flask] Passing Information Between before_req and after_req.

From:
alice ni
Date:
2011-12-22 @ 14:59
By the way is flipkart running on flask? ...

On 22-Dec-2011 4:28 PM, "Simon Sapin" <simon.sapin@exyr.org> wrote:

> Le 22/12/2011 11:40, Abhishek K a écrit :
> > Hi
> >
> > I want to log the time it took to serve each request in my Flask App.
> >
> > So I plan to measure start-time in
> > @app.before_request
> > And log the difference in
> > @app.after_request
> >
> > I have a few questions :
> >
> >   * How can I pass information between before and after Methods.
> >   * How can I log the times. How can I access the logger configured for
> >     the Flask App (as given in Error Handling tutorial).
>
> Hi,
>
> You can add attributes to the "g" object, they will stay there for the
> life-time of the request. The configured logger is in app.logger.
>
> http://flask.pocoo.org/docs/api/#flask.g
> http://flask.pocoo.org/docs/api/#flask.Flask.logger
>
> Regards,
> --
> Simon Sapin
>

Re: [flask] Passing Information Between before_req and after_req.

From:
kracekumar ramaraju
Date:
2011-12-22 @ 15:29
On Thu, Dec 22, 2011 at 8:29 PM, alice ni <alice.ni19@gmail.com> wrote:

> By the way is flipkart running on flask? ...
>

No. they use java. :(.


> On 22-Dec-2011 4:28 PM, "Simon Sapin" <simon.sapin@exyr.org> wrote:
>
>> Le 22/12/2011 11:40, Abhishek K a écrit :
>> > Hi
>> >
>> > I want to log the time it took to serve each request in my Flask App.
>> >
>> > So I plan to measure start-time in
>> > @app.before_request
>> > And log the difference in
>> > @app.after_request
>> >
>> > I have a few questions :
>> >
>> >   * How can I pass information between before and after Methods.
>> >   * How can I log the times. How can I access the logger configured for
>> >     the Flask App (as given in Error Handling tutorial).
>>
>> Hi,
>>
>> You can add attributes to the "g" object, they will stay there for the
>> life-time of the request. The configured logger is in app.logger.
>>
>> http://flask.pocoo.org/docs/api/#flask.g
>> http://flask.pocoo.org/docs/api/#flask.Flask.logger
>>
>> Regards,
>> --
>> Simon Sapin
>>
>


-- 
*
Thanks & Regards

"Talk is cheap, show me the code" -- Linus Torvalds
kracekumar
www.kracekumar.com
*