mirror of
https://github.com/rmontanana/microblog.git
synced 2025-08-16 15:55:51 +00:00
Chapter 7
This commit is contained in:
@@ -1,8 +1,13 @@
|
||||
import os
|
||||
from flask import Flask
|
||||
from config import Config
|
||||
import logging
|
||||
from loggin.handlers import RotatingFileHandler
|
||||
from logging.handlers import SMTPHandler
|
||||
from flask_sqlalchemy import SQLAlchemy
|
||||
from flask_migrate import Migrate
|
||||
from flask_login import LoginManager
|
||||
from app import routes, models, errors
|
||||
|
||||
app = Flask(__name__)
|
||||
app.config.from_object(Config)
|
||||
@@ -16,4 +21,36 @@ login = LoginManager(app)
|
||||
# sets de default login view
|
||||
login.login_view = "login"
|
||||
|
||||
from app import routes, models
|
||||
if not app.debug:
|
||||
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="Microblog 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/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")
|
||||
|
Reference in New Issue
Block a user