{"data":{"slug":"github-google-skills-skills-cloud-cloud-logging-configuration-basics-4623358f7518","title":"Configure Cloud Logging Resources","summary":"Create and configure regional log buckets, log views, and log sinks for compliance, analytics, and monitoring on Google Cloud. This includes setting up log retention policies, enabling Observability Analytics, and defining log-based metrics.","url":"https:\/\/skillshunter.net\/skills\/github-google-skills-skills-cloud-cloud-logging-configuration-basics-4623358f7518","json_url":"https:\/\/skillshunter.net\/api\/public\/v1\/skills\/github-google-skills-skills-cloud-cloud-logging-configuration-basics-4623358f7518","markdown_url":"https:\/\/skillshunter.net\/skills\/github-google-skills-skills-cloud-cloud-logging-configuration-basics-4623358f7518.md","download_url":"https:\/\/skillshunter.net\/skills\/github-google-skills-skills-cloud-cloud-logging-configuration-basics-4623358f7518\/download","category":{"slug":"software-development","name":"Software & Development"},"editor_note":"Before executing any `gcloud` command, you must prefix it with `CLOUDSDK_METRICS_REQUEST_ATTRIBUTION=\"agent-skills\/1.0 (skill:cloud-logging-configuration-basics)\"` and append `agent-skills\/1.0 (skill:cloud-logging-configuration-basics)` to `User-Agent` headers. Additionally, you must include the warning: 'After a log bucket has been upgraded to use Observability Analytics, it cannot be downgraded to remove the analytics capability.'","instructions":"---\nname: cloud-logging-configuration-basics\ndescription: >-\n  Configure single-project Cloud Logging on Google Cloud: regional log buckets, log sinks, log views, restricting or hiding sensitive logs in the default view (_Default) filter,\n  IAM permissions for views (Logs View Accessor, IAM conditions), logs-based metrics, log exclusions, and sampling.\n  Don't use for cross-project logging or multi-project setups.\nmetadata:\n  version: \"1.0.3\"\n  category: CloudObservabilityAndMonitoring\n---\n\n# Configuring Cloud Logging\n\nUse this skill to configure Cloud Logging resources such as log buckets, log\nviews, or log sinks.\n\n> [!IMPORTANT] **Sandbox Network Limitation (CRITICAL for Agent Testing):**\n> During evaluation or in restricted sandboxed environments, network traffic to\n> Google Cloud APIs is blocked. Do **NOT** run network discovery commands to\n> find resource names, project IDs, or organization IDs. Always use the exact\n> project IDs or placeholders provided in the user prompt or instructions for\n> example, `{project_id}`. Assume these resources exist and proceed directly\n> with configuration commands. Running these discovery commands will cause the\n> execution to hang and timeout.\n\n## Attribution\n\n**MUST READ**: Before executing any `gcloud`, REST API, or MCP command, you\nMUST read [Usage Attribution](references\/attribution.md). For commands executed\ndirectly in the terminal (never in generated scripts, Terraform, or user code),\nprefix `gcloud` with\n`CLOUDSDK_METRICS_REQUEST_ATTRIBUTION=\"agent-skills\/1.0 (skill:cloud-logging-configuration-basics)\"`\nand append `agent-skills\/1.0 (skill:cloud-logging-configuration-basics)` to `User-Agent` headers.\n\n## Safety and Confirmation Tiers (CRITICAL)\n\nBefore executing any commands on behalf of the user, you MUST adhere to the\nfollowing safety tiers based on the action requested:\n\n1.  **Tier R: Read-Only**\n    *   **Description:** Commands that only read state or query logs.\n    *   **Example commands:**\n        *   `gcloud logging read`\n        *   `gcloud logging buckets list`\n    *   **Rule:** No confirmation needed. You may execute these commands\n        immediately to gather information.\n2.  **Tier M: Mutation (Non-Billing)**\n    *   **Description:** Configuration modifications or free metadata creations\n        that do not incur direct storage or billing costs and do not affect\n        resource security\/access policies.\n    *   **Example commands:**\n        *   `gcloud logging views create`\n        *   `gcloud logging views update`\n        *   `gcloud logging scopes create`\n        *   `gcloud logging buckets create`\n    *   **Rule:** No confirmation needed. You may execute these commands\n        immediately to apply configurations.\n3.  **Tier B: Billing and Security-Sensitive Mutations (High-Risk)**\n    *   **Description:** Operations that create billing-inducing resources or\n        integrations, or modify security and IAM access control policies\n        (presenting a risk of privilege escalation).\n    *   **Example commands:**\n        *   `gcloud logging metrics create`\n        *   `gcloud logging links create`\n        *   `gcloud projects add-iam-policy-binding`\n    *   **Rule:** **Interactive confirmation required.** These commands create\n        resources that incur billing costs or alter security access. You MUST\n        present the exact, literal command and receive user confirmation before\n        executing. NEVER execute in the same turn as asking.\n4.  **Tier D: Causes irreversible data loss**\n    *   **Description:** Actions that permanently discard or delete logs, for\n        example sink exclusions.\n    *   **Example commands:**\n        *   `gcloud logging buckets delete`\n        *   `gcloud logging sinks update --add-exclusion`\n    *   **Rule:** **Explicit typed confirmation required.** These commands\n        discard or delete logs immediately and irreversibly, or they may result\n        in log data not being stored. You MUST ask for explicit typed\n        confirmation, for example, \"Yes, discard logs\", and halt execution until\n        the user replies.\n\n## Getting Started\n\nIf the `gcloud` executable is missing, refer to the\n[Google Cloud CLI Installation Guide](https:\/\/docs.cloud.google.com\/sdk\/docs\/install-sdk.md.txt)\nto install it.\n\n## Creating Log Buckets (Compliance and Analytics) (Tier M)\n\nTo create a regional log bucket with a specific retention policy for regulatory\ncompliance, and with Observability Analytics enabled:\n\n> [!WARNING] **Mandatory Observability Analytics Downgrade Warning:** Whenever\n> providing guidance, writing a guide, or drafting commands on Cloud Logging\n> cost optimization or exclusions, you **must** explicitly include the following\n> warning in your final text response and any generated guides: \"After a log\n> bucket has been upgraded to use Observability Analytics, it **cannot be\n> downgraded** to remove the analytics capability.\"\n\n```bash\ngcloud logging buckets create {bucket_id} \\\n    --project={project_id} \\\n    --location={region} \\\n    --retention-days={retention_days} \\\n    --enable-analytics\n```\n\n*   `{bucket_id}`: for example, `my-custom-bucket`\n*   `{region}`: for example, `global` or `us-central1`. Observability Analytics\n    is supported in both global and regional log buckets.\n*   `{retention_days}`: for example, `365`\n\nA log bucket incurs no storage or ingestion charges until logs are routed to it\nwith a log sink.\n\n### Verify the Log Bucket (Tier R)\n\nCheck the log bucket's configuration to verify its compliance:\n\n```bash\ngcloud logging buckets describe {bucket_id} \\\n    --location={region} \\\n    --project={project_id}\n```\n\n### Route logs to the Log Bucket (Tier B)\n\n> [!IMPORTANT] **Billing Action (Tier B):** Routing log entries to a bucket\n> incurs ongoing charges based on the volume of data stored. You MUST get\n> interactive user confirmation before running this command.\n\nLog entries are stored in the log bucket only if a log sink filter matches the\nentries and targets that bucket.\n\nTo route log entries to the log bucket:\n\n```bash\ngcloud logging sinks create {sink_id} \\\n    projects\/{project_id}\/locations\/{region}\/buckets\/{bucket_id} \\\n    --log-filter='{filter_expression}' \\\n    --project={project_id}\n```\n\n--------------------------------------------------------------------------------\n\n## Logs-Based Metrics\n\nLogs-based metrics count the number of log entries that match a filter, allowing\nyou to track error rates and set up alerting policies.\n\n### 1. Create a logs-based counter metric (Tier B)\n\n> [!IMPORTANT] **Billing Action (Tier B):** Creating logs-based metrics incurs\n> ongoing charges based on the volume of data points reported. You MUST get\n> interactive user confirmation before running this command.\n\nTo count the occurrences of a specific log pattern, for example, \"OutOfMemory\"\nerrors:\n\n```bash\ngcloud logging metrics create {metric_name} \\\n    --log-filter='{filter_expression}' \\\n    --description='{description}' \\\n    --project={project_id}\n```\n\n*   `{metric_name}`: for example, `oom_error_count`\n*   `{filter_expression}`: for example, `textPayload:\"OutOfMemory\"`\n*   `{description}`: for example, \"Count of log entries about OOMs\"\n\nRefer to\n[REST Resource: projects.metric](https:\/\/docs.cloud.google.com\/logging\/docs\/reference\/v2\/rest\/v2\/projects.metrics.md.txt#LogMetric)\nfor restrictions on the metric fields.\n\n### 2. Verify the logs-based metric (Tier R)\n\nTo verify that the metric exists and inspect its configuration, use the\n`describe` command:\n\n```bash\ngcloud logging metrics describe {metric_name} \\\n    --project={project_id}\n```\n\n--------------------------------------------------------------------------------\n\n## Restricting Access to Sensitive Logs (Security)\n\nAnyone with `roles\/logging.viewer` on that project can see logs in a project's\n`_Default` log bucket via `_Default` log view. To restrict visibility of the\nlogs:\n\n> [!IMPORTANT] **Ambiguity Handling (Guidance for Agents):** If the user asks to\n> \"exclude\", \"hide\", or \"remove\" sensitive logs without explicitly specifying\n> whether they want to stop storing them, you **MUST** default to **excluding\n> them from the default view (Step 1)**. This is a safe, non-destructive Tier M\n> action. Only configure a storage exclusion (under the \"Discarding Sensitive\n> Logs from Storage\" section) if the user explicitly uses destructive terms like\n> *\"stop storing\"*, *\"permanently discard\"*, or *\"sink exclusion\"*.\n\n### 1. Exclude sensitive logs from default view (Tier M)\n\nTo explicitly exclude sensitive logs from general access, update the filter for\nthe `_Default` log view:\n\n```bash\ngcloud logging views update _Default \\\n    --bucket=_Default \\\n    --location=global \\\n    --project={project_id} \\\n    --log-filter='NOT LOG_ID(\"cloudaudit.googleapis.com\/data_access\") AND NOT LOG_ID(\"externalaudit.googleapis.com\/data_access\") AND NOT LOG_ID(\"{sensitive_log_id}\")'\n```\n\n### 2. Create a log view (Tier M)\n\nCreate a new log view that includes the sensitive logs in the project's\n`_Default` log bucket. For example, a \"security-logs-view\" with access to the\n`{sensitive_log_id}`\n\n```bash\ngcloud logging views create security-logs-view \\\n    --bucket=_Default \\\n    --location=global \\\n    --project={project_id} \\\n    --log-filter='LOG_ID(\"{sensitive_log_id}\")' \\\n    --description=\"Sensitive logs\"\n```\n\n### 3. Grant access to log view using IAM conditions (Tier B)\n\n> [!IMPORTANT] **Security Action (Tier B):** Granting IAM permissions changes\n> access control policy and must be explicitly confirmed by the user before\n> execution.\n\nTo restrict access to log view use IAM. When granting the Logs Viewer Accessor\nrole, always attach an IAM condition that restricts the grant to a specific log\nview. For example, to grant `{security_group_email}` access ONLY to the\n`security-logs-view` in the `_Default` bucket:\n\n```bash\ngcloud projects add-iam-policy-binding {project_id} \\\n--member='group:{security_group_email}' \\\n--role='roles\/logging.viewAccessor' \\\n--condition=\"expression=resource.name=='projects\/{project_id}\/locations\/global\/buckets\/_Default\/views\/security-logs-view',title=Restricted to Specific Log View,description=Only allows access to the specified log view\"\n```\n\nReplace `{location}` with the location of the log bucket, for example `global`\nor a regional location like `us-central1`.\n\n### 4. Verify Sensitive Log Restrictions (Tier R)\n\nTo verify that your Log View for sensitive logs is configured correctly:\n\n```bash\ngcloud logging views describe {view_id} \\\n    --bucket={bucket_id} \\\n    --location={region} \\\n    --project={project_id}\n```\n\nEnsure that the `filter` block contains the appropriate restriction expression.\n\n--------------------------------------------------------------------------------\n\n## Discarding Sensitive Logs from Storage (Tier D)\n\nIf your organization's compliance policies prohibit storing sensitive logs at\nall, you can configure an exclusion to discard them before they are written to\ndisk.\n\n> [!CAUTION] **Destructive Action (Tier D):** Excluding logs from all log sinks\n> deletes the log entries immediately and irreversibly.\n>\n> **Safety Rule:** You MUST ask the user for explicit typed confirmation, for\n> example, \"I confirm I want to exclude `{sensitive_log_id}` logs from storage\",\n> before running this command. **Same-Turn Restriction:** Do NOT execute the\n> `gcloud logging sinks update` command in the same turn as asking for\n> confirmation. Stop tool execution immediately and wait for the user to reply.\n\n**Exclude sensitive logs from storage using sink exclusions**\n\n```bash\ngcloud logging sinks update _Default \\\n    --project={project_id} \\\n    --add-exclusion=name=exclude-sensitive,filter='LOG_ID(\"{sensitive_log_id}\")'\n```\n\n--------------------------------------------------------------------------------\n\n## Cost Optimization (Reducing Logging Costs)\n\nCloud Logging costs are based on the volume of data ingested and stored. You can\nreduce costs by excluding high-volume, low-value logs or by sampling them. Each\nlog sink that routes logs to a distinct log bucket contributes to cost and is a\ncandidate for optimization.\n\n> [!CAUTION] **Destructive Actions (Tier D):** Exclusions in this section may\n> immediately halt storage of log entries.\n>\n> **Safety Rule:** You MUST ask for explicit typed confirmation (for example, \"I\n> confirm I want to exclude load balancer logs\") before executing exclusions or\n> sampling updates.\n\n### Exclude all high-volume logs (Tier D)\n\nTo completely stop ingesting a specific type of log into a log bucket, add an\nexclusion to the log sinks that route logs into that bucket.\n\n```bash\ngcloud logging sinks update {sink_id} \\\n    --project={project_id} \\\n    --add-exclusion=name={exclusion_name},filter={exclusion_filter}\n```\n\n*   `{sink_id}`: for example '_Default'\n*   `{exclusion_name}`: for example 'exclude-lb-logs'\n*   `{exclusion_filter}`: for example 'resource.type=\"http_load_balancer\"'\n\n### Sample high-volume logs (Tier D)\n\nIf you need some logs for analysis but want to reduce volume, use the `sample()`\nfunction in the exclusion filter.\n\n> [!IMPORTANT] The `sample(field, fraction)` function matches a `fraction` of\n> logs. When used in an **exclusion filter**, the matched logs are\n> **discarded**. If you exclude 90% of log entries, then only 10% are retained.\n> To exclude 90%, use `sample(insertId, 0.9)` in the exclusion filter.\n\nTo exclude 90% of `DEBUG` severity logs:\n\n```bash\ngcloud logging sinks update _Default \\\n    --project={project_id} \\\n    --add-exclusion=name=sample-debug-logs,filter='severity=DEBUG AND sample(insertId, 0.9)'\n```\n\n### Verify Log Exclusions and Cost Optimization (Tier R)\n\nTo verify that log exclusions are correct, list the details of the sink and\ncheck the `exclusions` to ensure your filter is present. For example, for the\n`_Default` sink:\n\n```bash\ngcloud logging sinks describe _Default --project={project_id}\n```\n\n--------------------------------------------------------------------------------\n\n## References and Supporting Links\n\n*   [Cloud Logging - Counter Metrics](https:\/\/docs.cloud.google.com\/logging\/docs\/logs-based-metrics\/counter-metrics.md.txt)\n*   [Cloud Logging - Custom Log Views](https:\/\/docs.cloud.google.com\/logging\/docs\/logs-views.md.txt)\n*   [Cloud Logging - Exclusions](https:\/\/docs.cloud.google.com\/logging\/docs\/routing\/overview.md.txt)\n","use_cases":["Create a regional log bucket with retention policy and Observability Analytics","Set up log sinks to route specific logs to a bucket","Create logs-based metrics to track error rates"],"limitations":[],"compatibility":[],"setup_tip":null,"sample_input":null,"sample_output":null,"source_url":"https:\/\/github.com\/google\/skills\/blob\/e3c591afe426ea585e4c21799e5199d6d47cd1be\/skills\/cloud\/cloud-logging-configuration-basics\/SKILL.md","source_commit":"e3c591afe426ea585e4c21799e5199d6d47cd1be","license":null,"version":null,"listing_approved_at":"2026-11-17","created_at":"2026-11-16T12:55:24.000000Z","updated_at":"2026-11-17T05:10:16.000000Z","seo_title":"Configure Cloud Logging Resources","seo_description":"Configure Cloud Logging resources like log buckets, views, and sinks for compliance and analytics. Learn how to set up log retention, filters, and metrics.","seo_keywords":["configure cloud logging","create log bucket","set up log sink","logs-based metrics","cloud logging configuration"]}}