gpt4 book ai didi

python - 如何使用 Cherrypy 设置日志记录?

转载 作者:行者123 更新时间:2023-11-30 23:34:28 26 4
gpt4 key购买 nike

我正在尝试在我的 Openshift python 3.3 应用程序上使用 Cherrypy 设置日志记录。 “appserver.log”文件仅在实际服务器启动之前更新,然后不会将任何内容添加到日志文件中。我已阅读并遵循(据我所知)以下链接中的文档。仍然没有记录。

CherryPy server errors log

http://docs.cherrypy.org/dev/refman/_cplogging.html

我的Python代码片段:

def run_cherrypy_server(app, ip, port=8080):
from cherrypy import wsgiserver
from cherrypy import config

# log.screen: Set this to True to have both “error” and “access” messages printed to stdout.
# log.access_file: Set this to an absolute filename where you want “access” messages written.
# log.error_file: Set this to an absolute filename where you want “error” messages written.

appserver_error_log = os.path.join(os.environ['OPENSHIFT_HOMEDIR'], 'python', 'logs','appserver_error.log')
appserver_access_log = os.path.join(os.environ['OPENSHIFT_HOMEDIR'], 'python', 'logs','appserver_access.log')



config.update({
'log.screen': True,
'log.error_file': appserver_error_log,
'log.access_file': appserver_access_log
})

server = wsgiserver.CherryPyWSGIServer(
(ip, port), app, server_name='www.cherrypy.example')
server.start()

“appserver_error.log”和“appserver_access.log”文件实际上是在正确的 Openshift python 目录中创建的。但是,appserver_error.log 和 appserver_access.log 文件中都没有日志记录信息。

一切运行正常,但没有日志记录。

知道我做错了什么吗?

最佳答案

WSGI 服务器本身不执行任何日志记录。 CherryPy 引擎(控制进程启动和关闭)写入“错误”日志,并且只有 CherryPy 应用程序(使用 CherryPy 的请求和响应对象)写入访问日志。如果您要传递自己的 WSGI 应用程序,则必须进行自己的日志记录。

关于python - 如何使用 Cherrypy 设置日志记录?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18092909/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com