所有日志都被复制到apache错误日志中

时间:2016-04-06 09:45:34

标签: python apache logging flask mod-wsgi

我有一个烧瓶项目,其中包含由配置文件设置的日志记录。 这在本地运行时可以正常工作,但是当我在apache wsgi下运行它时,所有日志消息(不仅仅是错误)都会写入vhost中设置的error.log文件。

经过一些谷歌搜索后,我发现this issue我认为可能是相关的,并尝试设置app.logger_name并调用app.logger,但我仍然遇到同样的问题。

config / logging.yaml:pastebin

VHOST:

<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)

1 个答案:

答案 0 :(得分:0)

我发现写入stdout会写入Apache错误日志。我打开了一个更相关的问题:How can I stop sys.stdout logging to apache error file?

相关问题