Loading...
Loading...
Configure single-project Google Cloud Logging: regional log buckets, log sinks, log views, restricting or hiding sensitive logs in the default view (_Default) filter, IAM permissions for views (Logs View Accessor, IAM conditions), logs-based metrics, log exclusions, and sampling. Don't use for cross-project logging or multi-project setups.
npx skill4agent add google/skills cloud-logging-configuration-basics[!IMPORTANT] Sandbox Network Limitation (CRITICAL for Agent Testing): During evaluation or in restricted sandboxed environments, network traffic to Google Cloud APIs is blocked. Do NOT run network discovery commands to find resource names, project IDs, or organization IDs. Always use the exact project IDs or placeholders provided in the user prompt or instructions for example,. Assume these resources exist and proceed directly with configuration commands. Running these discovery commands will cause the execution to hang and timeout.{project_id}
gcloud logging readgcloud logging buckets listgcloud logging views creategcloud logging views updategcloud logging scopes creategcloud logging buckets creategcloud logging metrics creategcloud logging links creategcloud projects add-iam-policy-bindinggcloud logging buckets deletegcloud logging sinks update --add-exclusiongcloud[!WARNING] Mandatory Observability Analytics Downgrade Warning: Whenever providing guidance, writing a guide, or drafting commands on Cloud Logging cost optimization or exclusions, you must explicitly include the following warning in your final text response and any generated guides: "After a log bucket has been upgraded to use Observability Analytics, it cannot be downgraded to remove the analytics capability."
gcloud logging buckets create {bucket_id} \
--project={project_id} \
--location={region} \
--retention-days={retention_days} \
--enable-analytics{bucket_id}my-custom-bucket{region}us-central1{retention_days}365gcloud logging buckets describe {bucket_id} \
--location={region} \
--project={project_id}[!IMPORTANT] Billing Action (Tier B): Routing log entries to a bucket incurs ongoing charges based on the volume of data stored. You MUST get interactive user confirmation before running this command.
gcloud logging sinks create {sink_id} \
projects/{project_id}/locations/{region}/buckets/{bucket_id} \
--log-filter='{filter_expression}' \
--project={project_id}[!IMPORTANT] Billing Action (Tier B): Creating logs-based metrics incurs ongoing charges based on the volume of data points reported. You MUST get interactive user confirmation before running this command.
gcloud logging metrics create {metric_name} \
--log-filter='{filter_expression}' \
--description='{description}' \
--project={project_id}{metric_name}oom_error_count{filter_expression}textPayload:"OutOfMemory"{description}describegcloud logging metrics describe {metric_name} \
--project={project_id}roles/logging.viewer_Default_Default[!IMPORTANT] Ambiguity Handling (Guidance for Agents): If the user asks to "exclude", "hide", or "remove" sensitive logs without explicitly specifying whether they want to stop storing them, you MUST default to excluding them from the default view (Step 1). This is a safe, non-destructive Tier M action. Only configure a storage exclusion (under the "Discarding Sensitive Logs from Storage" section) if the user explicitly uses destructive terms like "stop storing", "permanently discard", or "sink exclusion".
_Defaultgcloud logging views update _Default \
--bucket=_Default \
--location=global \
--project={project_id} \
--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}")'_Default{sensitive_log_id}gcloud logging views create security-logs-view \
--bucket=_Default \
--location=global \
--project={project_id} \
--log-filter='LOG_ID("{sensitive_log_id}")' \
--description="Sensitive logs"[!IMPORTANT] Security Action (Tier B): Granting IAM permissions changes access control policy and must be explicitly confirmed by the user before execution.
{security_group_email}security-logs-view_Defaultgcloud projects add-iam-policy-binding {project_id} \
--member='group:{security_group_email}' \
--role='roles/logging.viewAccessor' \
--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"{location}globalus-central1gcloud logging views describe {view_id} \
--bucket={bucket_id} \
--location={region} \
--project={project_id}filter[!CAUTION] Destructive Action (Tier D): Excluding logs from all log sinks deletes the log entries immediately and irreversibly.Safety Rule: You MUST ask the user for explicit typed confirmation, for example, "I confirm I want to excludelogs from storage", before running this command. Same-Turn Restriction: Do NOT execute the{sensitive_log_id}command in the same turn as asking for confirmation. Stop tool execution immediately and wait for the user to reply.gcloud logging sinks update
gcloud logging sinks update _Default \
--project={project_id} \
--add-exclusion=name=exclude-sensitive,filter='LOG_ID("{sensitive_log_id}")'[!CAUTION] Destructive Actions (Tier D): Exclusions in this section may immediately halt storage of log entries.Safety Rule: You MUST ask for explicit typed confirmation (for example, "I confirm I want to exclude load balancer logs") before executing exclusions or sampling updates.
gcloud logging sinks update {sink_id} \
--project={project_id} \
--add-exclusion=name={exclusion_name},filter={exclusion_filter}{sink_id}{exclusion_name}{exclusion_filter}sample()[!IMPORTANT] Thefunction matches asample(field, fraction)of logs. When used in an exclusion filter, the matched logs are discarded. If you exclude 90% of log entries, then only 10% are retained. To exclude 90%, usefractionin the exclusion filter.sample(insertId, 0.9)
DEBUGgcloud logging sinks update _Default \
--project={project_id} \
--add-exclusion=name=sample-debug-logs,filter='severity=DEBUG AND sample(insertId, 0.9)'exclusions_Defaultgcloud logging sinks describe _Default --project={project_id}