我正在使用Flask的Hello World版本。我想将日志记录添加到文件中。当我添加以下行时,Flask应用程序将永远不会启动:
logging.basicConfig(filename=os.path.join(os.path.dirname(os.path.realpath(__file__)), 'errors.txt'),
level=logging.ERROR)
完整代码:
import logging
import os
from flask import Flask
app = Flask(__name__)
@app.route('/')
def hello_world():
return 'Hello, World!'
logging.basicConfig(filename=os.path.join(os.path.dirname(os.path.realpath(__file__)), 'errors.txt'),
level=logging.ERROR)
app.run()