【Azure Function】开启Azure Function输出详细Debug日志 ( --verbose)

简介: 【Azure Function】开启Azure Function输出详细Debug日志 ( --verbose)

When func.exe is run from VS, it suggests "For detailed output, run func with --verbose flag."

问题描述

在本地调式Azure Function时候,默认输出的日志都是比较简洁的。如果需要详细的日志输出,可以在启动func命令中添加--verbose参数。那如何来添加呢?

日志输出对比:

开启前日志 开启后日志
Hosting environment: Production
Content root path: /home/pont/projects/fibre-collective/packages/certification
Now listening on: http://0.0.0.0:7071
Application started. Press Ctrl+C to shut down.
Value cannot be null. (Parameter 'provider')
Azure Functions Core Tools (3.0.2358 Commit hash: d6d66f19ea30fda5fbfe068fc22bc126f0a74168)
Function Runtime Version: 3.0.13159.0
[5/19/2020 12:09:26 PM] FUNCTIONS_WORKER_RUNTIME set to node. Skipping WorkerConfig for language:python
[5/19/2020 12:09:26 PM] FUNCTIONS_WORKER_RUNTIME set to node. Skipping WorkerConfig for language:java
[5/19/2020 12:09:26 PM] FUNCTIONS_WORKER_RUNTIME set to node. Skipping WorkerConfig for language:powershell
[5/19/2020 12:09:26 PM] Building host: startup suppressed: 'False', configuration suppressed: 'False', startup operation id: '190e8a62-6b3e-48f1-83d1-a3ede0bce239'
[5/19/2020 12:09:26 PM] Reading host configuration file '/home/pont/projects/fibre-collective/packages/certification/host.json'
[5/19/2020 12:09:26 PM] Host configuration file read:
[5/19/2020 12:09:26 PM] {
[5/19/2020 12:09:26 PM]   "version": "2.0",
[5/19/2020 12:09:26 PM]   "logging": {
[5/19/2020 12:09:26 PM]     "applicationInsights": {
[5/19/2020 12:09:26 PM]       "samplingExcludedTypes": "Request",
[5/19/2020 12:09:26 PM]       "samplingSettings": {
[5/19/2020 12:09:26 PM]         "isEnabled": true
[5/19/2020 12:09:26 PM]       }
[5/19/2020 12:09:26 PM]     }
[5/19/2020 12:09:26 PM]   },
[5/19/2020 12:09:26 PM]   "extensionBundle": {
[5/19/2020 12:09:26 PM]     "id": "Microsoft.Azure.Functions.ExtensionBundle",
[5/19/2020 12:09:26 PM]     "version": "[1.*, 2.0.0)"
[5/19/2020 12:09:26 PM]   }
[5/19/2020 12:09:26 PM] }
[5/19/2020 12:09:26 PM] Reading functions metadata
[5/19/2020 12:09:26 PM] 1 functions found
[5/19/2020 12:09:26 PM] Looking for extension bundle Microsoft.Azure.Functions.ExtensionBundle at /tmp/Functions/ExtensionBundles/Microsoft.Azure.Functions.ExtensionBundle
[5/19/2020 12:09:26 PM] Fetching information on versions of extension bundle Microsoft.Azure.Functions.ExtensionBundle available on https://functionscdn.azureedge.net/public/ExtensionBundles/Microsoft.Azure.Functions.ExtensionBundle/index.json
[5/19/2020 12:09:27 PM] Downloading extension bundle from https://functionscdn.azureedge.net/public/ExtensionBundles/Microsoft.Azure.Functions.ExtensionBundle/1.1.1/Microsoft.Azure.Functions.ExtensionBundle.1.1.1.zip to /tmp/d87a8cf9-a864-42f0-a891-b7e41a7d103d/Microsoft.Azure.Functions.ExtensionBundle.1.1.1.zip
Hosting environment: Production
Content root path: /home/pont/projects/fibre-collective/packages/certification
Now listening on: http://0.0.0.0:7071
Application started. Press Ctrl+C to shut down.
[5/19/2020 12:11:22 PM] Executing HTTP request: {
[5/19/2020 12:11:22 PM]   "requestId": "90571ec9-f3f7-4606-b012-62097466c9a3",
[5/19/2020 12:11:22 PM]   "method": "GET",
[5/19/2020 12:11:22 PM]   "uri": "/"
[5/19/2020 12:11:22 PM] }
System.ArgumentNullException: Value cannot be null. (Parameter 'provider')
   at Microsoft.Extensions.DependencyInjection.ServiceProviderServiceExtensions.GetRequiredService[T](IServiceProvider provider)
   at Azure.Functions.Cli.Actions.HostActions.StartHostAction.RunAsync() in D:\a\1\s\src\Azure.Functions.Cli\Actions\HostActions\StartHostAction.cs:line 252
   at Azure.Functions.Cli.ConsoleApp.RunAsync[T](String[] args, IContainer container) in D:\a\1\s\src\Azure.Functions.Cli\ConsoleApp.cs:line 66
