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

842 views
Skip to first unread message

Flask User

unread,
Sep 13, 2016, 2:28:49 AM9/13/16
to cherrypy-users
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?

Sylvain Hellegouarch

unread,
Sep 13, 2016, 10:00:55 AM9/13/16
to cherryp...@googlegroups.com
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

--
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 cherrypy-users+unsubscribe@googlegroups.com.
To post to this group, send email to cherrypy-users@googlegroups.com.
Visit this group at https://groups.google.com/group/cherrypy-users.
For more options, visit https://groups.google.com/d/optout.



--

Flask User

unread,
Sep 13, 2016, 7:37:46 PM9/13/16
to cherrypy-users
This means using werkzeug or wsgilog kind of middleware with flask?

Joel Rivera

unread,
Sep 13, 2016, 7:41:52 PM9/13/16
to cherryp...@googlegroups.com
On Tue, 13 Sep 2016 16:37:45 -0700 (PDT)
Flask User <ad...@vyomtech.com> 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²

Flask User

unread,
Sep 13, 2016, 11:20:04 PM9/13/16
to cherrypy-users
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()

Avinash kumar

unread,
Oct 19, 2023, 9:32:58 AM10/19/23
to cherrypy-users
hi could you please help me with djangorest app?
i am facing same problem for logging request

Reply all
Reply to author
Forward
0 new messages