如何在没有屏幕记录的情况下运行cherrypy应用程序?
我正在寻找一些配置或标志,使我可以使请求的页面静音.
Hi I looking for some configuration or flag that allows me to silence the requested pages.
当我运行 python cherrypy_app.py
时,我加入了启动cherrypy应用程序的控制台中的 127.0.0.1:8080
When I run python cherrypy_app.py
and I join to the 127.0.0.1:8080
in the console where I start the cherrypy app show me
127.0.0.1--[09/Oct/2014:19:10:35]"GET/HTTP/1.1" 200 1512""Mozilla/5.0 ..."127.0.0.1--[09/Oct/2014:19:10:35]"GET/static/css/style.css HTTP/1.1" 200 88"http://127.0.0.1:8080/""Mozilla/5.0..."127.0.0.1--[09/Oct/2014:19:10:36]"GET/favicon.ico HTTP/1.1" 200 1406""Mozilla/5.0 ..."
我不想显示此信息.有可能吗?
I do not want to show this info. It is possible?
据我对CherryPy的初次尝试,我有同样的愿望.因此,除了关闭stdout日志记录本身以外,还有更多要说的话.
I as far as I remember in my first attempts with CherryPy I had the same desire. So here's a little more to say besides turning off the stdout logging per se.
CherryPy具有一些预定义的环境:分期,生产,嵌入式,在此处href ="https://bitbucket.org/cherrypy/cherrypy/src/4939ea9fbe6b0def376fbb349c039c38b0a8994b/cherrypy/_cpconfig.py?at=default#cl-187" rel ="nofollow">此处.每个环境都有其配置集.因此,尽管开发标准输出日志记录实际上很有帮助,但是在生产环境中却没有任何意义.根据部署设置环境是在CherryPy中进行配置的正确方法.
CherryPy has some predefined environments: staging, production, embedded, test_suite that are defined here. Each environment has its set of configuration. So while developing stdout logging is in fact quite helpful, whereas in production environment it makes no sense. Setting the environment according to the deployment is the correct way to deal configuration in CherryPy.
在您的特定情况下,标准输出日志记录由 log.screen
控制.在生产环境中已将其禁用.
In your particular case the stdout logging is controlled by log.screen
. It is already disabled in production environment.
这里是示例,但是请注意,在应用程序内部设置环境并不是最好的主意.您最好使用 cherryd
-environment
.
Here's the example, but note that setting environment inside your application isn't the best idea. You're better use cherryd
's --environment
for it instead.
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import cherrypy
config = {
'global' : {
'server.socket_host' : '127.0.0.1',
'server.socket_port' : 8080,
'server.thread_pool' : 8,
# Doing it explicity isn't a recommended way
# 'log.screen' : False
}
}
class App:
@cherrypy.expose
def index(self):
return 'Logging example'
if __name__ == '__main__':
# Better use cherryd (http://cherrypy.readthedocs.org/en/latest/install.html#cherryd)
# for setting the environment outside the app
cherrypy.config.update({'environment' : 'production'})
cherrypy.quickstart(App(), '/', config)