我正在使用一个views.py 子进程操作系统调用,它以非零返回码失败,我需要捕获问题所在。我还想记录所有内容,并且努力按照说明(https://docs.pylonsproject.org/projects/pyramid/en/latest/narr/logging.html?awesome > Advanced Configuration > 见下文)来完成这项工作.
TIA
金字塔装置是最近建成的
virtualenv --no-site-packages myproj
cd /home/user/myproj/
source bin/activate
pip3.6 install pyramid pyramid-debugtoolbar pyramid-jinja2 waitress cookiecutter
pcreate -s starter mywsgi
cd mywsgi
python3.6 setup.py develop
在运行时保存 production.ini
views.py 调用
import os
import subprocess
import json
from pyramid.view import view_config
@view_config(route_name='overlay_event', renderer='json')
def event_view(request):
return {'new_overlay': subprocess.check_output(['/usr/bin/foo', '/path/thing.script',json.dumps(request.json_body)])
production.ini 是样板文件,如下所示。我的版本低于此。对于 subprocess.check_output 的非零返回代码失败,我确实获得了控制台日志记录,但没有从失败的脚本调用发送到 STDOUT 和 STDERR 的内容。我的脚本运行良好,所以它一定是某个环境、路径、JSON、ARGV 或其他问题。但我也只想记录。
当我根据上述日志记录指令编辑以下内容时,我收到有关错误处理程序的错误。当我逐渐将我的编辑回滚到 production.ini 时,就会发生这种情况。也许这缺少一些额外的包含或?view.py 也需要改变吗?
生物板
###
# app configuration
# https://docs.pylonsproject.org/projects/pyramid/en/1.9-branch/narr/environment.html
###
[app:main]
use = egg:myproj
pyramid.reload_templates = false
pyramid.debug_authorization = false
pyramid.debug_notfound = false
pyramid.debug_routematch = false
pyramid.default_locale_name = en
###
# wsgi server configuration
###
[server:main]
use = egg:waitress#main
listen = *:6543
###
# logging configuration
# https://docs.pylonsproject.org/projects/pyramid/en/1.9-branch/narr/logging.html
###
[loggers]
keys = root, myproj
[handlers]
keys = console
[formatters]
keys = generic
[logger_root]
level = WARN
handlers = console
[logger_myproj]
level = WARN
handlers =
qualname = myproj
[handler_console]
class = StreamHandler
args = (sys.stderr,)
level = NOTSET
formatter = generic
[formatter_generic]
format = %(asctime)s %(levelname)-5.5s [%(name)s:%(lineno)s][%(threadName)s] %(message)s
我对 production.ini 文件的编辑
[loggers]
keys = root, filelog
[handlers]
keys = console, myproj, filelog
[formatters]
keys = generic
[logger_root]
level = INFO
handlers = console, filelog
[logger_filelog]
class = FileHandler
args = ('%(here)s/myproj.log','a')
level = INFO
formatter = generic
[logger_myproj]
level = WARN
qualname = myproj
[handler_console]
class = StreamHandler
args = (sys.stderr,)
level = NOTSET
formatter = generic
[formatter_generic]
format = %(asctime)s %(levelname)-5.5s [%(name)s:%(lineno)s][%(threadName)s] %(message)s