librelist archives

« back to archive

Standard Request Logging - Not Error Logging

Standard Request Logging - Not Error Logging

From:
MandolinPlayer
Date:
2012-08-10 @ 12:30
I have a cozy little flask app, and I think I am going to deploy it with
CherryPys CherryPyWSGIServer Works well, it's smallish.

That being said, I can not for the life of me figure out standard
access.logging  I.e. for every request, regardless of error status, if I am
handling explicitly etc, I want to log something like the apache combined
log format. This data can get fed into our security system etc for review.
This is different then logging errors for debugging purposes.  This is I
want everything logged.  How would I most easily accomplish that?   I
thought of just opening a file and doing it myself, but a. I don't know how
to leave the file open (it seems like not a good idea to open and close it
constantly, especially with the multi threading with cherrypy) and even
then, where would I catch "all"?

I can say I am loving this product in general, provides an awesome way to
work with web sites etc.

Re: [flask] Standard Request Logging - Not Error Logging

From:
Alex
Date:
2012-08-10 @ 15:27
If you are going to use CherryPy server it will manage every HTTP
request, so it make sense to use CP itself (and not Flask) for access
logging.

See here http://docs.cherrypy.org/dev/refman/_cplogging.html#simple-config

Alex

On Fri, Aug 10, 2012 at 2:30 PM, MandolinPlayer
<mandolinplayer@gmail.com> wrote:
> I have a cozy little flask app, and I think I am going to deploy it with
> CherryPys CherryPyWSGIServer Works well, it's smallish.
>
> That being said, I can not for the life of me figure out standard
> access.logging  I.e. for every request, regardless of error status, if I am
> handling explicitly etc, I want to log something like the apache combined
> log format. This data can get fed into our security system etc for review.
> This is different then logging errors for debugging purposes.  This is I
> want everything logged.  How would I most easily accomplish that?   I
> thought of just opening a file and doing it myself, but a. I don't know how
> to leave the file open (it seems like not a good idea to open and close it
> constantly, especially with the multi threading with cherrypy) and even
> then, where would I catch "all"?
>
> I can say I am loving this product in general, provides an awesome way to
> work with web sites etc.
>
>

Re: [flask] Standard Request Logging - Not Error Logging

From:
MandolinPlayer
Date:
2012-08-10 @ 16:29
The problem is when I set my flask app to be what the WSGIServer is
running, the app.log object doesn't exist. I have a feeling that cherrypy,
based on my research, doesn't do the same logging if it's not handling the
application.   Is there no default setup in Flask I could use?

On Fri, Aug 10, 2012 at 10:27 AM, Alex <thinkpragmatic@gmail.com> wrote:

> If you are going to use CherryPy server it will manage every HTTP
> request, so it make sense to use CP itself (and not Flask) for access
> logging.
>
> See here http://docs.cherrypy.org/dev/refman/_cplogging.html#simple-config
>
> Alex
>
> On Fri, Aug 10, 2012 at 2:30 PM, MandolinPlayer
> <mandolinplayer@gmail.com> wrote:
> > I have a cozy little flask app, and I think I am going to deploy it with
> > CherryPys CherryPyWSGIServer Works well, it's smallish.
> >
> > That being said, I can not for the life of me figure out standard
> > access.logging  I.e. for every request, regardless of error status, if I
> am
> > handling explicitly etc, I want to log something like the apache combined
> > log format. This data can get fed into our security system etc for
> review.
> > This is different then logging errors for debugging purposes.  This is I
> > want everything logged.  How would I most easily accomplish that?   I
> > thought of just opening a file and doing it myself, but a. I don't know
> how
> > to leave the file open (it seems like not a good idea to open and close
> it
> > constantly, especially with the multi threading with cherrypy) and even
> > then, where would I catch "all"?
> >
> > I can say I am loving this product in general, provides an awesome way to
> > work with web sites etc.
> >
> >
>

Re: [flask] Standard Request Logging - Not Error Logging

From:
MandolinPlayer
Date:
2012-08-10 @ 16:39
Ok to put this another way. Let's take Cherry Py out. I am now just running
Flask: How do I standard Access Logging? :)


On Fri, Aug 10, 2012 at 11:29 AM, MandolinPlayer
<mandolinplayer@gmail.com>wrote:

