Google Cloud功能的console.log信息显示在哪里

马克·彼得森

运行Google Cloud功能时如何查看console.log?有云控制台吗?

exports.helloWorld = function helloWorld(req, res) {
  // Example input: {"message": "Hello!"}
  if (req.body.message === undefined) {
    // This is an error case, as "message" is required.
    res.status(400).send('No message defined!');
  } else {
    // Everything is okay.
    console.log(req.body.message);
    res.status(200).send('Success: ' + req.body.message);
  }
};
Tuxdude

查看日志

您可以使用以下任一方式查看云功能日志:

// By default, the client will authenticate using the service account file
// specified by the GOOGLE_APPLICATION_CREDENTIALS environment variable and use
// the project specified by the GCLOUD_PROJECT environment variable. See
// https://googlecloudplatform.github.io/gcloud-node/#/docs/google-cloud/latest/guides/authentication
const Logging = require('@google-cloud/logging');

function getLogEntries () {
  // Instantiates a client
  const logging = Logging();

  const options = {
    pageSize: 10,
    filter: 'resource.type="cloud_function"'
  };

  // Retrieve the latest Cloud Function log entries
  // See https://googlecloudplatform.github.io/gcloud-node/#/docs/logging
  return logging.getEntries(options)
    .then(([entries]) => {
      console.log('Entries:');
      entries.forEach((entry) => console.log(entry));
      return entries;
    });
}

要使用gcloud工具查看日志,请使用logs read命令:

gcloud functions logs read

要查看特定功能的日志,请提供功能名称作为参数:

gcloud functions logs read <FUNCTION_NAME>

您甚至可以查看特定执行的日志:

gcloud functions logs read <FUNCTION_NAME> --execution-id EXECUTION_ID

有关日志查看选项的完整范围,请查看有关日志读取的帮助:

gcloud functions logs read -h

写日志

您可以使用console.log()console.error()

  • console.log()命令具有INFO日志级别。
  • console.error()命令具有ERROR日志级别。
  • 内部系统消息具有DEBUG日志级别。

有关查看云功能日志的更多信息,请参见此处

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

在 Google Actions 上使用 console.log() 时存储在哪里?

在哪里启动 Google Cloud SQL 代理?

忽略Google Cloud Console测试中完成功能的异常

在哪里保存 Google Cloud Platform 服务帐户凭据

Google Cloud Functions API在哪里存储和检索数据?

我的Google Cloud Storage存储桶中的文件在哪里?

在哪里可以找到旧版 google-cloud-python 的文档?

Google Cloud ML控制台用户界面在哪里?

在哪里可以在 Google Cloud Platform 上运行连续作业?

在哪里可以找到Google Cloud Compute Cost Breakdown?

Firebase云功能退出并显示代码16,什么是错误代码16,在哪里可以找到更多信息?

在功能组件中,应将console.log放置在哪里以测试该组件是否重新投放?

如何在Google Cloud Console中设置云功能的日志文件?

永远将console.log输出存储在哪里?

未显示Google地方信息自动填充功能

xenial 16.04中/ var / log / dmesg的功能在哪里?

从Google Build部署Google Cloud功能

Google Developers Console项目中的发件人ID在哪里?

功能-显示与执行console.log

Rails功能规格:调用了外部Google字体API,但我不知道在哪里

在 Google 标签管理器中启用展示广告功能的选项在哪里

在哪里可以找到官方 Google Cloud Python 库的旧版本文档?

在哪里可以找到Google Cloud Functions中活动并发调用的数量

GO在哪里寻找google-cloud-sdk?GOPATH应该是什么?

Google Cloud Storage go客户端中的重试逻辑在哪里?

Google Cloud Logging包含/排除过滤器的文档在哪里?

如何检查Google Cloud上永久磁盘的剩余容量?在哪里可以找到实例中的代码?

在登录到Google Cloud Compute实例后进行安装时,数据存储在哪里?

Google Marker集群在哪里?