我正在使用用nodejs编写的azure函数。
我有这个 azure 的功能
module.exports = async function (context, req) {
const title = req.body.title;
console.log('title', title);
if (title) {
req.body.completed = false;
context.bindings.outputDocument = req.body;
context.res = {
body: { success: true, message: `Todo added successfully` }
};
} else {
context.res = {
status: 400,
body: { success: false, message: `Please add title field` }
};
}
};
和绑定(bind)
{
"bindings": [
{
"authLevel": "anonymous",
"type": "httpTrigger",
"direction": "in",
"name": "req",
"methods": [
"post"
]
},
{
"type": "http",
"direction": "out",
"name": "res"
},
{
"type": "cosmosDB",
"name": "outputDocument",
"databaseName": "xxx",
"collectionName": "items",
"createIfNotExists": false,
"connectionStringSetting": "xxx",
"partitionKey": "/all",
"direction": "out"
}
],
"disabled": false
}
当我运行时本地
func host start
我没有看到我的控制台日志语句。
如何在本地主机上查看?
部署后我需要在我的 Azure 门户中查看日志。
我尝试进入函数应用程序 - 打开我的函数,然后出现 azure 函数,但我看不到任何日志...
最佳答案
How can i see on localhost ?
And where i need to go in my azure portal to see the logs there after deployment.
I tried to go in Function App - open my function and there the azure function but i can't see any logs there...
当然,您可以获取本地的日志文件。我假设你是基于Windows的,那么只需编辑host.json,如下所示:
{
"version": "2.0",
"logging": {
"fileLoggingMode": "always",
"applicationInsights": {
"samplingSettings": {
"isEnabled": true,
"excludedTypes": "Request"
}
}
},
"extensionBundle": {
"id": "Microsoft.Azure.Functions.ExtensionBundle",
"version": "[1.*, 2.0.0)"
}
}
然后转到
C:\Users\yourusernameonlocal\AppData\Local\Temp\LogFiles\Application\Functions\Function\yourfunctionname
之后您将看到日志文件。:)
关于node.js - 我在哪里可以看到本地主机上的控制台日志以及该功能何时部署?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65990963/