Using Console
Using CLI
gcloud init
gcloud services enable compute.googleapis.com
gcloud logging sinks create [SINK_NAME] storage.googleapis.com/[BUCKET_NAME] --log-filter='resource.type="http_load_balancer" AND resource.labels.forwarding_rule_name="[FORWARDING_RULE_NAME]"'
Replace [SINK_NAME]
with a name for your logging sink, [BUCKET_NAME]
with the name of the GCP storage bucket where you want to store the logs, and [FORWARDING_RULE_NAME]
with the name of the forwarding rule associated with the regional backend service.
logging.logWriter
IAM role to the Cloud Logging service account using the command:
gcloud projects add-iam-policy-binding [PROJECT_ID] --member='serviceAccount:[SINK_NAME]@[PROJECT_ID].iam.gserviceaccount.com' --role='roles/logging.logWriter'
Replace [PROJECT_ID]
with your GCP project ID and [SINK_NAME]
with the name of your logging sink.
gcloud compute backend-services update [BACKEND_SERVICE_NAME] --enable-cdn-logging --cdn-logging-sink=[SINK_NAME]
Replace [BACKEND_SERVICE_NAME]
with the name of the regional backend service and [SINK_NAME]
with the name of the logging sink created in step 3.
Using Python
<path_to_service_account_file>
, <your_project_id>
, and <backend_service_name>
with the appropriate values.