所有日志都被复制到 apache 错误日志中
All logs being duplicated into apache error log
我有一个 flask 项目,它通过配置文件设置了日志记录。
这在 运行 本地时按需要工作,但是当我 运行 它在 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)
我发现写入 stdout 会写入 Apache 错误日志。我已经打开了一个更相关的问题:How can I stop sys.stdout logging to apache error file?
我有一个 flask 项目,它通过配置文件设置了日志记录。 这在 运行 本地时按需要工作,但是当我 运行 它在 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)
我发现写入 stdout 会写入 Apache 错误日志。我已经打开了一个更相关的问题:How can I stop sys.stdout logging to apache error file?