> The problem is when I set my flask app to be what the WSGIServer is
> running, the app.log object doesn't exist. I have a feeling that cherrypy,
> based on my research, doesn't do the same logging if it's not handling the
> application.   Is there no default setup in Flask I could use?
>
>
> On Fri, Aug 10, 2012 at 10:27 AM, Alex <thinkpragmatic@gmail.com> wrote:
>
>> If you are going to use CherryPy server it will manage every HTTP
>> request, so it make sense to use CP itself (and not Flask) for access
>> logging.
>>
>> See here
>> http://docs.cherrypy.org/dev/refman/_cplogging.html#simple-config
>>
>> Alex
>>
>> On Fri, Aug 10, 2012 at 2:30 PM, MandolinPlayer
>> <mandolinplayer@gmail.com> wrote:
>> > I have a cozy little flask app, and I think I am going to deploy it with
>> > CherryPys CherryPyWSGIServer Works well, it's smallish.
>> >
>> > That being said, I can not for the life of me figure out standard
>> > access.logging  I.e. for every request, regardless of error status, if
>> I am
>> > handling explicitly etc, I want to log something like the apache
>> combined
>> > log format. This data can get fed into our security system etc for
>> review.
>> > This is different then logging errors for debugging purposes.  This is I
>> > want everything logged.  How would I most easily accomplish that?   I
>> > thought of just opening a file and doing it myself, but a. I don't know
>> how
>> > to leave the file open (it seems like not a good idea to open and close
>> it
>> > constantly, especially with the multi threading with cherrypy) and even
>> > then, where would I catch "all"?
>> >
>> > I can say I am loving this product in general, provides an awesome way
>> to
>> > work with web sites etc.
>> >
>> >
>>
>
>

Re: [flask] Standard Request Logging - Not Error Logging

From:
Simon Sapin
Date:
2012-08-10 @ 17:43
Le 10/08/2012 18:39, MandolinPlayer a écrit :
> Ok to put this another way. Let's take Cherry Py out. I am now just
> running Flask: How do I standard Access Logging? :)

I agree with other posters that this is more something that the server 
(not the application) should do.

That said, if you really need to do it with just Flask:

     from flask import request
     @app.after_request
     def write_access_log(response):
         log(request.path, response.status_code, ...)
         return response

You will be responsible for generating log lines in the right format. 
For that, extract the information you need from the request and response 
objects. request.path and response.status_code are just examples, there 
are many other attributes you can access, documented here:

http://werkzeug.pocoo.org/docs/wrappers/

Regards,
-- 
Simon Sapin

Re: [flask] Standard Request Logging - Not Error Logging

From:
MandolinPlayer
Date:
2012-08-13 @ 17:41
Cool thanks. Is there any documentation on the advanced @app routing
directives in Flask?  I was trying to find that, but apparently my
google-fu was week that day.

Thanks!



On Fri, Aug 10, 2012 at 12:43 PM, Simon Sapin <simon.sapin@exyr.org> wrote:

> Le 10/08/2012 18:39, MandolinPlayer a écrit :
> > Ok to put this another way. Let's take Cherry Py out. I am now just
> > running Flask: How do I standard Access Logging? :)
>
> I agree with other posters that this is more something that the server
> (not the application) should do.
>
> That said, if you really need to do it with just Flask:
>
>      from flask import request
>      @app.after_request
>      def write_access_log(response):
>          log(request.path, response.status_code, ...)
>          return response
>
> You will be responsible for generating log lines in the right format.
> For that, extract the information you need from the request and response
> objects. request.path and response.status_code are just examples, there
> are many other attributes you can access, documented here:
>
> http://werkzeug.pocoo.org/docs/wrappers/
>
> Regards,
> --
> Simon Sapin
>

Re: [flask] Standard Request Logging - Not Error Logging

From:
Simon Sapin
Date:
2012-08-13 @ 18:06
Le 13/08/2012 19:41, MandolinPlayer a écrit :
> Cool thanks. Is there any documentation on the advanced @app routing
> directives in Flask?  I was trying to find that, but apparently my
> google-fu was week that day.

The details of every function and method is here:
http://flask.pocoo.org/docs/api/

… but the other pages of the docs have a lot of interesting stuff too. 
It is worth taking some time and skim through them.

If you want something specific about one project, remember to search 
this project’s docs, not the whole world. Try the "quick search" box on 
the sidebar, or inurl:flask.pocoo.org/docs on google

-- 
Simon Sapin