Google Cloud

Cloud Logging Complete Guide: LQL, Log Router, Audit Logs & Retention

2026-05-24
NicheeLab Editorial Team

Cloud Logging is GCP's unified log management service that automatically collects, searches, and analyzes logs from every GCP service. Powerful search via Logging Query Language (LQL), flexible routing through Log Router, and compliance support via Audit Logs are its core capabilities.

Core Components

  • Log Entry: A single log record
  • Log Bucket: Log storage location (_Default / _Required / Custom)
  • Log Sink (Log Router): Log routing rules
  • Log View: Filtered view within a Bucket (RBAC)
  • Log-based Metric: Metrics generated from logs

Log Bucket Types

BucketRetentionUse Case
_Default30 days (configurable, up to 10 years)Default log destination
_Required400 days (fixed)Admin Activity / System Event / Policy Denied
Custom1 day to 10 yearsLong-term retention, Log Analytics

Logging Query Language (LQL) Examples

# 特定サービスのエラー
resource.type="cloud_run_revision"
resource.labels.service_name="my-api"
severity>=ERROR

# 特定 JSON フィールド
jsonPayload.user_id="user-123"
jsonPayload.duration_ms>1000

# 時間範囲
timestamp>="2026-05-01T00:00:00Z"
timestamp<="2026-05-31T23:59:59Z"

# 否定 + AND/OR
severity=(ERROR OR CRITICAL)
NOT textPayload:"health check"

# Audit log で特定操作
protoPayload.methodName="storage.buckets.delete"
protoPayload.authenticationInfo.principalEmail="[email protected]"

Audit Logs Types

TypeDescriptionPricing
Admin ActivityResource changes (always on, cannot be disabled)Free
Data AccessData reads / writes (must be enabled)$0.50/GiB
System EventSystem operations initiated by GoogleFree
Policy DeniedIAM / VPC SC denialsFree

Log Router (Sink) Patterns

  • BigQuery Sink: Export logs to BigQuery and analyze with SQL
  • Cloud Storage Sink: Long-term archive (cheap with the Archive class)
  • Pub/Sub Sink: Real-time integration to Dataflow / SIEM
  • Log Bucket Sink: Forward to a Bucket in a different Project / Region
  • Exclude Filter: Exclude unwanted logs before ingestion (cost reduction)

Log-based Metric Examples

# Counter: ERROR ログ件数
filter: 'resource.type="cloud_run_revision" severity>=ERROR'
metric_kind: DELTA
value_type: INT64

# Distribution: API レスポンス時間
filter: 'jsonPayload.event="api_request"'
value_extractor: 'EXTRACT(jsonPayload.duration_ms)'

Pricing

ItemPrice
Ingestion$0.50/GiB
Storage (beyond 30 days)$0.01/GiB/month
Free tier50 GiB of monthly ingestion
Log RouterFree (destination charges like BigQuery are separate)
Log AnalyticsFree (Storage is billed separately)

Log Analytics

  • Released in 2022; queries logs using the BigQuery engine
  • Complex analytics and JOINs using standard SQL
  • Create a Custom Bucket with Log Analytics enabled
  • Free (Storage charged at the standard rate)

Comparison with Other Clouds

ItemCloud LoggingCloudWatch LogsAzure Monitor Logs
Query languageLQLCloudWatch Logs InsightsKQL
Retention30 days to 10 years1 day to indefinite4 days to 2 years (+ Archive)
Ingestion price$0.50/GiB$0.50/GiB$2.30/GB
Long-term analyticsLog Analytics (BQ)S3 exportWorkspace

Best Practices

  • Use Exclude Filters to drop noisy logs like health checks
  • Use a BigQuery Sink for long-term retention (cheap and SQL-queryable)
  • Integrate with SIEM via a Pub/Sub Sink to any destination
  • Standardize on structured logging (jsonPayload)
  • Set severity correctly (INFO / WARNING / ERROR / CRITICAL)
  • Combine with Sensitive Data Protection to detect PII

What is the log retention period in Cloud Logging?

