From 047cef845d2807556d587b4e061ec3e9ec6d29ae Mon Sep 17 00:00:00 2001 From: James Curtin Date: Fri, 7 Jun 2019 23:31:40 -0400 Subject: [PATCH] Fix logging issue Closes #247 --- tasks.py | 2 ++ {{cookiecutter.app_name}}/docker-compose.yml | 3 +++ .../{{cookiecutter.app_name}}/app.py | 11 +++++++++++ .../{{cookiecutter.app_name}}/public/views.py | 3 ++- 4 files changed, 18 insertions(+), 1 deletion(-) diff --git a/tasks.py b/tasks.py index 0a57d8c..ec347b6 100644 --- a/tasks.py +++ b/tasks.py @@ -55,6 +55,8 @@ def test(ctx): os.chdir(COOKIE) shutil.copyfile(os.path.join(COOKIE, '.env.example'), os.path.join(COOKIE, '.env')) + os.environ["FLASK_ENV"] = "production" + os.environ["FLASK_DEBUG"] = "0" _run_flask_command(ctx, 'lint') _run_flask_command(ctx, 'test') diff --git a/{{cookiecutter.app_name}}/docker-compose.yml b/{{cookiecutter.app_name}}/docker-compose.yml index bce64af..d9a6dce 100644 --- a/{{cookiecutter.app_name}}/docker-compose.yml +++ b/{{cookiecutter.app_name}}/docker-compose.yml @@ -43,6 +43,9 @@ services: build: context: . target: manage + environment: + FLASK_ENV: production + FLASK_DEBUG: 0 image: "{{cookiecutter.app_name}}-manage" stdin_open: true tty: true diff --git a/{{cookiecutter.app_name}}/{{cookiecutter.app_name}}/app.py b/{{cookiecutter.app_name}}/{{cookiecutter.app_name}}/app.py index 0879645..efa9fb7 100644 --- a/{{cookiecutter.app_name}}/{{cookiecutter.app_name}}/app.py +++ b/{{cookiecutter.app_name}}/{{cookiecutter.app_name}}/app.py @@ -1,5 +1,8 @@ # -*- coding: utf-8 -*- """The app module, containing the app factory function.""" +import logging +import sys + from flask import Flask, render_template from {{cookiecutter.app_name}} import commands, public, user @@ -18,6 +21,7 @@ def create_app(config_object='{{cookiecutter.app_name}}.settings'): register_errorhandlers(app) register_shellcontext(app) register_commands(app) + configure_logger(app) return app @@ -70,3 +74,10 @@ def register_commands(app): app.cli.add_command(commands.lint) app.cli.add_command(commands.clean) app.cli.add_command(commands.urls) + + +def configure_logger(app): + """Configure loggers.""" + handler = logging.StreamHandler(sys.stdout) + if not app.logger.handlers: + app.logger.addHandler(handler) diff --git a/{{cookiecutter.app_name}}/{{cookiecutter.app_name}}/public/views.py b/{{cookiecutter.app_name}}/{{cookiecutter.app_name}}/public/views.py index 8fe92e3..c64810d 100644 --- a/{{cookiecutter.app_name}}/{{cookiecutter.app_name}}/public/views.py +++ b/{{cookiecutter.app_name}}/{{cookiecutter.app_name}}/public/views.py @@ -1,6 +1,6 @@ # -*- coding: utf-8 -*- """Public section, including homepage and signup.""" -from flask import Blueprint, flash, redirect, render_template, request, url_for +from flask import Blueprint, current_app, flash, redirect, render_template, request, url_for from flask_login import login_required, login_user, logout_user from {{cookiecutter.app_name}}.extensions import login_manager @@ -22,6 +22,7 @@ def load_user(user_id): def home(): """Home page.""" form = LoginForm(request.form) + current_app.logger.info('Hello from the home page!') # Handle logging in if request.method == 'POST': if form.validate_on_submit():