diff --git a/Procfile b/Procfile new file mode 100644 index 0000000..216c639 --- /dev/null +++ b/Procfile @@ -0,0 +1 @@ +web: flask db upgrade; flask translate compile; gunicorn microblog:app diff --git a/app/__init__.py b/app/__init__.py index a1b9e2b..1abc540 100644 --- a/app/__init__.py +++ b/app/__init__.py @@ -63,15 +63,20 @@ def create_app(config_class=Config): mail_handler.setLevel(logging.ERROR) app.logger.addHandler(mail_handler) - if not os.path.exists('logs'): - os.mkdir('logs') - file_handler = RotatingFileHandler('logs/microblog.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 app.config['LOG_TO_STDOUT']: + stream_handler = logging.StreamHandler() + stream_handler.setLevel(logging.INFO) + app.logger.addHandler(stream_handler) + else: + if not os.path.exists('logs'): + os.mkdir('logs') + file_handler = RotatingFileHandler('logs/microblog.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('Microblog startup') diff --git a/config.py b/config.py index 15415a1..15de317 100644 --- a/config.py +++ b/config.py @@ -10,6 +10,7 @@ class Config(object): SQLALCHEMY_DATABASE_URI = os.environ.get('DATABASE_URL') or \ 'sqlite:///' + os.path.join(basedir, 'app.db') SQLALCHEMY_TRACK_MODIFICATIONS = False + LOG_TO_STDOUT = os.environ.get('LOG_TO_STDOUT') 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 diff --git a/requirements.txt b/requirements.txt index f16ff6f..f3c7b17 100644 --- a/requirements.txt +++ b/requirements.txt @@ -33,3 +33,7 @@ urllib3==1.22 visitor==0.1.3 Werkzeug==0.12.2 WTForms==2.1 + +# requirements for Heroku +psycopg2==2.7.3.1 +gunicorn==19.7.1