Application is shutting down...
[5/19/2020 12:11:45 PM] Stopping host...
[5/19/2020 12:11:45 PM] Host shutdown completed.

 

开启方式

方式一:在VS Code中修改.vscode\launch.json文件中的启动命令

默认通过VS Code创建一个Java Azure Function的文件目录结构为:

PS C:\Function>  tree /f
Folder PATH listing for volume OSDisk
Volume serial number is 4A75-5D11
C:.
   .classpath
   .gitignore
   .project
   host.json
   local.settings.json
   pom.xml

├───.settings
       org.eclipse.core.resources.prefs
       org.eclipse.jdt.apt.core.prefs
       org.eclipse.jdt.core.prefs
       org.eclipse.m2e.core.prefs

├───.vscode
       extensions.json
       launch.json
       settings.json
       tasks.json

├───src
   ├───main
      └───java
          └───com
              └───function
                      Function.java
   
   └───test
       └───java
           └───com
               └───function
                       FunctionTest.java
                       HttpResponseMessageMock.java

 

在launch.json文件中,添加启动参数 --verbose

{
  "version": "0.2.0",
  "configurations": [
    {
      "name": "Attach to Java Functions",
      "type": "java",
      "request": "attach",
      "hostName": "127.0.0.1",
      "port": 5005,
      "preLaunchTask": "func: host start --verbose"
    }
  ]
}

点击F5,从VS Code中启动Azure Function,根据提示,在tasks.json也需要添加--verbose参数

{
  "version": "2.0.0",
  "tasks": [
    {
      "type": "func",
      "command": "host start --verbose",
      "problemMatcher": "$func-java-watch",
      "isBackground": true,
      "options": {
        "cwd": "${workspaceFolder}/target/azure-functions/myFunction-0115"
      },
      "dependsOn": "package"
    },
    {
      "label": "package",
      "command": "mvn clean package",
      "type": "shell",
      "group": {
        "kind": "build",
        "isDefault": true
      }
    }
  ]
}

 

方式二:直接通过命令行启动Azure Funciton,使用完整命令: func host --

verbose 
PS C:\Function> func  start --verbose

 

效果展示:

 

参考资料:

Value cannot be null. (Parameter 'provider'): https://github.com/Azure/azure-functions-core-tools/issues/2232

在 Azure 中使用 Visual Studio Code 创建 Java 函数: https://docs.azure.cn/zh-cn/azure-functions/create-first-function-vs-code-java

 

