我想将标准输出和标准错误记录到日志文件中,这就是我尝试过的。
app = Flask(__name__)
app.logger.setLevel(logging.INFO) # use the native logger of flask
app.logger.disabled = False
handler = logging.handlers.RotatingFileHandler(
SYSTEM_LOG_FILENAME,
'a',
maxBytes=1024 * 1024 * 100,
backupCount=20
)
formatter = logging.Formatter(\
"%(asctime)s - %(levelname)s - %(name)s: \t%(message)s")
handler.setFormatter(formatter)
app.logger.addHandler(handler)
@app.route('/')
def hello():
return 'Hello World'
if __name__ == '__main__':
app.run()
然后我想将控制台输出记录在文件中。如
* Running on http://127.0.0.1:5000/
127.0.0.1 - - [24/May/2013 14:55:14] "GET / HTTP/1.1" 200 -
127.0.0.1 - - [24/May/2013 14:55:14] "GET /favicon.ico HTTP/1.1" 404 -
我能做些什么?