app_prod.py 1.0 KB

1234567891011121314151617181920212223242526272829303132333435
  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)