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

本文涉及的产品
日志服务 SLS,月写入数据量 50GB 1个月
简介: 【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

 

相关实践学习
日志服务之使用Nginx模式采集日志
本文介绍如何通过日志服务控制台创建Nginx模式的Logtail配置快速采集Nginx日志并进行多维度分析。
相关文章
|
2月前
|
Linux Python
【Azure Function】Python Function部署到Azure后报错No module named '_cffi_backend'
ERROR: Error: No module named '_cffi_backend', Cannot find module. Please check the requirements.txt file for the missing module.
|
3月前
【Azure Policy】分享Policy实现对Azure Activity Log导出到Log A workspace中
在Policy Rule部分中,选择资源的类型为 "Microsoft.Resources/subscriptions", 效果使用 DeployIfNotExists (如果不存在,则通过修复任务进行修正。 在 existenceCondition 条件中,如果当前订阅已经启用了 diagnostic setting并且输出日志到同一个Log A workspace,表示满足Policy要求,不需要进行修正。 在 deployment 中,使用了 ARM 模板, 为订阅添加Diagnostic Setting并且所有的日志Category均启用。
|
4月前
【Azure Function】Azure Function中的Timer Trigger无法自动触发问题
【Azure Function】Azure Function中的Timer Trigger无法自动触发问题
|
4月前
【Azure Function & Application Insights】在Azure Function的日志中,发现DrainMode mode enabled Traces。它是什么意思呢?
【Azure Function & Application Insights】在Azure Function的日志中,发现DrainMode mode enabled Traces。它是什么意思呢?
|
4月前
|
缓存
【Azure Function】Function App代码中使用Managed Identity认证获取Blob数据时遇见400报错
【Azure Function】Function App代码中使用Managed Identity认证获取Blob数据时遇见400报错
【Azure Function】Function App代码中使用Managed Identity认证获取Blob数据时遇见400报错
|
4月前
|
Python
【Azure Function】发布 Python Function 到 Azure 成功,但是无法显示Function列表
【Azure Function】发布 Python Function 到 Azure 成功,但是无法显示Function列表
|
4月前
|
存储 大数据 索引
【Azure Contianer Apps】在云上使用容器应用时收集日志遇见延迟问题
【Azure Contianer Apps】在云上使用容器应用时收集日志遇见延迟问题
|
4月前
|
C#
【Azure Function】Function App启动时出现 Failed to open local port 4001 错误,这是什么情况呢?
【Azure Function】Function App启动时出现 Failed to open local port 4001 错误,这是什么情况呢?
|
4月前
|
C# C++
【Azure Function】在VS Code中创建Function项目遇见 No .NET worker runtimes found
【Azure Function】在VS Code中创建Function项目遇见 No .NET worker runtimes found
|
4月前
【Azure Function & Application Insights】调用Function上传和下载文件,有时候遇见大于1MB的文件的日志没有记录在Application Insights中
【Azure Function & Application Insights】调用Function上传和下载文件,有时候遇见大于1MB的文件的日志没有记录在Application Insights中

热门文章

最新文章