首页 > 代码库 > 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日志记录