node.js - 我在哪里可以看到本地主机上的控制台日志以及该功能何时部署?

标签 node.js azure azure-functions

我正在使用用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/

相关文章:

c# - 为什么使用 PrimarySearcher 比 FindByIdentity() 更快?

azure - Azure 中的端口 454 和 455 正在监听什么?安全扫描标记的警告

json - 在 Azure Function 中动态设置计划

azure - 从 Azure Function App 中删除多个函数

javascript - 是否正在复制文件

java - 如何发出 HTTPS GET 请求来与其他方竞争并尝试成为最快的?

Azure:如何计算存储事务

python - Azure Python 无服务器函数中的 strip 签名验证错误

javascript - 为什么在哈巴狗的简单渲染中显示 'Cannot Get/'?

sql - 使用nodejs SQL DB2插入海量数据