app_prod.py 1.0 KB

12345678910111213141516171819202122232425262728293031323334
  1. import os; os.environ.setdefault('FFDNISPDB_SETTINGS', '../settings_prod.py')
  2. from ffdnispdb import create_app
  3. app=create_app()
  4. if not app.debug:
  5. import logging
  6. from logging.handlers import SMTPHandler
  7. from logging import FileHandler
  8. mail_handler = SMTPHandler('127.0.0.1',
  9. 'server-error@db.ffdn.org',
  10. app.config['ADMINS'], 'FFDN DB Error')
  11. mail_handler.setLevel(logging.ERROR)
  12. mail_handler.setFormatter(logging.Formatter('''
  13. Message type: %(levelname)s
  14. Location: %(pathname)s:%(lineno)d
  15. Module: %(module)s
  16. Function: %(funcName)s
  17. Time: %(asctime)s
  18. Message:
  19. %(message)s
  20. '''))
  21. app.logger.addHandler(mail_handler)
  22. file_handler = FileHandler('application.log')
  23. file_handler.setLevel(logging.WARNING)
  24. file_handler.setFormatter(logging.Formatter(
  25. '%(asctime)s %(levelname)s: %(message)s '
  26. '[in %(pathname)s:%(lineno)d]'
  27. ))
  28. app.logger.addHandler(file_handler)