app.py的代码：

from flask import Flask, render_template, request, send_file
import os

app = Flask(__name__)

# 定义日志文件路径
log_files = {
    '项目名用英文': '/www/wwwroot/你的日志保存地址/error.log'
}

@app.route('/')
def index():
    return render_template('index.html')

@app.route('/get_log', methods=['GET'])
def get_log():
    log_key = request.args.get('log_key')
    if log_key in log_files:
        log_path = log_files[log_key]
        if os.path.exists(log_path):
            return send_file(log_path, mimetype='text/plain')
    return "Log file not found", 404

if __name__ == '__main__':
    app.run(debug=True, host='0.0.0.0', port=5000)

=============================================================
templates/index.html的代码：

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Log Viewer</title>
    <style>
        button {
            margin: 5px;
            margin-left: 20px;
            /* 修改部分：将按钮字号设大一号 */
            font-size: larger;
        }
        textarea {
            width: 95%;
            height: 600px;
            margin-top: 20px;
            margin-left: 20px;
        }
    </style>
</head>
<body>
    <!-- 定义按钮 -->
    <button onclick="loadLog('app中的项目名')">项目名称</button>

    <!-- 新增清空按钮 -->
    <!-- <button onclick="clearLog()">清空</button> -->

    <!-- 新增复选框用于控制自动刷新 -->
    <input type="checkbox" id="auto-refresh-checkbox" checked onchange="toggleAutoRefresh()"> 自动刷新

    <!-- 文本输出框 -->
    <textarea id="log-output" readonly></textarea>

    <script>
        let currentLogKey = null;
        let refreshInterval = null;
        const autoRefreshCheckbox = document.getElementById('auto-refresh-checkbox');

        function loadLog(logKey) {
            currentLogKey = logKey;
            // 加载日志文件内容
            fetchLog();
            // 清除之前的刷新间隔
            if (refreshInterval) {
                clearInterval(refreshInterval);
            }
            // 根据复选框状态设置刷新间隔
            if (autoRefreshCheckbox.checked) {
                refreshInterval = setInterval(fetchLog, 1000);
            }
        }

        function toggleAutoRefresh() {
            if (autoRefreshCheckbox.checked) {
                if (!refreshInterval && currentLogKey) {
                    refreshInterval = setInterval(fetchLog, 1000);
                }
            } else {
                if (refreshInterval) {
                    clearInterval(refreshInterval);
                    refreshInterval = null;
                }
            }
        }

        function fetchLog() {
            if (currentLogKey) {
                // 发送请求获取日志文件内容
                fetch(`/get_log?log_key=${currentLogKey}`)
                   .then(response => response.text())
                   .then(data => {
                        // 更新文本输出框内容
                        const logOutput = document.getElementById('log-output');
                        logOutput.value = data;
                        // 将滚动条设置到最底部
                        logOutput.scrollTop = logOutput.scrollHeight;
                    });
            }
        }

        // // 新增清空函数
        // function clearLog() {
        //     const logOutput = document.getElementById('log-output');
        //     logOutput.value = '';
        // }
    </script>
</body>
</html>