Reporting Logs

This page describes how to use the Service Infrastructure to enable managed services to send logs to both service producer and service consumer projects.

The Service Control API accepts structured or unstructured log data, which it batches and forwards to Stackdriver Logging. Both you and users of your managed services can use Google Cloud Platform Console and Google API Console to view the log data, or use the Stackdriver Logging API to access the data programmatically.

Whereas Logging alone allows a managed service to generate logs for use by you as the developer of the managed service, the Service Control API also lets you generate logs that are intended for your users. This makes it possible for your users to understand and diagnose their use of your managed service.

Configuring logs

Before you send logs to the Service Control API, you need to specify three different bits of information in your service configuration:

  • Log names: You can have one or more distinct logs. Each log is identified by a unique name. Individual logs make it possible for you to isolate distinct types of data if it makes the data easier to visualize or use.

  • Monitored resources: Monitored resource types control the shape of the data that is held within a given log. Logging provides a well-known set of monitored resource types that you can chose from.

  • Log configuration: Lets you specify the monitored resource associated with any log stream and the service producer or service consumer project where each log should be sent.

In the following example of service configuration state, the log activity_log is configured to be sent to the service consumer. See service.proto for details on service configuration.

# The monitored resource to be used.
- type: api
  - key:
  - key:
  - key:
  - key:
  - key:

# The log name to be used.
- name: activity_log

# The logging configuration.
  - monitored_resource: api
    - activity_log

Reporting logs

Once you have configured logs in the service configuration and pushed the configuration using the Service Management API, you can call the Service Control API to report log entries. The following example uses the gcurl command to demonstrate the call. To learn how to set this up, see Getting Started with the Service Control API.

gcurl -d "{
  'operations': [ {
    'operationId': 'e8bf36ef-f9b5-4274-b4f9-079a3731e6e5',
    'operationName': 'google.example.hello.v1.HelloService.GetHello',
    'consumerId': 'project:endpointsapis-consumer',
    'startTime': '`date +%FT%T%:z`',
    'endTime': '`date +%FT%T%:z`',
    'labels': {
      '': 'global',
      '': 'v1',
      '': 'google.example.hello.v1.HelloService.GetHello',
      '': 'proven-catcher-789',
      '': ''
    'logEntries': [ {
      'severity': 'INFO',
      'textPayload': 'new book arrived',
      'name': 'activity_log'
    } ]
  } ]
Kunde den här sidan hjälpa dig? Berätta:

Skicka feedback om ...

Service Infrastructure