Skip to content

Commit

Permalink
uncomment email and file logging code written a long time ago but dis…
Browse files Browse the repository at this point in the history
…abled lol
  • Loading branch information
xochozomatli committed Jan 1, 2021
1 parent 85d1580 commit aa3dfe7
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 36 deletions.
58 changes: 28 additions & 30 deletions api/app/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,38 +33,36 @@ def create_app(config_class=Config):
from app.api import bp as api_bp
app.register_blueprint(api_bp, url_prefix='/api')

########################################################
### Everything below is unused mail and logging code ###
########################################################
# if not app.debug and not app.testing:
# if app.config['MAIL_SERVER']:
# auth = None
# if app.config['MAIL_USERNAME'] or app.config['MAIL_PASSWORD']:
# auth = (app.config['MAIL_USERNAME'],
# app.config['MAIL_PASSWORD'])
# secure = None
# if app.config['MAIL_USE_TLS']:
# secure = ()
# mail_handler = SMTPHandler(
# mailhost=(app.config['MAIL_SERVER'], app.config['MAIL_PORT']),
# fromaddr='no-reply@' + app.config['MAIL_SERVER'],
# toaddrs=app.config['ADMINS'], subject='Totlahtol Failure',
# credentials=auth, secure=secure)
# mail_handler.setLevel(logging.ERROR)
# app.logger.addHandler(mail_handler)
# Emails stack trace to ADMINS if app crashes
if not app.debug and not app.testing:
if app.config['MAIL_SERVER']:
auth = None
if app.config['MAIL_USERNAME'] or app.config['MAIL_PASSWORD']:
auth = (app.config['MAIL_USERNAME'],
app.config['MAIL_PASSWORD'])
secure = None
if app.config['MAIL_USE_TLS']:
secure = ()
mail_handler = SMTPHandler(
mailhost=(app.config['MAIL_SERVER'], app.config['MAIL_PORT']),
fromaddr='no-reply@' + app.config['MAIL_SERVER'],
toaddrs=app.config['ADMINS'], subject='Totlahtol Failure',
credentials=auth, secure=secure)
mail_handler.setLevel(logging.ERROR)
app.logger.addHandler(mail_handler)

# if not os.path.exists('logs'):
# os.mkdir('logs')
# file_handler = RotatingFileHandler('logs/totlahtol.log',
# maxBytes=10240, backupCount=10)
# file_handler.setFormatter(logging.Formatter(
# '%(asctime)s %(levelname)s: %(message)s '
# '[in %(pathname)s:%(lineno)d]'))
# file_handler.setLevel(logging.INFO)
# app.logger.addHandler(file_handler)
if not os.path.exists('logs'):
os.mkdir('logs')
file_handler = RotatingFileHandler('logs/totlahtol.log',
maxBytes=10240, backupCount=10)
file_handler.setFormatter(logging.Formatter(
'%(asctime)s %(levelname)s: %(message)s '
'[in %(pathname)s:%(lineno)d]'))
file_handler.setLevel(logging.INFO)
app.logger.addHandler(file_handler)

# app.logger.setLevel(logging.INFO)
# app.logger.info('Totlahtol startup')
app.logger.setLevel(logging.INFO)
app.logger.info('Totlahtol startup')

return app

Expand Down
12 changes: 6 additions & 6 deletions api/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@ class Config(object):
SQLALCHEMY_DATABASE_URI = os.environ.get('DATABASE_URL') or \
'sqlite:///' + os.path.join(basedir, 'app.db')
SQLALCHEMY_TRACK_MODIFICATIONS = False
# MAIL_SERVER = os.environ.get('MAIL_SERVER')
# MAIL_PORT = int(os.environ.get('MAIL_PORT') or 25)
# MAIL_USE_TLS = os.environ.get('MAIL_USE_TLS') is not None
# MAIL_USERNAME = os.environ.get('MAIL_USERNAME')
# MAIL_PASSWORD = os.environ.get('MAIL_PASSWORD')
# ADMINS = ['[email protected]']
MAIL_SERVER = os.environ.get('MAIL_SERVER')
MAIL_PORT = int(os.environ.get('MAIL_PORT') or 25)
MAIL_USE_TLS = os.environ.get('MAIL_USE_TLS') is not None
MAIL_USERNAME = os.environ.get('MAIL_USERNAME')
MAIL_PASSWORD = os.environ.get('MAIL_PASSWORD')
ADMINS = ['[email protected]']
# POSTS_PER_PAGE = 3
# LANGUAGES = ['en', 'es']
# MS_TRANSLATOR_KEY=os.environ.get('MS_TRANSLATOR_KEY')

0 comments on commit aa3dfe7

Please sign in to comment.