问题
I use uwsgi to deploy my pyramid project. and also use pyramid_exclog to catch exception log which is expected to logto the file exception.log . But all the log info(include the exception log) was output to the file 'project.log' which was setted in the section of [uwsgi], file production.ini
[uwsgi]
logto = /var/log/project.log
I need your help to make exception info output to the file of exception.log instead of project.log I use the 'pserve' command to start up my project, everything works well. So how to deploy the pyramid_exclog under uwsgi.
回答1:
I ran into the same problem. I've tried the --ini-paste-logged
option, but that requires Paste. I'm running under Python 3.3 and Paste hasn't been updated for Python 3, so that wasn't going to work for me.
What I came up with was to create my own WSGI application file like so (file named production.wsgi
):
import configparser
import logging.config
from myapp import main
ini_path = 'production.ini'
# Set up logging
logging.config.fileConfig(ini_path)
# Parse config and create WSGI app
config = configparser.ConfigParser()
config.read(ini_path)
# First argument is default config values, second argument are the settings
# from the app:main section
# http://docs.pylonsproject.org/projects/pyramid/en/latest/narr/startup.html
application = main(config['DEFAULT'], **config['app:main'])
Then in my production.ini
file I have the following [uwsgi]
section:
[uwsgi]
wsgi-file = %d/production.wsgi
chdir = %d
http-socket = :29999
enable-threads = true
master = true
processes = 1
Instead of starting it with --ini-paste
or --ini-paste-logged
, I just start it with --ini
:
/usr/bin/uwsgi --ini /usr/local/myapp/production.ini
(uWSGI is actually installed into my app's virtual environment.)
回答2:
pyramid_exclog uses the standard python logging module. Thus you need to ensure that uwsgi is parsing logging configuration from your ini when running your application. I think this involves invoking your app with --ini-paste-logged
or some such under uWSGI. Also, ensure you actually setup logging as mentioned in the pyramid_exclog documentation.
回答3:
Here is how I do it. Found this on irc log
First, make sure you set it up properly like described here
Then set the logging manually in your app
from pyramid.paster import setup_logging
# somewhere in your main app
setup_logging('your-settings.ini')
I do not know if there is side effects doing this but so far it works
来源:https://stackoverflow.com/questions/11539647/no-exception-log-output-in-excepiton-log-file-in-pyramid-project-with-plugin-pyr