如何从Azure Functions JavaScript函数中获取更详细的错误消息?

时间:2018-04-19 18:23:33

标签: javascript node.js azure-functions diagnostics serverless

我在运行时的v2上的Azure Functions上运行Node.js函数,并且经常运行该函数最终会出错。但调试错误确实很困难,因为大部分时间我得到的东西都是这样的:

2018-04-19T18:08:51  Welcome, you are now connected to log-streaming service.
2018-04-19T18:09:37.473 [Information] Executing 'Functions.GetAnswer' (Reason='This function was programmatically called via the host APIs.', Id=82d8e1df-7bb8-4f08-80c9-1d27d68959e2)
2018-04-19T18:09:37.788 [Error] System.Private.CoreLib: Exception while executing function: Functions.GetAnswer. System.Private.CoreLib: One or more errors occurred. (Worker process with pid 4736 exited with code 1) (Worker process with pid 5328 exited with code 1) (Worker process with pid 5428 exited with code 1). Worker process with pid 4736 exited with code 1.
2018-04-19T18:09:37.937 [Error] Executed 'Functions.GetAnswer' (Failed, Id=82d8e1df-7bb8-4f08-80c9-1d27d68959e2)

使用App Insights时,我不会获得更多信息:

Exception while executing function:
Functions.GetAnswer One or more errors occurred.
(Worker process with pid 4736 exited with code 1)
(Worker process with pid 5328 exited with code 1)
(Worker process with pid 5428 exited with code 1)
Worker process with pid 4736 exited with code 1
Worker process with pid 5328 exited with code 1
Worker process with pid 5428 exited with code 1

有没有办法获得一条错误消息,可以显示更多有关正在发生的事情?甚至可能是Node.js错误?

1 个答案:

答案 0 :(得分:2)

您可以尝试将verbose中的所有日志记录级别设置为host.json

{
    "tracing": {
        "consoleLevel": "verbose"
    },
    "logger": {
        "categoryFilter": {
            "defaultLevel": "verbose",
            "categoryLevels": {
                "Host.Results": "verbose",
                "Function": "verbose",
                "Host.Aggregator": "verbose"
            }
        }
    }
}

然后检查它是否为您提供了更多信息,但是这个特定错误与Azure Functions运行时的内部部分有关,如果您没有提供函数代码,则很难调查。