为 Google Chat 应用开启错误日志记录功能
使用集合让一切井井有条
根据您的偏好保存内容并对其进行分类。
本页介绍了如何开启 Chat 应用错误日志记录,以便您在测试 Chat 应用时,可以在 Google Cloud 日志浏览器中查询和查看错误日志。
前提条件
如需开启 Chat 应用错误日志记录功能,您需要:
- 拥有 Google Chat 访问权限的 Google Workspace 账号。
- 一个 Chat 应用。如需构建 Chat 应用,请按照此快速入门操作。
设置环境
在查询 Chat 应用错误日志之前,您必须在 Chat 应用的 Google Cloud 项目中启用 Cloud Logging API。
在 Google Cloud 控制台中,开启 Cloud Logging API。依次点击菜单
menu
> API 和服务
> 库。
> 搜索 Cloud Logging API
> 点击 Cloud Logging API
> 点击启用。
启用该 API
开启错误日志记录
启用错误日志记录功能,当 Chat 应用返回错误时,系统会将该错误记录到 Cloud Logging。由于 Cloud Logging 会产生费用,因此您可能需要在完成问题排查后关闭错误日志记录。
在 Google Cloud 控制台中,前往 Chat API 配置页面。依次点击菜单图标 menu > 更多产品
> Google Workspace
> 产品库
> Google Chat API
> 管理
> 配置。
前往 Chat API
在“功能”下,选择将错误记录到 Cloud Logging。
点击保存。
现在,每当 Chat 应用返回错误时,该错误都会记录到 Cloud Logging。
关闭错误日志记录
由于 Cloud Logging 会产生费用,您可能需要关闭错误日志记录功能。
在 Google Cloud 控制台中,前往 Chat API 配置页面。依次点击菜单图标 menu > 更多产品
> Google Workspace
> 产品库
> Google Chat API
> 管理
> 配置。
前往 Chat API
在“功能”下,取消选中将错误记录到 Cloud Logging。
点击保存。
现在,每当 Chat 应用返回错误时,该错误都不会记录到 Cloud Logging。您可以使用 Logs Explorer 继续查询过往的错误日志。
开启错误日志记录功能后,您就可以查询 Chat 应用的错误日志了。
如未另行说明,那么本页面中的内容已根据知识共享署名 4.0 许可获得了许可,并且代码示例已根据 Apache 2.0 许可获得了许可。有关详情,请参阅 Google 开发者网站政策。Java 是 Oracle 和/或其关联公司的注册商标。
最后更新时间 (UTC):2025-08-04。
[null,null,["最后更新时间 (UTC):2025-08-04。"],[[["\u003cp\u003eThis guide explains how to enable error logging for your Google Chat app, allowing you to view and analyze errors in Google Cloud Logs Explorer.\u003c/p\u003e\n"],["\u003cp\u003eTo enable error logging, you need a Google Workspace account, a Chat app, and the Cloud Logging API enabled in your Google Cloud project.\u003c/p\u003e\n"],["\u003cp\u003eWhen enabled, Chat app errors are logged to Cloud Logging, which may incur costs; you can disable logging after troubleshooting.\u003c/p\u003e\n"],["\u003cp\u003eYou can turn off error logging to avoid incurring costs from Cloud Logging, but you can still query past logs.\u003c/p\u003e\n"]]],["To enable Chat app error logging, first enable the Cloud Logging API in the Google Cloud console. Then, navigate to the Chat API configuration page and under Functionality, select \"Log errors to Cloud Logging,\" and save. Errors are now logged to Cloud Logging. To disable, deselect \"Log errors to Cloud Logging\" and save. Remember to disable it when troubleshooting is complete, as Cloud Logging incurs a cost. Error logs can be viewed in Google Cloud Logs Explorer.\n"],null,["This page describes how to turn on Chat app error logging, so that you can query and view error logs in [Google Cloud Logs Explorer](https://cloud.google.com/logging/docs/view/logs-viewer-interface) while testing your Chat app.\n\nPrerequisites\n\nTo turn on Chat app error logging, you need:\n\n- A Google Workspace account with access to Google Chat.\n- A Chat app. To build a Chat app, follow this [quickstart](/workspace/chat/quickstart/gcf-app).\n\nSet up the environment\n\nBefore querying Chat app error logs, you must enable the Cloud Logging API in the Chat app's Google Cloud project.\n\n1. In the Google Cloud console, turn on the Cloud Logging API. Click **Menu**\n menu\n \\\u003e **APIs \\& Services**\n \\\u003e **Library** .\n \\\u003e search for **Cloud Logging API**\n \\\u003e click **Cloud Logging API**\n \\\u003e **Enable**.\n\n [Enable the API](https://console.cloud.google.com/marketplace/product/google/logging.googleapis.com)\n\nTurn on error logging\n\nTurn on error logging and when a Chat app returns an error, it logs it to Cloud logging. Because Cloud Logging [incurs a cost](https://cloud.google.com/stackdriver/pricing), you might want to [turn off error logging](#turn-off-error-logging) after you finish troubleshooting.\n\n1. In the Google Cloud console, go to the Chat API **configuration** page. Click **Menu**\n menu\n \\\u003e **More products**\n \\\u003e **Google Workspace**\n \\\u003e **Product Library**\n \\\u003e **Google Chat API**\n \\\u003e **Manage**\n \\\u003e **Configuration**.\n\n [Go to Chat API](https://console.cloud.google.com/apis/api/chat.googleapis.com/hangouts-chat)\n2. Under Functionality, select **Log errors to Cloud Logging**.\n\n3. Click **Save**.\n\nNow, whenever the Chat app returns an error, the error gets logged to Cloud Logging.\n\nTurn off error logging\n\nBecause Cloud Logging [incurs a cost](https://cloud.google.com/stackdriver/pricing), you might want to turn off error logging.\n\n1. In the Google Cloud console, go to the Chat API **configuration** page. Click **Menu**\n menu\n \\\u003e **More products**\n \\\u003e **Google Workspace**\n \\\u003e **Product Library**\n \\\u003e **Google Chat API**\n \\\u003e **Manage**\n \\\u003e **Configuration**.\n\n [Go to Chat API](https://console.cloud.google.com/apis/api/chat.googleapis.com/hangouts-chat)\n2. Under Functionality, deselect **Log errors to Cloud Logging**.\n\n3. Click **Save**.\n\nNow, whenever the Chat app returns an error, the error doesn't get logged to Cloud Logging. You can continue to query past error logs using Logs Explorer.\n\nRelated topics\n\nAfter turning on error logging, you're ready to [query error logs](/workspace/chat/query-logs) for your Chat app."]]