## Enable Cloud Logging

Fleet Engine should automatically have logging enabled.

1. Open the [Logs Explorer](https://cloud.google.com/logging/docs/view/logs-explorer-interface).
2. Enter the following query:

       resource.type:"fleetengine.googleapis.com"

If the results for the query list logs, then logging is enabled.

If you don't see any logs listed in the results for this query,
Cloud Logging may not be enabled for your project. To enable
Cloud Logging, contact [Google Maps Platform Support](https://console.cloud.google.com/google/maps-apis/support).

## Enable restricted use logs

In accordance with the [Mobility Service Specific Terms](https://developers.google.com/maps/documentation/transportation-logistics-terms/mobility/service-terms), some
of the log data that Fleet Engine generates may only be retained for 30 days.
Fleet Engine labels those logs as `TOS_RESTRICTED` and sorts them into a
restricted-retention log bucket, which you must create as shown below.

All other log data is assigned to the default bucket where it can be retained
longer, as defined in the [Mobility Service Specific Terms](https://developers.google.com/maps/documentation/transportation-logistics-terms/mobility/service-terms).
See [Logs Storage](https://developers.google.com/maps/documentation/mobility/operations/cloud-logging/console.cloud.google.come/logs/storage) in the Google Cloud
Console about customizing your log buckets and their retention periods.

For analysis, you can join the data from restricted and default logs for a
complete set of log data.

Do the following to enable restricted use logs:

1. Create a sink and bucket for restricted-use logs, and filter logs into their
   appropriate buckets.

2. Contact support to enable restricted-use logs.

For details, see the following sections.

### Create a sink and bucket for restricted logs in your project

1. In the [Logs Explorer](https://cloud.google.com/logging/docs/view/logs-explorer-interface), in the left-hand
   navigation, open the **Log Router** page.

2. Modify the _Default logging bucket to exclude restricted-use logs.

   1. Under **Log Router Sinks**, select the _Default logging bucket.
   2. Choose **Edit sink** from the **Actions** menu.
   3. Go to the **Choose logs to filter out of sink** section and click the **Add Exclusion** button.
   4. Set the **Exclusion filter name** to *ExcludeRestrictedLogs*.
   5. In the **Build and exclusion filter** box, paste this filter: `labels.restriction="TOS_RESTRICTED"`
   6. Click **Update sink**.
3. Create a restricted logging bucket to store the restricted-use logs. You do
   this by creating a sink and bucket for all logs, and then excluding the
   non-restricted logs.

   1. On the [Log Router page](https://console.cloud.google.com/logs/router), towards the top, select **Create sink**.
   2. Fill in the **Sink details** :
      1. Name: *RestrictedLogs*
      2. Description: *Routes Fleet Engine restricted-use logs.*
   3. Click **Next**.
   4. Fill in the **Sink destination** :
      1. Select Sink service: Logging bucket
      2. Select log bucket: Select **Create new log bucket**.
      3. In the **Bucket details** dialog, fill in:
         1. Name: *Restricted*
         2. Description: *Contains Fleet Engine restricted-use logs.*
      4. Leave the rest as is and click **Next**.
      5. Set the **Retention period** to 30 days. (The retention period must not exceed 30 days.)
      6. Click **Create bucket**.
   5. Back in the sink creation dialog, leave the **Logs to include in sink** section empty.
   6. In the **Logs to filter out of sink** section, click **Add Exclusion** and fill in:
      1. Exclusion filter name: *ExcludeNonRestrictedLogs*
      2. Exclusion filter: `NOT (resource.type =
         "fleetengine.googleapis.com/Fleet" OR resource.type =
         "fleetengine.googleapis.com/DeliveryFleet") NOT (labels.restriction
         = "TOS_RESTRICTED")`
   7. Click **Create sink.**

### Contact support to enable restricted-use logs

1. Go to [Google Maps Platform Support](https://console.cloud.google.com/google/maps-apis/support)
2. Click **Create Case** to start a new support request.
3. Provide the following information:

   - Project ID(s) to enable.
   - Email address of the person requesting the change. This person should have edit access to the Google Cloud Projects you are listing.
4. Agree to the following by writing **Yes** : *By enabling restricted-use
   Google Maps Content in Cloud Logging, you agree to adhere to the
   [Google Maps Platform terms](https://cloud.google.com/maps-platform/terms/) and [Mobility service specific
   terms](https://developers.google.com/maps/documentation/transportation-logistics-terms/mobility/service-terms), including caching and permitted use requirements as they relate
   to Google Maps Content.*

Once the support team handles your request, you will receive a confirmation that
logging has been enabled for your project.

> [!NOTE]
> **Note:** Fleet Engine logs may contain sensitive vehicle and trip information. You can restrict and audit access to these logs with Google Cloud [Identity and Access Management for Cloud Logging](https://cloud.google.com/logging/docs/access-control).

## What's next

Learn how to [Work with logs in Logs Explorer](https://developers.google.com/maps/documentation/mobility/operations/cloud-logging/work-with-logs.md.txt).