Reporting Logs

This page describes how to use Google Service Control to enable services to send logs to both service producers and service consumers.

Service Control accepts structured or unstructured log data, which it batches and forwards to Stackdriver Logging. Both service consumers and service producers can use Google Cloud Console and Google API Console to view the log data, or use the Stackdriver Logging API to access the data programmatically.

Whereas Stackdriver Logging alone allows a service to produce logs for the sake of the service's producer, Service Control also lets you produce logs that are intended for the service consumers. This makes it possible for service consumers to understand and diagnose their use of the service.

Configuring logs

Before you send logs to Service Control, 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. Stackdriver 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 destination (producer or consumer) 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 to Google Service Management, you can call the Service Control API to report log entries. The following example uses the gcurl command to demonstrate the call; see Getting Started for how to set this up.

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'
    } ]
  } ]