Azure Function App(Linux Python)无法查看日志求助
Linux Python Azure Function App 日志查看问题解答
核心结论
是的,Linux托管的Python Azure Function App必须关联Application Insights资源才能使用以下日志功能:
- Azure门户的「Log Stream」标签页流式日志
- 「Code + Test」界面的控制台日志
- VS Code Azure扩展的日志流功能
这是因为Azure Functions针对Linux环境的日志架构设计,上述可视化/流式日志功能依赖Application Insights的数据管道,未关联时这些界面会因缺少数据源持续处于加载状态,无法展示日志。
无需新建Application Insights的日志查看替代方案
如果受限于企业架构无法创建新资源,可通过以下方式获取日志:
直接访问Kudu控制台的日志文件
- 进入Function App的「高级工具」,点击「Go」打开Kudu界面
- 导航到路径:
/home/LogFiles/Application/Functions/Function/http_trigger_test - 查看目录下的日志文件,里面包含函数执行的
logging输出、错误信息等内容
使用Azure CLI查看日志
执行以下命令(替换占位符为你的资源信息):az functionapp log tail --name <你的Function App名称> --resource-group <所属资源组名称>该命令可直接拉取函数的实时日志输出,无需依赖Application Insights。
本地调试查看日志
使用Azure Functions Core Tools在本地运行函数,通过本地控制台直接查看日志:func start此方式完全不依赖云端资源,适合开发阶段调试。
附用户提供的相关代码
function_app.py
import azure.functions as func import logging @app.route(route="http_trigger_test") def http_trigger_test(req: func.HttpRequest) -> func.HttpResponse: logging.info('Python HTTP trigger function processed a request.') return func.HttpResponse(f"Code finished", status_code=200)
requirements.txt
# DO NOT include azure-functions-worker in this file # The Python Worker is managed by Azure Functions platform # Manually managing azure-functions-worker may cause unexpected issues azure-functions
http_trigger_test.json
{ "name": "http_trigger_test", "entryPoint": "http_trigger_test", "scriptFile": "function_app.py", "language": "python", "functionDirectory": "/home/site/wwwroot", "bindings": [ { "direction": "IN", "type": "httpTrigger", "name": "req", "authLevel": "ANONYMOUS", "route": "http_trigger_test" }, { "direction": "OUT", "type": "http", "name": "$return" } ] }
内容的提问来源于stack exchange,提问作者herdek550
相关产品推荐
相关产品推荐

