降低日志记录费用
使用集合让一切井井有条
根据您的偏好保存内容并对其进行分类。
启用日志记录功能后,您需要负责设置日志的路由、存储和保留方式。如果您超出免费使用和保留限额,可能需要为日志注入和保留支付额外的 Google Cloud 费用。请参阅 Google Cloud Observability 价格。
不过,您可以使用以下部分中介绍的任何方法来控制日志记录费用。
减少日志记录用量
您可以通过排除某些日志条目来限制提取的日志数据量。如需了解详情,请参阅排除日志。
以下示例演示了常见的 Fleet Engine 场景,以及如何过滤掉特定日志消息以降低费用。
按方法过滤
您可以过滤掉只读方法,因为这些方法通常不需要用于数据分析或问题排查。
以下命令会更新 _Default
日志记录存储分区,以排除 GetVehicle
日志。
gcloud logging sinks update _Default \
--add-exclusion=name=ExcludeFleetengineGetVehicle,\
filter='jsonPayload.@type:"type.googleapis.com/maps.fleetengine.v1.GetVehicleLog"'
以下命令会更新 _Default
日志记录存储分区,以排除 GetTrip
日志。
gcloud logging sinks update _Default \
--add-exclusion=name=ExcludeFleetengineGetTrip,filter=\
'jsonPayload.@type:"type.googleapis.com/maps.fleetengine.v1.GetTripLog"'
创建调试属性
您可以通过设置 debug
属性,将日志减少到仅包含特定车辆的日志。
现在,任何不具有 debug
属性的车辆都将被排除。
以下命令会更新 _Default
日志记录存储分区,以从 UpdateVehicle
日志中排除没有 debug
属性的车辆。
gcloud logging sinks update _Default \
--add-exclusion=name=ExcludeFleetengineNonDebug,\
filter='resource.type="fleetengine.googleapis.com/Fleet"
log_name:"logs/fleetengine.googleapis.com%2Fupdate_vehicle"
jsonPayload.@type="type.googleapis.com/maps.fleetengine.v1.UpdateVehicleLog"
NOT jsonPayload.response.attributes.key="debug"'
过滤了空受限使用日志
启用后,受限使用日志会为每个常规日志创建子日志,即使相应操作未填充受限字段也是如此。过滤掉这些空的受限日志可以降低费用。
以下命令会更新 RestrictedLogs
日志记录存储分区,以排除空的受限 UpdateVehicle
日志。
gcloud logging sinks update RestrictedLogs \
--add-exclusion=name=ExcludeFleetengineEmptyRestrictedVehicleLogs,\
filter='resource.type="fleetengine.googleapis.com/Fleet"
log_name:"logs/fleetengine.googleapis.com%2Fupdate_vehicle_restricted"
NOT jsonPayload.request.vehicle.currentRouteSegment:*
NOT jsonPayload.response.currentRouteSegment:*
NOT jsonPayload.response.waypoints:*'
导出或路由日志
您可以将日志路由到其他 Google Cloud 或外部目的地,以避免产生默认的提取和存储费用。请务必按照下一部分中的说明关闭日志提取功能,以免产生提取费用。
请参阅 Cloud Logging 导出和导出日志。
关闭日志提取
如果您不打算使用 Fleet Engine 日志,则可以关闭提取功能,以免产生潜在的 Cloud Logging 费用。默认情况下,Fleet Engine 日志会路由到 _Default 日志存储分区。
以下命令会更新 _Default 日志记录存储分区,使其不接收 Fleet Engine 日志。
gcloud logging sinks update _Default \
--log-filter='NOT LOG_ID("cloudaudit.googleapis.com/activity")
AND NOT LOG_ID("externalaudit.googleapis.com/activity")
AND NOT LOG_ID("cloudaudit.googleapis.com/system_event")
AND NOT LOG_ID("externalaudit.googleapis.com/system_event")
AND NOT LOG_ID("cloudaudit.googleapis.com/access_transparency")
AND NOT LOG_ID("externalaudit.googleapis.com/access_transparency")
AND NOT resource.type:"fleetengine.googleapis.com"'
另请参阅根据预算管理 Cloud Logging 费用的四个步骤。
如未另行说明,那么本页面中的内容已根据知识共享署名 4.0 许可获得了许可,并且代码示例已根据 Apache 2.0 许可获得了许可。有关详情,请参阅 Google 开发者网站政策。Java 是 Oracle 和/或其关联公司的注册商标。
最后更新时间 (UTC):2025-09-10。
[[["易于理解","easyToUnderstand","thumb-up"],["解决了我的问题","solvedMyProblem","thumb-up"],["其他","otherUp","thumb-up"]],[["没有我需要的信息","missingTheInformationINeed","thumb-down"],["太复杂/步骤太多","tooComplicatedTooManySteps","thumb-down"],["内容需要更新","outOfDate","thumb-down"],["翻译问题","translationIssue","thumb-down"],["示例/代码问题","samplesCodeIssue","thumb-down"],["其他","otherDown","thumb-down"]],["最后更新时间 (UTC):2025-09-10。"],[[["\u003cp\u003eWhen logging is enabled, you are responsible for routing, storage, and retention, which might incur extra Google Cloud costs if usage and retention limits for no charge are exceeded.\u003c/p\u003e\n"],["\u003cp\u003eYou can reduce logging costs by limiting ingested data, excluding specific log entries, routing logs to other destinations, or turning off log ingestion entirely.\u003c/p\u003e\n"],["\u003cp\u003eIf you choose to route logs to external destinations, ensure to turn off log ingestion to avoid extra charges.\u003c/p\u003e\n"],["\u003cp\u003eTo completely avoid Fleet Engine logging charges when you don't intend to use the logs, turn off ingestion for the _Default log bucket.\u003c/p\u003e\n"]]],["After enabling logging, you can manage costs by controlling log ingestion and retention. To reduce costs, limit ingested data by excluding specific log entries, like `GetVehicle` logs, using commands such as `gcloud logging sinks update`. You can also route logs to other destinations, avoiding default storage costs, by using Cloud Logging Exports. To completely prevent charges, you can turn off log ingestion using the provided command to update the `_Default` logging bucket to ignore specified logs including `fleetengine.googleapis.com`.\n"],null,["After logging is enabled, you are responsible for setting up how you would like\nto route, store, and retain your logs. You may incur extra Google Cloud costs\nfor log ingestion and retention if you exceed the usage and retention limits for\nno charge. See [Google Cloud Observability pricing](https://cloud.google.com/stackdriver/pricing).\n\nHowever, you can control logging costs by using any of the following approaches\ndescribed in the following sections.\n\nReduce logging usage\n\nYou can limit the amount of log data that is ingested by excluding certain log\nentries. See [Excluding logs](https://cloud.google.com/logging/docs/exclusions) for more details.\n\nThe following examples demonstrate common Fleet Engine scenarios and how to\nfilter out specific log messages to reduce costs.\n\nFilter by method\n\nYou can filter out read-only methods since these are typically not need for data\nanalysis or troubleshooting.\n\nThe following command updates the `_Default` logging bucket to exclude\n`GetVehicle` logs. \n\n gcloud logging sinks update _Default \\\n --add-exclusion=name=ExcludeFleetengineGetVehicle,\\\n filter='jsonPayload.@type:\"type.googleapis.com/maps.fleetengine.v1.GetVehicleLog\"'\n\nThe following command updates the `_Default` logging bucket to exclude\n`GetTrip` logs. \n\n gcloud logging sinks update _Default \\\n --add-exclusion=name=ExcludeFleetengineGetTrip,filter=\\\n 'jsonPayload.@type:\"type.googleapis.com/maps.fleetengine.v1.GetTripLog\"'\n\nCreate a debug attribute\n\nYou can reduce logs to specific vehicles only by setting a `debug` [attribute](https://developers.google.com/maps/documentation/mobility/fleet-engine/essentials/vehicles/on-demand-vehicle-fields#vehicle_attributes_field).\nAny vehicle that does not have the `debug` attribute will now be excluded.\n\nThe following command updates the `_Default` logging bucket to exclude vehicles\nwithout the `debug` attribute from the `UpdateVehicle` logs. \n\n gcloud logging sinks update _Default \\\n --add-exclusion=name=ExcludeFleetengineNonDebug,\\\n filter='resource.type=\"fleetengine.googleapis.com/Fleet\"\n log_name:\"logs/fleetengine.googleapis.com%2Fupdate_vehicle\"\n jsonPayload.@type=\"type.googleapis.com/maps.fleetengine.v1.UpdateVehicleLog\"\n NOT jsonPayload.response.attributes.key=\"debug\"'\n\nFilter empty restricted use logs\n\nWhen enabled, restricted use logs create a child log for every regular log,\neven if the operation doesn't populate restricted fields. Filtering out these\nempty restricted logs can reduce costs.\n\nThe following command updates the `RestrictedLogs` logging bucket to exclude\nempty restricted `UpdateVehicle` logs. \n\n gcloud logging sinks update RestrictedLogs \\\n --add-exclusion=name=ExcludeFleetengineEmptyRestrictedVehicleLogs,\\\n filter='resource.type=\"fleetengine.googleapis.com/Fleet\"\n log_name:\"logs/fleetengine.googleapis.com%2Fupdate_vehicle_restricted\"\n NOT jsonPayload.request.vehicle.currentRouteSegment:*\n NOT jsonPayload.response.currentRouteSegment:*\n NOT jsonPayload.response.waypoints:*'\n\nExport or route logs\n\nYou can route logs to other Google Cloud or external destinations to avoid the\ndefault ingestion and storage costs. Make sure you turn off log ingestion, as\ndescribed in the next section, to avoid ingestion costs.\n\nSee [Cloud Logging Exports](https://cloud.google.com/logging/docs/overview#store) and [Exporting\nlogs](https://cloud.google.com/logging/docs/export/configure_export_v2).\n\nTurn off log ingestion\n\nIf you don't intend to use Fleet Engine logs, you can avoid potential Cloud\nLogging charges by turning off ingestion. By default, Fleet Engine logs are\nrouted to the _Default log bucket.\n\nThe following command updates the _Default logging bucket to not ingest Fleet\nEngine logs. \n\n gcloud logging sinks update _Default \\\n --log-filter='NOT LOG_ID(\"cloudaudit.googleapis.com/activity\")\n AND NOT LOG_ID(\"externalaudit.googleapis.com/activity\")\n AND NOT LOG_ID(\"cloudaudit.googleapis.com/system_event\")\n AND NOT LOG_ID(\"externalaudit.googleapis.com/system_event\")\n AND NOT LOG_ID(\"cloudaudit.googleapis.com/access_transparency\")\n AND NOT LOG_ID(\"externalaudit.googleapis.com/access_transparency\")\n AND NOT resource.type:\"fleetengine.googleapis.com\"'\n\nSee also [Four steps to managing your Cloud Logging costs on a\nbudget](https://cloud.google.com/blog/products/devops-sre/cloud-logging-cost-management-best-practices)."]]