# Librairies Python
import os
import logging
from logging.handlers import RotatingFileHandler
from flask import Flask
# Import fichiers homemade
from config import Config

# Version + Nom créateur
__version__ = (0, 0, 8)
__author__ = 'Enzo Foucaud'
# Création de l'application
app = Flask(__name__)
app.config.from_object(Config)

from oxyapp.errors import bp as errors_bp
app.register_blueprint(errors_bp)

from oxyapp.auth import bp as auth_bp
app.register_blueprint(auth_bp)

from oxyapp.main import bp as main_bp
app.register_blueprint(main_bp)

# Permet de générer un .txt pour les erreurs
if not app.debug:
    if not os.path.exists('logs'):
        os.mkdir('logs')
    file_handler = RotatingFileHandler('logs/oxycardio.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('Oxycardio')

from oxyapp import errors, auth, main
