How to display requests for flask app running under cherrypy using WSGI

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

How to display requests for flask app running under cherrypy using WSGI

Flask User
I have a flask app running under cherrypy. In the config I enabled log.screen: True, still I cannot see any request logs or console messages from flask app. When I run the same app using flask run I can see it.

Following is the configuration:

cherrypy.tree.graft(app, "/")
cherrypy
.config.update({
       
'engine.autoreload_on': True,
       
'log.screen': True,
       
'server.socket_port': 5000,
       
'server.socket_host': '0.0.0.0',
   
})
cherrypy
.engine.start()
cherrypy
.engine.block()

If running using flask built-in server can see message like:

127.0.0.1 - - [13/Sep/2016 14:24:42] "POST /auth/api/v1/login HTTP/1.1" 404 -

But when running under cherrypy cannot see any request on flask app:

[13/Sep/2016:14:25:47] ENGINE Started monitor thread 'Autoreloader'.
[13/Sep/2016:14:25:47] ENGINE Started monitor thread '_TimeoutMonitor'.
[13/Sep/2016:14:25:47] ENGINE Serving on http://0.0.0.0:5000
[13/Sep/2016:14:25:47] ENGINE Bus STARTED

Am I doing something wrong here?

--
You received this message because you are subscribed to the Google Groups "cherrypy-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
Visit this group at https://groups.google.com/group/cherrypy-users.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: How to display requests for flask app running under cherrypy using WSGI

Sylvain Hellegouarch
Hi there,

WSGI app that are "grafted" cannot benefit from the higher level CherryPy assets. They merely live at the WSGI server level. You should therefore look towards Flask doc to enable those logs or use a WSGI middleware that adds this for you.

- Sylvain

2016-09-13 8:27 GMT+02:00 Flask User <[hidden email]>:
I have a flask app running under cherrypy. In the config I enabled log.screen: True, still I cannot see any request logs or console messages from flask app. When I run the same app using flask run I can see it.

Following is the configuration:

cherrypy.tree.graft(app, "/")
cherrypy
.config.update({
       
'engine.autoreload_on': True,
       
'log.screen': True,
       
'server.socket_port': 5000,
       
'server.socket_host': '0.0.0.0',
   
})
cherrypy
.engine.start()
cherrypy
.engine.block()

If running using flask built-in server can see message like:

127.0.0.1 - - [13/Sep/2016 14:24:42] "POST /auth/api/v1/login HTTP/1.1" 404 -

But when running under cherrypy cannot see any request on flask app:

[13/Sep/2016:14:25:47] ENGINE Started monitor thread 'Autoreloader'.
[13/Sep/2016:14:25:47] ENGINE Started monitor thread '_TimeoutMonitor'.
[13/Sep/2016:14:25:47] ENGINE Serving on http://0.0.0.0:5000
[13/Sep/2016:14:25:47] ENGINE Bus STARTED

Am I doing something wrong here?

--
You received this message because you are subscribed to the Google Groups "cherrypy-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
Visit this group at https://groups.google.com/group/cherrypy-users.
For more options, visit https://groups.google.com/d/optout.



--

--
You received this message because you are subscribed to the Google Groups "cherrypy-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
Visit this group at https://groups.google.com/group/cherrypy-users.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: How to display requests for flask app running under cherrypy using WSGI

Flask User
This means using werkzeug or wsgilog kind of middleware with flask?

--
You received this message because you are subscribed to the Google Groups "cherrypy-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
Visit this group at https://groups.google.com/group/cherrypy-users.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: How to display requests for flask app running under cherrypy using WSGI

cyraxjoe
On Tue, 13 Sep 2016 16:37:45 -0700 (PDT)
Flask User <[hidden email]> wrote:

> This means using werkzeug or wsgilog kind of middleware with flask?
>

Take a look into: http://blog.joel.mx/posts/cherrypy-as-a-wsgi-server

Specially the `_with_access_log` function, specifically I'm using
https://pypi.python.org/pypi/wsgi-request-logger/.
--
Rivera²

--
You received this message because you are subscribed to the Google Groups "cherrypy-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
Visit this group at https://groups.google.com/group/cherrypy-users.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: How to display requests for flask app running under cherrypy using WSGI

Flask User
I was thinking that by tweaking cherrypy logger or werkzeug, I don't need to use middleware (one less dependency), but based on all the examples and your response thought it isn't possible without using wsgi middleware.

I achieved it by using wsgi-request-logger (installing it by pip install wsgi-request-logger), the code I used is following.

import cherrypy
from requestlogger import WSGILogger, ApacheFormatter
from logging.handlers import TimedRotatingFileHandler

from api.flask_app import create_app

app
= create_app()

handlers
= [TimedRotatingFileHandler('logs/access.log', 'd', 7), ]
app_with_log
= WSGILogger(app, handlers, ApacheFormatter())
cherrypy
.tree.graft(app_with_log, "/")
cherrypy
.config.update({
       
'engine.autoreload_on': True,
       
'log.screen': True,
       
'server.socket_port': 8080,
       
'server.socket_host': '0.0.0.0',
   
})
cherrypy
.engine.start()
cherrypy
.engine.block()



On Wednesday, September 14, 2016 at 7:41:52 AM UTC+8, Joel Rivera wrote:
On Tue, 13 Sep 2016 16:37:45 -0700 (PDT)
Flask User <<a href="javascript:" target="_blank" gdf-obfuscated-mailto="w517JsJTAAAJ" rel="nofollow" onmousedown="this.href=&#39;javascript:&#39;;return true;" onclick="this.href=&#39;javascript:&#39;;return true;">ad...@...> wrote:

> This means using werkzeug or wsgilog kind of middleware with flask?
>

Take a look into: <a href="http://blog.joel.mx/posts/cherrypy-as-a-wsgi-server" target="_blank" rel="nofollow" onmousedown="this.href=&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Fblog.joel.mx%2Fposts%2Fcherrypy-as-a-wsgi-server\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNF5DC1vpFQnBAO2fgOfWTkrqpFyDQ&#39;;return true;" onclick="this.href=&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Fblog.joel.mx%2Fposts%2Fcherrypy-as-a-wsgi-server\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNF5DC1vpFQnBAO2fgOfWTkrqpFyDQ&#39;;return true;">http://blog.joel.mx/posts/cherrypy-as-a-wsgi-server

Specially the `_with_access_log` function, specifically I'm using
<a href="https://pypi.python.org/pypi/wsgi-request-logger/" target="_blank" rel="nofollow" onmousedown="this.href=&#39;https://www.google.com/url?q\x3dhttps%3A%2F%2Fpypi.python.org%2Fpypi%2Fwsgi-request-logger%2F\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNHUrc51nYQ8wezowLEOJnYAAp3bOw&#39;;return true;" onclick="this.href=&#39;https://www.google.com/url?q\x3dhttps%3A%2F%2Fpypi.python.org%2Fpypi%2Fwsgi-request-logger%2F\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNHUrc51nYQ8wezowLEOJnYAAp3bOw&#39;;return true;">https://pypi.python.org/pypi/wsgi-request-logger/.
--
Rivera²

--
You received this message because you are subscribed to the Google Groups "cherrypy-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
Visit this group at https://groups.google.com/group/cherrypy-users.
For more options, visit https://groups.google.com/d/optout.