Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from __future__ import print_function
- import os, sys, traceback
- import logging.config
- APP_CONFIG = "/home/.../production.ini"
- logging.config.fileConfig(APP_CONFIG)
- def _get_log():
- return open("/home/.../passenger_wsgi.log", 'a')
- log = _get_log()
- print("running %s" % sys.executable, file=log)
- INTERP = "/home/.../bin/python"
- if sys.executable != INTERP:
- print("Detected wrong interpreter location , swapping to %s" % INTERP, file=log)
- log.flush()
- log.close()
- os.execl(INTERP, INTERP, *sys.argv)
- from paste.deploy import loadapp
- from paste.exceptions.errormiddleware import ErrorMiddleware
- log.flush()
- log.close()
- def application(environ, start_response):
- log = _get_log()
- print("Application called:", file=log)
- print("environ: %s" % str(environ), file=log)
- results = []
- try:
- app = loadapp("config:/home/.../production.ini")
- print("App loaded, attempting to run", file=log)
- log.flush()
- results = app(environ, start_response)
- print("App executed successfully", file=log)
- except Exception: # ignoring the broad exception as this is intended to catch and log any uncaught errors
- traceback.print_exc(file=log)
- log.flush()
- finally:
- log.close()
- print("Returning results.")
- return results
- application = ErrorMiddleware(application, debug=True)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement