import time
import platform
import os
from flask import Flask
from flask_cors import CORS
from interfaces.resume import resume
from interfaces.rocketmq import rocket
import logging
from logging.handlers import TimedRotatingFileHandler

app = Flask(__name__)
app.config['JSON_AS_ASCII'] = False
CORS(app, resources=r'/*')

# 注册蓝图
app.register_blueprint(resume, url_prefix='/resume')
app.register_blueprint(rocket, url_prefix='/rocket')

# 设置日志目录-----设置为当前脚本文件所在的目录下的 logs 目录。
log_directory = os.path.join(os.path.dirname(__file__), 'logs')
os.makedirs(log_directory, exist_ok=True)

# 配置日志
formatter = logging.Formatter("[%(asctime)s][%(filename)s:%(lineno)d][%(levelname)s][%(thread)d] - %(message)s")
handler = TimedRotatingFileHandler(os.path.join(log_directory, "flask.log"), when="midnight", interval=1, backupCount=15, encoding="UTF-8",delay=True)
handler.setFormatter(formatter)
app.logger.addHandler(handler)
app.logger.setLevel(logging.DEBUG)

# 启动应用
def run_app():
    plat = platform.system().lower()
    if plat == 'windows':
        app.run(host='0.0.0.0', port=3333, debug=True, use_reloader=True)
    elif plat == 'linux':
        app.run(host='0.0.0.0', port=3333, debug=False, processes=3)

if __name__ == '__main__':
    run_app()

