💎一站式轻松地调用各大LLM模型接口,支持GPT4、智谱、星火、月之暗面及文生图 广告
### 手动记录 在控制器文件中使用 ``` #!/usr/bin/env python3 # -*- encoding: utf-8 -*- from app.api_1_0 import bp from flask import render_template, current_app @bp.route('/', methods=['GET']) def index(): pass @bp.route('/mylog') def logtest(): current_app.logger.debug("我是 debug 级别") current_app.logger.info("我是 info 级别") current_app.logger.warning("我是 warning 级别") current_app.logger.error("我是 error 级别") current_app.logger.critical("我是 critical 级别") try: num = 1/0 except ZeroDivisionError as e: current_app.logger.error("除数为 0") except Exception as e: current_app.logger("未知原因报错") return '愿世界一切安好,程序永无BUG!!!' ``` 访问测试 `root@airvip:~/python_app/flask-demo# curl 127.0.0.1:5000/api/v1.0/mylog` 我们可以在 `logs/log` 文件中查看到如下内容 ``` DEBUG index.py:20 我是 debug 级别 INFO index.py:21 我是 info 级别 WARNING index.py:22 我是 warning 级别 ERROR index.py:23 我是 error 级别 CRITICAL index.py:24 我是 critical 级别 ERROR index.py:29 除数为 0 INFO _internal.py:113 127.0.0.1 - - [30/Dec/2020 10:12:06] "GET /api/v1.0/mylog HTTP/1.1" 200 - ```