FLASK日志记录
Posted webbky
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了FLASK日志记录相关的知识,希望对你有一定的参考价值。
from flask import Flask from flask_restful import Resource, Api import logging app = Flask(__name__) api = Api(app) # app.logger.debug(‘A value for debugging‘) # app.logger.warning(‘A warning occurred (%d apples)‘, 42) # app.logger.error(‘An error occurred‘) class HelloWorld(Resource): def get(self): app.logger.info(‘this is a string‘) app.logger.debug(‘A value for debugging‘) app.logger.warning(‘A warning occurred (%d apples)‘, 42) app.logger.error(‘An error occurred‘) return {‘hello‘: ‘world‘} api.add_resource(HelloWorld, ‘/‘) if __name__ == ‘__main__‘: handler = logging.FileHandler(‘flask2.log‘, encoding=‘UTF-8‘) handler.setLevel(logging.DEBUG) logging_format = logging.Formatter( ‘%(asctime)s - %(levelname)s - %(filename)s - %(funcName)s - %(lineno)s - %(message)s‘) handler.setFormatter(logging_format) app.logger.addHandler(handler) app.run(debug=True)
更多 http://www.qingpingshan.com/bc/flex/205196.html
https://www.polarxiong.com/archives/Flask%E4%BD%BF%E7%94%A8%E6%97%A5%E5%BF%97%E8%AE%B0%E5%BD%95%E5%88%B0%E6%96%87%E4%BB%B6%E7%A4%BA%E4%BE%8B.html
以上是关于FLASK日志记录的主要内容,如果未能解决你的问题,请参考以下文章