logging - 在 Azure Service Fabric 中托管时,使用 AppInsights 从 Python 中的 Flask 日志不显示
问题描述
在本地运行我的烧瓶应用程序时,我可以使用端点并且这些日志消息出现在我的 Azure 门户的 Application Insights 资源中。
在 Service Fabric 容器中运行我的烧瓶应用程序时,我可以使用本地计算机中的端点并获得工作响应,请求信息确实出现在 Application Insights 中,但日志消息没有。
示例代码:
from flask import Flask, jsonify
from flasgger import Swagger
from applicationinsights.flask.ext import AppInsights
from config.AppConfig import configure_app
# create Flask app
app = Flask(__name__)
# configure app from settings
configure_app(app)
# initiate Application Insights - allowing requests, exceptions and logs to be examined in Azure Portal
appinsights = AppInsights(app)
Swagger(app)
# force flushing application insights handler after each request
@app.after_request
def after_request(response):
appinsights.flush()
return response
# api routes
@app.route('/diagnostics', methods=['GET'])
def get_diagnostics():
"""This is a diagnostics endpoint to test connectivity.
---
operationId: get_diagnostics
produces:
- application/json
responses:
200:
description: returns ok
examples:
{
"status": "ok"
}
"""
app.logger.info('Diagnostics endpoint was used.')
app.logger.debug('This is a debug log message')
app.logger.info('This is an information log message')
app.logger.warn('This is a warning log message')
app.logger.error('This is an error message')
app.logger.critical('This is a critical message')
return jsonify({'status': "ok"}), 200
if __name__ == "__main__":
host = app.config['SERVER_HOST']
port = int(app.config['SERVER_PORT'])
app.logger.info('DataScience starting on port %s ... ', port)
app.run(host, port)
检测密钥在应用配置中设置,如前所述,在非本地运行时请求仍显示在 Azure 门户中。
有什么建议么?谢谢你。
解决方案
推荐阅读
- python - 如何处理 Python Numpy 中的精度问题?
- javascript - 回调箭头函数不会从它的父函数继承“this”**这不是重复的**
- arrays - 尝试在 C 中创建打字效果
- html - 如何在带有方向列的 flex 中定位单个组件?
- r - 与 R 中的两个数据框相比,如何插入列(缺少日期)?
- javascript - 动态创建 React 应用程序安装在其上的元素
- c++ - 错误:C2061:语法错误:标识符'concurrent_vector<`template-type-parameter-1',`template-type-parameter-2'>'
- python-3.x - 列表作为字典值
- spring-data-jdbc - 自定义分页查询无法返回 Page
类型? - python - 在 PyQt5 中创建循环