_Default Bucket = 30 days, _Required Bucket = 400 days (Audit Logs). Custom Buckets can retain logs for up to 10 years.

What is the log query language?

Logging Query Language (LQL). It uses a SQL-like syntax to filter by resource.type, severity, jsonPayload, and more.

What is a Log-based Metric?

Automatically generates Counter / Distribution metrics from logs. Example: convert ERROR log counts into a time-series metric and wire it up to alerts.

What can you do with Log Router (Sink)?

Routes logs to BigQuery / Cloud Storage / Pub/Sub / another Log Bucket. Essential for long-term analytics, SIEM integration, and cost optimization.

How many types of Audit Logs are there?

Admin Activity (always on), Data Access (must be enabled), System Event (always on), and Policy Denied (always on). Data Access generates by far the largest volume.

What is the pricing model?

Ingestion $0.50/GiB, storage $0.01/GiB/month (after 30 days). Includes 50 GiB of free monthly ingestion. Audit Admin Activity and System Event logs are free.

How does it compare to AWS CloudWatch Logs / Azure Monitor Logs?

GCP wins on LQL power; AWS uses CloudWatch Logs Insights; Azure uses KQL. GCP's strength is the combination of automatic GKE / Cloud Run collection plus LQL.

Can I send logs via OpenTelemetry?

Yes. Send logs to Cloud Logging via the OpenTelemetry Collector to avoid vendor lock-in on the application side.

Related Articles: Observability

GCP Professional Cloud Developer (PCD) 完全ガイド|Cloud Run・GKE・CI/CD・APM

Google Cloud Professional Cloud Developer の試験範囲、Cloud Run / GKE / Cloud Build / Cloud Trace、AWS DVA / Azure AZ-204 比較、学習ロードマップを徹底解説。

Eventarc 完全ガイド|CloudEvents・90+ イベントソース・サーバレストリガー (GCP)

Google Cloud Eventarc の全機能解説。CloudEvents 標準、Cloud Audit Logs / GCS / Pub/Sub トリガー、Cloud Run / Functions / Workflows ターゲット、料金、AWS EventBridge 比較を網羅。

GCP Professional Cloud Network Engineer (PCNE) 完全ガイド|VPC・Interconnect・Load Balancing

Google Cloud Professional Cloud Network Engineer の試験範囲、VPC / Cloud Interconnect / Cloud Load Balancing / Cloud Armor、AWS ANS・Azure AZ-700 比較を詳解。

Cloud Build 完全ガイド|CI/CD・cloudbuild.yaml・Private Pool・GitHub 連携 (GCP)

Google Cloud Cloud Build の全機能解説。cloudbuild.yaml、トリガー設定、Private Pool、Workload Identity、Build Approvals、Cloud Deploy 連携、AWS CodeBuild / Azure DevOps 比較を網羅。

Note: Google Cloud is a trademark of Google LLC. For the latest information, see the official Cloud Logging documentation.

Check what you learned with practice questions

Practice with certification-focused question sets

Go to the GCP exam prep page
Author

NicheeLab Editorial Team

NicheeLab editorial team focused on data engineering and cloud certification learning. Content is structured around practical study needs and official exam domains.


Related articles
Google Cloud

Google Cloud Certification Roadmap (2026)

Choose your GCP certification path — Foundational, Associate...

Google Cloud

CDL Cloud Digital Leader: Complete Exam Guide (2026)

Pass the Cloud Digital Leader exam — cloud business value, G...

Google Cloud

GAIL Generative AI Leader: Complete Exam Guide (2026)

Pass the Generative AI Leader exam — Gemini, Vertex AI, Work...

Google Cloud

Vertex AI Fundamentals for GCP Certs (2026)

Vertex AI basics every cert candidate needs — Workbench, Pip...

Google Cloud

Associate Cloud Engineer (ACE): Complete Guide (2026)

Pass the Associate Cloud Engineer exam — Console, gcloud, pr...

Browse all Google Cloud articles (103)
© 2026 NicheeLab All rights reserved.