码迷,mamicode.com
首页 > 其他好文 > 详细

FLASK日志记录

时间:2017-03-12 15:28:04      阅读:251      评论:0      收藏:0      [点我收藏+]

标签:file   utf-8   restful   orm   flask   log   logs   his   import   

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日志记录

标签:file   utf-8   restful   orm   flask   log   logs   his   import   

原文地址:http://www.cnblogs.com/wanghaonull/p/6537823.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!