Files
multi_camera/app/__init__.py

43 lines
1.2 KiB
Python

"""
Flask应用工厂
"""
import logging
from flask import Flask
from .config import DEBUG, SECRET_KEY, HOST, PORT
from .health import register_health_routes
from .routes.main import register_main_routes
def create_app():
"""创建Flask应用实例"""
app = Flask(__name__,
static_folder='../static',
template_folder='templates')
# 配置
app.config['DEBUG'] = DEBUG
app.config['SECRET_KEY'] = SECRET_KEY
# 配置日志
configure_logging(app)
# 注册路由
register_health_routes(app)
register_main_routes(app)
return app
def configure_logging(app):
"""配置日志"""
if not app.debug:
# 在生产环境中,将日志输出到文件
import logging
from logging.handlers import RotatingFileHandler
file_handler = RotatingFileHandler('multi_camera.log', maxBytes=10240, backupCount=10)
file_handler.setFormatter(logging.Formatter(
'%(asctime)s - %(levelname)s - %(message)s'
))
file_handler.setLevel(logging.INFO)
app.logger.addHandler(file_handler)
app.logger.setLevel(logging.INFO)
app.logger.info('多摄像头监控系统启动')