haldis/app/app.py
2019-04-05 23:26:57 +02:00

48 lines
1.4 KiB
Python

import logging
from logging.handlers import TimedRotatingFileHandler
from flask import Flask
from flask_bootstrap import Bootstrap, StaticCDN
from flask_sqlalchemy import SQLAlchemy
from flask_debugtoolbar import DebugToolbarExtension
from airbrake import Airbrake, AirbrakeHandler
app = Flask(__name__)
app.config.from_object('config.Configuration')
Bootstrap(app)
app.config['BOOTSTRAP_SERVE_LOCAL'] = True
# use our own bootstrap theme
app.extensions['bootstrap']['cdns']['bootstrap'] = StaticCDN()
db = SQLAlchemy(app)
toolbar = DebugToolbarExtension(app)
if not app.debug:
timedFileHandler = TimedRotatingFileHandler(app.config['LOGFILE'], when='midnight', backupCount=100)
timedFileHandler.setLevel(logging.DEBUG)
loglogger = logging.getLogger('werkzeug')
loglogger.setLevel(logging.DEBUG)
loglogger.addHandler(timedFileHandler)
app.logger.addHandler(timedFileHandler)
airbrakelogger = logging.getLogger('airbrake')
# Airbrake
airbrake = Airbrake(
project_id=app.config['AIRBRAKE_ID'],
api_key=app.config['AIRBRAKE_KEY']
)
# ugly hack to make this work for out errbit
airbrake._api_url = "http://errbit.awesomepeople.tv/api/v3/projects/{}/notices".format(airbrake.project_id)
airbrakelogger.addHandler(
AirbrakeHandler(airbrake=airbrake)
)
app.logger.addHandler(
AirbrakeHandler(airbrake=airbrake)
)