首页 > 代码库 > FLASK日志记录
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日志记录
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。