Skip to main content
 首页 » 编程设计

python之BottlePy 应用程序和 CherryPy 服务器未记录访问

2024年10月25日9grandyang

我正在像这样使用 CherryPy 提供 BottlePy 应用程序:

import cherrypy 
from myapp import MyApp 
from beaker.middleware import SessionMiddleware 
 
appdir = '/path/to/app' 
app = MyApp(appdir) 
 
session_opts = { 
    'session.timeout': 600,  # 10 minutes 
    'session.type': 'file', 
    'session.auto': True, 
    'session.data_dir': appdir + '/auth/data' 
} 
app = SessionMiddleware(app, session_opts) 
 
cherrypy.tree.graft(app, '/') 
cherrypy.config.update({ 
    'log.screen': False, 
    'log.access_file': appdir + '/front_end/cherrypy.access.log', 
    'log.error_file': appdir + '/front_end/cherrypy.error.log', 
    'server.socket_port': 8080, 
    'server.socket_host': '0.0.0.0' 
}) 
 
cherrypy.engine.start() 
cherrypy.engine.block() 

一切似乎都在正常工作,但 cherrypy.access.log 仍然是空的,而 cherrypy.error.log 显示:

[30/Dec/2014:11:04:55] ENGINE Bus STARTING 
[30/Dec/2014:11:04:55] ENGINE Started monitor thread '_TimeoutMonitor'. 
[30/Dec/2014:11:04:55] ENGINE Started monitor thread 'Autoreloader'. 
[30/Dec/2014:11:04:56] ENGINE Serving on http://0.0.0.0:8080 
[30/Dec/2014:11:04:56] ENGINE Bus STARTED 

但没有别的,没有访问日志,即使在提供内容之后也是如此。

我也试过

from cherrypy import wsgiserver 
 
# Instead of the cherrypy.* calls 
 
server = wsgiserver.CherryPyWSGIServer(('0.0.0.0', 8080), app) 
server.start() 

但是它会打印和上面一样的,但是没有访问日志。找不到有关日志记录和 BottlePy 集成的任何进一步文档。

请您参考如下方法:

您运行的应用不是原生的 CherryPy,grafting 基本上绕过了 CP 的大部分内部结构,很可能包括访问日志记录。

由于除了基本的 WSGI 发布之外您不使用任何 CherryPy 的功能,您最好使用一种更面向服务的(和更新的)解决方案,如 uWSGI、Gunicorn 或 nginx/Apache+plugins。