相关实践学习
通过日志服务实现云资源OSS的安全审计
本实验介绍如何通过日志服务实现云资源OSS的安全审计。
相关文章
|
6月前
|
API C++
【Azure 环境】VS Code登录China Azure(Function)报错 An error occurred while signing in: invalid_request - AADSTS65002
An error occurred while signing in: invalid_request - AADSTS65002: Consent between first party application 'c27c220f-ce2f-4904-927d-333864217eeb' and first party resource '797f4846-ba00-4fd7-ba43-dac1f8f63013' must be configured via preauthorization - applications owned and operated by Microsoft mus
330 13
|
10月前
|
存储 安全 数据安全/隐私保护
【Azure Function App】在Function App中使用System Managed Identity访问Storage Account
本文介绍了如何在Azure Function中使用托管身份(Managed Identity)替代AzureWebJobsStorage连接函数应用到存储账户,以提高安全性并减少Access Key的使用。具体步骤包括:1) 启用系统分配的身份;2) 为函数应用授予存储访问权限,添加必要角色(如Storage Blob Data Contributor);3) 配置`AzureWebJobsStorage__blobServiceUri`参数指定Blob Service Uri。完成后删除旧配置,即可通过Managed Identity访问Storage Account。
332 19
|
5月前
|
数据安全/隐私保护
【Azure Function App】PowerShell Function 执行 Get-AzAccessToken 的返回值类型问题:System.String 与 System.Security.SecureString
将PowerShell Function部署到Azure Function App后,Get-AzAccessToken返回值类型在不同环境中有差异。正常为SecureString类型,但部分情况下为System.String类型,导致后续处理出错。解决方法是在profile.ps1中设置环境变量$env:AZUREPS_OUTPUT_PLAINTEXT_AZACCESSTOKEN=false,以禁用明文输出。
177 1
|
6月前
|
JSON 数据格式
【Azure 环境】当一个Azure Function资源创建很久了,是否可以获取到它的创建时间呢?
用户在尝试获取 Azure Function App 的创建时间时发现,资源 JSON 中缺少 `createdTime` 字段,仅能查看到 `lastModifiedTime`。同时,活动日志和 Azure Resource Graph 查询也未能提供创建时间信息。经解答,Azure 并未为所有资源类型记录创建时间,建议在部署时将创建时间作为标签记录。若创建时间在 90 天内,可通过部署日志间接获取。
234 7
|
7月前
|
网络协议 API 网络安全
【Azure Function App】发现部分请求Function App遇见 403.72 报错(请求Body>100KB)
在调用Azure Function的HTTP Trigger时,发送POST请求偶尔出现403错误,且响应为空、Header信息少。经排查发现,当请求Body大于100KB时会触发403.72错误,原因是启用了“Client Certificate mode”为“Optional Interactive User”。解决方法是将该模式设置为“Ignore”。由于TLS重新协商机制限制,大请求体无法正常处理,导致此问题。
241 1
|
10月前
|
JSON API 数据格式
【Azure APIM】如何把APIM中处理的请求的所有请求头保存在日志中?
Azure API Management 默认诊断日志不记录请求的 Header 和 Body 信息。为实现记录,可通过配置 Trace 策略解决。例如,使用 `context.Request.Headers` 和 `context.Request.Body` 获取相关信息,并以 JSON 或字符串格式保存。示例代码展示了如何将 Headers 转换为 JSON 或逗号分隔字符串形式记录。相关参考资料包括 Set Body Policy 和 Trace Policy 官方文档,帮助进一步了解与扩展功能。
252 36
|
9月前
|
存储 数据可视化 开发工具
【Application Insights】Application Insights存储的Function App的日志存在"Operation Link" 为空的情况
在将 Azure Functions 升级到 .NET 8 和 Isolated Worker 模式后,Application Insights 的请求日志中 `operation_Link` 字段为空,导致分布式追踪无法正常关联。解决方法包括:确保引用正确的 SDK 包(如 `Microsoft.Azure.Functions.Worker.ApplicationInsights`),正确配置 Application Insights 服务,移除默认日志过滤规则,并使用最新依赖包以支持分布式追踪。通过这些步骤,可恢复端到端事务视图的可视化效果。
200 10
|
9月前
|
安全 Linux 开发工具
【Azure Function】分享把Function App从.NET 6.0升级到.NET 8.0 Isolated的步骤
本文介绍了将Azure Function App从.NET 6.0升级到.NET 8.0 Isolated的步骤。.NET 6.0作为长期支持版本,生命周期至2024年11月结束。为确保持续支持,建议升级至更新版本。升级步骤包括安装.NET 8 SDK、更新Azure Functions Core Tools、修改项目文件目标框架为net8.0、更新兼容的NuGet包、本地测试以及重新发布到Azure。更多详细信息可参考官方文档。
401 9
|
10月前
|
存储 Windows
【Azure Cloud Service】微软云服务上的日志收集方法
本文介绍了在使用微软云服务(Cloud Service Extended Support)时,如何收集日志以分析未记录在应用日志中的服务异常。由于云服务基于传统虚拟机模式,需通过远程桌面登录实例,查看IIS、Windows Event及云服务组件日志(如WindowsAzureGuestAgent)。此外,可使用CollectGuestLogs.exe工具打包日志,或通过“File Server Resource Manager”检查日志存储配额是否不足。附参考文档链接供深入学习。
333 29