[[["容易理解","easyToUnderstand","thumb-up"],["確實解決了我的問題","solvedMyProblem","thumb-up"],["其他","otherUp","thumb-up"]],[["難以理解","hardToUnderstand","thumb-down"],["資訊或程式碼範例有誤","incorrectInformationOrSampleCode","thumb-down"],["缺少我需要的資訊/範例","missingTheInformationSamplesINeed","thumb-down"],["翻譯問題","translationIssue","thumb-down"],["其他","otherDown","thumb-down"]],["上次更新時間:2025-09-04 (世界標準時間)。"],[],[],null,["# Reporting Logs\n\nThis page describes how to use the Service Infrastructure to enable\n[managed services](/service-infrastructure/docs/glossary#managed) to send logs to both\n[service producer](/service-infrastructure/docs/glossary#producer) and\n[service consumer](/service-infrastructure/docs/glossary#consumer) projects.\n\nThe Service Control API accepts structured or unstructured log data,\nwhich it batches and forwards to [Cloud Logging](/logging).\nBoth you and users of your managed services can use\nGoogle Cloud console and Google API Console to view the log data, or use the\nCloud Logging API to access the data programmatically.\n\nWhereas Logging alone allows a managed service to generate logs\nfor use by you as the developer of the managed service, the\nService Control API also lets you generate logs that are intended for\nyour users. This makes it possible for your users to understand and diagnose\ntheir use of your managed service.\n\nConfiguring logs\n----------------\n\nBefore you send logs to the Service Control API, you need to specify\nthree different bits of information in your\n[service configuration](/service-infrastructure/docs/service-management/reference/rpc/google.api#google.api.Service):\n\n- **Log names**: You can have one or more distinct logs. Each log is identified\n by a unique name. Individual logs make it possible for you to isolate\n distinct types of data if it makes the data easier to visualize or use.\n\n- **Monitored resources** :\n A [monitored resource](/logging/docs/api/v2#monitored-resources)\n represents a cloud entity that produces some logging data.\n To define a monitored resource in the service configuration, see\n [monitored_resource.proto](https://github.com/googleapis/googleapis/blob/master/google/api/monitored_resource.proto)\n for the technical specification.\n We strongly recommend you to use the same monitored resource for both\n [monitoring](/service-infrastructure/docs/reporting-metrics) and logging.\n\n- **Log configuration** : Lets you specify the monitored resource associated\n with any log stream and the service producer or service consumer project where\n each log should be sent. To configure the log association, see\n [logging.proto](https://github.com/googleapis/googleapis/blob/master/google/api/logging.proto)\n for the technical specification.\n\nIn the following example of [service configuration](/service-infrastructure/docs/glossary#config),\nthe log `activity_log` is configured to be sent to the service consumer. \n\n # The definition of the monitored resource to be used.\n monitored_resources:\n - type: library.appspot.com/Branch\n description: A library branch\n display_name: Library Branch\n launch_stage: ALPHA\n labels:\n - key: resource_container\n description: The Google Cloud resource container (ie. project id) for\n the branch.\n - key: location\n description: The Google Cloud region the branch is located.\n - key: branch_id\n description: The ID of the branch.\n\n # The log name to be used.\n logs:\n - name: activity_log\n\n # The logging configuration.\n logging:\n consumer_destinations:\n - monitored_resource: library.appspot.com/Branch\n logs:\n - activity_log\n\nAfter you have authored such configuration, you will need to follow\n[Managing Service Configurations](/service-infrastructure/docs/manage-config)\nand\n[Managing Service Rollouts](/service-infrastructure/docs/rollout) to push\nthe service configuration to the Service Management API, which will configure\nthe monitored resource in [Cloud Logging](/logging).\n\nReporting logs\n--------------\n\nAfter the service configuration push finishes, you can call the\nService Control API to report log entries. The following example uses the\n`gcurl` command to demonstrate the call. To learn how to set this up, see\n[Getting Started with the Service Control API](/service-infrastructure/docs/service-control/getting-started). \n\n```\ngcurl -d \"{\n 'operations': [ {\n 'operationId': 'e8bf36ef-f9b5-4274-b4f9-079a3731e6e5',\n 'operationName': 'New book arrived',\n 'consumerId': 'projects/library-consumer',\n 'startTime': '`date +%FT%T%:z`',\n 'endTime': '`date +%FT%T%:z`',\n 'labels': {\n 'location': 'us-east1',\n 'branch_id': 'my-test-library-branch'\n },\n 'logEntries': [ {\n 'severity': 'INFO',\n 'textPayload': 'new book arrived',\n 'name': 'activity_log'\n } ]\n } ]\n}\" https://servicecontrol.googleapis.com/v1/services/endpointsapis.appspot.com:report\n```"]]