If you get in trouble some some reason, maybe you'll find this article helpful in some way. Depending on how you serve your application, it might happen that your .ini configuration logging settings are not considered at all.
Covered arguments in this post:
- how to log exceptions based on PasteDeploy configuration .ini files
- running your app with uwsgi
- or with CherryPy (see the how to deploy pyramid applications on windows and the Windows service section on http://pyramid-cookbook.readthedocs.org/en/latest/deployment/windows.html)
How to configure your PasteDeploy .ini fileIn the following example I'm using the handlers.RotatingFileHandler (a python logrotate implementation), but feel free to use FileHandler (without handlers.).
You can configure your production.ini like the following one:
In the above example it is important omitting %(here)s/ in the RotatingFileHandler args, otherwise it won't be resolved running your app with uwsgi.... ### # logging configuration # http://docs.pylonsproject.org/projects/pyramid/en/latest/narr/logging.html ### [loggers] keys = root, mip_project, exc_logge [handlers] keys = console, exc_handle [formatters] keys = generic, exc_formatter [logger_root] level = WARN handlers = console [logger_mip_project] level = WARN handlers = qualname = mip_project [logger_exc_logger] level = ERROR handlers = exc_handler qualname = exc_logger [handler_console] class = StreamHandler args = (sys.stderr,) level = NOTSET formatter = generic [handler_exc_handler] class = handlers.RotatingFileHandler args = ('exception.log', 'a', 10000000, 10) level = ERROR formatter = exc_formatter [formatter_generic] format = %(asctime)s %(levelname)-5.5s [%(name)s][%(threadName)s] %(message)s [formatter_exc_formatter] format = %(asctime)s %(message)s [uwsgi] plugin = python ... master = true processes = 1 threads = 4 virtualenv = %d/your_python chdir = %d home = %d/your_python
If uwsgi complains about no paste.script.util.logging_config is availableIf your logger configuration is not considered by uwsgi and you see a warning more or less like a missing "paste.script.util.logging_config" module, just install PasteScript in your virtualenv:
And make sure your [uwsgi] section is pointing to your virtualenv (see previous section).(your_python) $ pip install PasteScript
Anyway, once installed PasteScript (I've tested the 1.7.5 version), all went fine:
Unfortunately I wasn't able to get exception logs enabled if I call the above command in a supervisord configuration file. Any suggestions?$ uwsgi --ini-paste-logged production.ini
Windows service and CherryPyIf you want to serve a Pyramid application with CherryPy (or creating a CherryPy based Windows service) with exception logging enabled you'll have to setup logging by hand because CherryPy does not consider your logging configuration.
from cherrypy import wsgiserver from pyramid.paster import get_app from pyramid.paster import setup_logging import osdef SvcDoRun(self):path = os.path.dirname(os.path.abspath(__file__)) os.chdir(path) app = get_app(CONFIG_FILE) setup_logging(CONFIG_FILE)....