Service Control API menerima data log terstruktur atau tidak terstruktur,
yang dikelompokkan dan diteruskan ke Cloud Logging.
Anda dan pengguna layanan terkelola dapat menggunakan konsolGoogle Cloud dan Konsol API Google untuk melihat data log, atau menggunakan Cloud Logging API untuk mengakses data secara terprogram.
Meskipun Logging saja memungkinkan layanan terkelola membuat log
untuk digunakan oleh Anda sebagai developer layanan terkelola, Service Control API juga memungkinkan Anda membuat log yang ditujukan untuk
pengguna Anda. Hal ini memungkinkan pengguna memahami dan mendiagnosis
penggunaan layanan terkelola Anda.
Mengonfigurasi log
Sebelum mengirim log ke Service Control API, Anda perlu menentukan
tiga bit informasi yang berbeda dalam
konfigurasi layanan:
Nama log: Anda dapat memiliki satu atau beberapa log yang berbeda. Setiap log diidentifikasi
dengan nama unik. Setiap log memungkinkan Anda mengisolasi
berbagai jenis data jika hal itu memudahkan visualisasi atau penggunaan data.
Resource yang dimonitor:
Resource yang dimonitor
mewakili entitas cloud yang menghasilkan beberapa data logging.
Untuk menentukan resource yang dipantau dalam konfigurasi layanan, lihat
monitored_resource.proto
untuk mengetahui spesifikasi teknisnya.
Sebaiknya gunakan resource yang dipantau yang sama untuk
pemantauan dan logging.
Konfigurasi log: Memungkinkan Anda menentukan resource yang dipantau yang terkait dengan streaming log dan project produsen layanan atau konsumen layanan tempat setiap log harus dikirim. Untuk mengonfigurasi pengaitan log, lihat
logging.proto
untuk mengetahui spesifikasi teknisnya.
Dalam contoh konfigurasi layanan berikut,
log activity_log dikonfigurasi untuk dikirim ke konsumen layanan.
Setelah push konfigurasi layanan selesai, Anda dapat memanggil
Service Control API untuk melaporkan entri log. Contoh berikut menggunakan
perintah gcurl untuk menunjukkan panggilan. Untuk mempelajari cara menyiapkannya, lihat
Mulai Menggunakan Service Control API.
[[["Mudah dipahami","easyToUnderstand","thumb-up"],["Memecahkan masalah saya","solvedMyProblem","thumb-up"],["Lainnya","otherUp","thumb-up"]],[["Sulit dipahami","hardToUnderstand","thumb-down"],["Informasi atau kode contoh salah","incorrectInformationOrSampleCode","thumb-down"],["Informasi/contoh yang saya butuhkan tidak ada","missingTheInformationSamplesINeed","thumb-down"],["Masalah terjemahan","translationIssue","thumb-down"],["Lainnya","otherDown","thumb-down"]],["Terakhir diperbarui pada 2025-09-04 UTC."],[],[],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```"]]