Merge pull request #501 from cookiecutter-flask/fix-247

Fix logging issue
master
James Curtin 5 years ago committed by GitHub
commit 196aafe2fb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      tasks.py
  2. 3
      {{cookiecutter.app_name}}/docker-compose.yml
  3. 11
      {{cookiecutter.app_name}}/{{cookiecutter.app_name}}/app.py
  4. 3
      {{cookiecutter.app_name}}/{{cookiecutter.app_name}}/public/views.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')

@ -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

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

@ -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():

Loading…
Cancel
Save