【发布时间】:2016-07-26 15:13:56
【问题描述】:
我有一个烧瓶项目,其日志记录由配置文件设置。 这在本地运行时可以正常工作,但是当我在 apache wsgi 下运行它时,所有日志消息(不仅仅是错误)也会写入到 vhost 中设置的 error.log 文件中。
经过一番谷歌搜索后,我找到了我认为可能相关的this issue,并尝试设置 app.logger_name 并调用 app.logger,但我仍然遇到同样的问题。
config/logging.yaml:pastebin
虚拟主机:
<VirtualHost *:80>
ServerName myapp.com
WSGIDaemonProcess myapp home=/var/www/vhosts/myapp/httpdocs
WSGIScriptAlias / /var/www/vhosts/myapp/httpdocs/myapp.wsgi
<Directory /var/www/vhosts/myapp/httpdocs>
WSGIProcessGroup myapp
WSGIApplicationGroup %{GLOBAL}
Order deny,allow
Allow from all
</Directory>
ErrorLog /var/www/vhosts/myapp/logs/error.log
CustomLog /var/www/vhosts/myapp/logs/access.log combined
</VirtualHost>
myapp.wsgi:
activate_this = '/var/www/vhosts/myapp/httpdocs/env/bin/activate_this.py'
execfile(activate_this, dict(__file__=activate_this))
import sys
sys.path.insert(0, '/var/www/vhosts/myapp/httpdocs')
from run_web import app as application
run_web.py:
import init
import logging
from web import app, api
init.add_to_syspath()
init.logging_conf()
# Flask removes all log handlers so our logs are written to the error log as well.
app.logger_name = "nowhere"
app.logger
logger = logging.getLogger('run_web')
logger.info('Starting web')
api.init()
if __name__ == '__main__':
logger.info('Flask running in debug mode')
app.debug = True
app.run()
init.logging_conf():
def logging_conf():
with open('conf/logging.yaml', 'r') as yaml_file:
logging_config = yaml.load(yaml_file)
dictConfig(logging_config)
【问题讨论】:
标签: python apache logging flask mod-wsgi