Skip to main content

Cloud Logging

Exam guide§3.4

Cloud Logging is a fully managed service that stores, searches, analyzes, monitors, and alerts on log data - ingesting application and system logs from thousands of VMs across Google Cloud and AWS. Logs flow into the Log Router, which decides where each entry goes based on sinks. Every entry hits the router first, then lands in one or more log buckets and/or is exported out. You read entries in the Logs Explorer with filter queries.

Four-stage Cloud Logging pipeline. Collection: Other Cloud Services (automatic ingestion), Audit Logs, GKE logs via Kubernetes Engine and a Fluent Bit collector, Compute Engine process and third-party app logs via the Ops Agent, and Hybrid/Multi-Cloud. Route: the Logging API feeds the Cloud Logging Router, which fans out through Log Sinks. Store: Cloud Logging Storage with optional log bucket customization, and export to Google Cloud services (BigQuery, Cloud Storage, Pub/Sub) and third-party export. Visualize and Analyze: Log Analytics, Logs Explorer, and Error Reporting in Cloud Logging, plus Log Based Metrics and Alerts, Dashboards, Alert Policies, and Notifications in Cloud Monitoring, and third-party notifications.
The Cloud Logging pipeline end to end: logs are collected (Google Cloud services, GKE via a Fluent Bit collector, Compute Engine via the Ops Agent, plus hybrid/multi-cloud), routed through the Logging API and Log Router's sinks, stored in log buckets (with optional customization), and finally visualized and analyzed - Log Analytics, Logs Explorer, Error Reporting, and Cloud Monitoring dashboards, alert policies, and notifications, with third-party export.

Log types

Which logs you see depends on which resources you use. The key categories:

Platform logs icon
Platform logs
Written by Google Cloud services - they help you debug and understand the services you use. Example: VPC Flow Logs record a sample of network flows sent from and received by your VM instances.
Component logs icon
Component logs
Like platform logs, but generated by Google-provided software components running on YOUR systems - e.g. GKE components on your own VM or data center. The logs (or their metadata) are sent to your project so Google can provide support.
Security logs icon
Security logs
Answer "who did what, where, and when." Cloud Audit Logs cover admin activity and access within your resources; Access Transparency logs actions Google staff take when accessing your content.
User-written logs icon
User-written logs
Written by your own custom applications and services, sent to Cloud Logging via the Ops Agent, the Cloud Logging API, or client libraries.
Multi-cloud & hybrid-cloud logs icon
Multi-cloud & hybrid-cloud logs
Logs from other cloud providers (Microsoft Azure, AWS) and from on-premises infrastructure.
The Google Cloud logs visible in Cloud Logging depend on which resources you use. Five key categories: platform, component, security, user-written, and multi-cloud/hybrid.

Security logs are covered in depth on the Audit Logs page.

Collecting logs

You send app logs with client libraries, a logging agent, gcloud logging write, or the entries.write API endpoint. How automatic collection works depends on the platform:

DECISIONWhere do logs come from automatically?
GKE / Container-Optimized OSagents auto-collect from stdout and stderr
Compute Engine VMsOps Agent collects from files, Windows Event Log, journald, or syslogd
Serverless (Cloud Run, Cloud Run functions)stdout / stderr appear automatically, no agent
Pick this when: depends on the compute platform

Logs Explorer and filters

The Logs Explorer interface has six regions: an action toolbar (refine scope, share, learn), the query pane (build LQL, plus Recent / Saved / Suggested queries), a results toolbar (create metric/alert, jump to now), the Log fields panel (counts per field for fast refinement), the Histogram (log volume over time, color-coded by severity), and the query results list. Ultimately it is the query that selects the entries.

Logs Explorer interface with six labeled regions: Action toolbar, Query pane (showing resource.type=k8s_container -severity=ERROR), Results toolbar, Log fields panel with per-field counts, Histogram of log volume by severity over time, and the Query results list.
The Logs Explorer panes: the action toolbar and query pane up top, a results toolbar, then the Log fields panel (entry counts per field), the Histogram (volume over time by severity), and the query results list. Click a field, a histogram bar, or a result to refine the query.

The Logs Explorer uses the Logging query language (LQL): filter by resource.type, severity, logName, labels, and free text. Severities: DEFAULT < DEBUG < INFO < NOTICE < WARNING < ERROR < CRITICAL < ALERT < EMERGENCY.

Build the query with the drop-down menus, the Log fields panel, or by clicking a field in a result. The drop-downs combine selections differently depending on the field:

FactsQuery-builder drop-down logic
  • Resource (resource.type) - one at a time; multiple entries are joined with AND.
  • Log name (logName) - multiple at once, joined with OR.
  • Severity (severity) - multiple at once, joined with OR.
FactsComparison operators
  • = and != - match / not-match a field value (find a specific resource type or id).
  • > < >= <= - numeric ordering, handy on timestamp or duration fields.
  • : - "has" / substring match within a field.
  • :* - test that a field exists (is present or defaulted) without matching a value.
GotchaBoolean operators must be UPPERCASE, and precedence bites

AND, OR, NOT must be written in all caps. Precedence is NOT > OR > AND (not the usual AND-before-OR), and AND/OR are short-circuit operators - parenthesize when in doubt.

Prefer the built-in SEARCH() function over a raw global or substring search - it is more efficient. SEARCH([query]) scans the whole entry; SEARCH([field], [query]) scans one field. It only matches text fields, so it can't search non-text fields.

FactsMake queries fast
  • Search indexed fields - logName, resource.type, resource.labels - these are preferentially indexed and make the biggest difference.
  • Name the log(s) you want explicitly rather than doing a full-text scan (full-text is slow).
  • Restrict the time range to shrink the data scanned.
CommandsRead and filter logs
gcloud logging read 'resource.type="gce_instance" severity>=ERROR' --limit=20
gcloud logging logs list

Log buckets

Storage lives in log buckets. Two exist automatically in every project:

NumbersDefault buckets and retention
  • _Required bucket - Admin Activity + System Event audit logs, 400 days, fixed, free, cannot be deleted or changed.
  • _Default bucket - everything else, 30 days default retention (configurable up to 3650 days / 10 years).

Log Router and sinks

Every entry hits the Log Router first, which uses inclusion and exclusion filters on its sinks to decide where each entry goes - one or more log buckets and/or exported destinations.

Five log types flow into the centralized logging API, which routes through the Required, Default, and user-defined log sinks into matching log buckets with 400-day and 30-day retention, and on to Cloud Storage, BigQuery, and Pub/Sub, then third-party applications.
Every log type enters through the centralized Logging API, and the Log Router's sinks fan entries into log buckets (the _Required bucket keeps 400 days and is non-configurable; _Default and user-defined keep a configurable 30 days) and out to Cloud Storage, BigQuery, or Pub/Sub.

A sink = an inclusion filter + a destination. This is how you route or export logs. You can also add exclusion filters to drop noisy logs before they're stored (saves cost).

Log sink flow: Logs enter Logging, pass through a Filter (severity >= ERROR, resource.type k8s_container, resource.labels.project_id), then a Log sink writes the matches to a chosen sink service. The Select sink service dropdown lists Cloud Logging bucket, BigQuery dataset, Cloud Storage bucket, Cloud Pub/Sub topic, Splunk, and Other project.
Creating a sink: logs flow through Logging, a filter (e.g. severity >= ERROR on a k8s_container in a given project) narrows what matches, and the log sink writes the matches to the selected sink service - Cloud Logging bucket, BigQuery dataset, Cloud Storage bucket, Cloud Pub/Sub topic, Splunk, or another project.
DECISIONWhere does a sink send logs?
Cloud Logging bucketPre-separate entries into a distinct log bucket
BigQuery datasetSQL query power for large / complex entries
Cloud Storage bucketSimple external archive / processing by other systems
Pub/Sub topicExport to third-party apps (Dataflow, Cloud Run functions)
SplunkIntegrate into an existing Splunk-based system
Other projectControl access to a subset of log entries
Pick this when: match the destination to the analysis need
GotchaAggregated sinks for org-wide export

To capture logs from every project in a folder or org into one destination, create an aggregated sink at the org, folder, or billing-account level. A per-project sink only catches that one project. Also: the sink's writer service account needs write permission on the destination or exports silently fail.

For security analytics, a common sink destination is Chronicle (Google's SIEM), joining Splunk and Pub/Sub-fed third-party SIEMs as the place aggregated security logs are streamed for threat detection.

Collect: Cloud Logging. Route: an aggregated sink in the Log Router. Analyze: the sink fans out to Log Analytics and BigQuery, and via Pub/Sub and Cloud Storage to a third-party SIEM, plus Chronicle SIEM through native ingest for a subset of Google Cloud logs.
Security-log routing: an aggregated sink in the Log Router fans logs from Cloud Logging out to the analysis destinations - Log Analytics and BigQuery for query, Pub/Sub and Cloud Storage as bridges to a third-party SIEM, and Chronicle SIEM via native ingest for a subset of Google Cloud logs.

Analyze exported logs

Logs are only retained for 30 days in the _Default bucket, so exporting is how you both keep them longer and do real analysis. Match the destination to the goal: Cloud Storage for cheap long-term archive, BigQuery to run fast SQL over the data, and Pub/Sub to stream entries to external apps or endpoints. Once logs land in a BigQuery dataset, connect the tables to Looker Studio to turn raw entries into reports and dashboards.

The simplest export path, end to end - events land in Logging and a sink writes matching entries straight to a Cloud Storage bucket for cheap long-term archive:

Three-step log export to Cloud Storage: Events, then Logging, then Cloud Storage.
Export to Cloud Storage for cheap long-term archive: events flow into Cloud Logging, and a sink writes matching entries straight to a Cloud Storage bucket.
Cloud Loggingexported logssink → BigQuery datasetBigQueryfast SQL, GB to PBconnect tablesLooker Studioreports & dashboardsForecast capacityfrom traffic growthOptimize costcut network egress spendNetwork forensicsanalyze incidents by IP
Export logs to a BigQuery dataset via a sink, run fast SQL to analyze network traffic, then connect the tables to Looker Studio for dashboards.
FactsWhat BigQuery + Looker Studio analysis buys you
  • Forecast capacity - query network-traffic logs to understand traffic growth over time.
  • Optimize spend - find your heaviest flows and cut network egress costs.
  • Network forensics - identify the top IP addresses talking to a server; relocate infrastructure or deny hostile IPs.
  • Looker Studio turns the BigQuery tables into shareable reports and dashboards - no SQL needed for viewers.
GotchaField names get lowercased in BigQuery

LogEntry-type fields keep their exact names, but user-supplied and structured-payload fields (without an @type) are normalized to lowercase in the BigQuery schema. So jsonPayload.MESSAGE becomes jsonpayload.message - write your SQL against the lowercase form.

Log entry fieldLogEntry type mappingBigQuery field name
insertIdinsertIdinsertId
textPayloadtextPayloadtextPayload
httpRequest.statushttpRequest.statushttpRequest.status
httpRequest.requestMethod.GEThttpRequest.requestMethod.[ABC]httpRequest.requestMethod.get
resource.labels.moduleidresource.labels.[ABC]resource.labels.moduleid
jsonPayload.MESSAGEjsonPayload.[ABC]jsonPayload.message
jsonPayload.myField.mySubfieldjsonPayload.[ABC].[XYZ]jsonPayload.myfield.mysubfield
How log entry fields map to BigQuery column names on export: LogEntry-type fields carry over exactly, while user-supplied and structured-payload fields (the [ABC]/[XYZ] placeholders) are lowercased. Highlighted cells are the ones the export renames.

Streaming export in near real time

The sink-to-BigQuery path above is a periodic batch export. When you need logs queryable seconds after they happen, stream them instead: route to a Pub/Sub topic, run a Dataflow pipeline that transforms and loads the stream, and land it in BigQuery.

Five-stage streaming export pipeline: Events enter Logging, which publishes to Pub/Sub, a Dataflow pipeline processes the stream, and results land in BigQuery.
Near-real-time export: events flow into Cloud Logging, out to a Pub/Sub topic, through a Dataflow streaming pipeline, and into BigQuery for immediate SQL analysis.

Log-based metrics

Log-based metrics derive Cloud Monitoring metrics from the content of log entries - for example, count entries containing a specific message, or extract a latency value. They become time series you can use in Monitoring charts and alerting policies. This is the bridge from logs to monitoring/alerting.

Log entries enter Cloud Logging, pass through a Filter, then branch to Count or Extract, and the resulting log-based metric feeds Cloud Monitoring.
Log entries flow into Cloud Logging, a filter narrows them, then the metric either counts matching entries or extracts a value from them - the resulting log-based metric becomes a time series in Cloud Monitoring.
log entriesfilter / extractCountercounts matching entriesDistributionbuckets an extracted valueBooleandid a filter match?Cloud Monitoringchart & alert
A log-based metric turns matching log entries into a monitoring time series. Counter counts entries, distribution buckets an extracted value, boolean records whether a filter matched.
FactsTwo sources, three types
  • System-defined - provided by Cloud Logging, available to all projects, all of the counter type. Calculated only from logs actually ingested (excluded logs don't count).
  • User-defined - you create them for what matters to you; can be counter, distribution, or boolean.
  • Counter - counts log entries matching a query.
  • Distribution - records the statistical distribution of an extracted numeric value in histogram buckets (count, mean, sum of squared deviations).
  • Boolean - records whether an entry matched the filter.
GotchaScope: project-level vs bucket-scoped

System-defined and project-level user metrics apply only to logs received in that project. Bucket-scoped user metrics apply to logs in a specific log bucket regardless of source project - the way to measure logs routed in from other projects or via an aggregated sink.

The Google Cloud resource hierarchy (Organization, Folders, Projects, Bucket): system-defined log-based metrics apply at the project level, while user-defined log-based metrics can apply at either project or bucket level.
System-defined log-based metrics apply at the project level. User-defined log-based metrics can apply at either the project or the bucket level.
GotchaLabels multiply time series - and are permanent

User-defined labels (extracted from a LogEntry field, optionally via a regexp) let one metric hold many time series. But a metric supports up to 10 user-defined labels, caps at about 30,000 active time series, and a metric cannot be removed once created. 100 resources x a 20-value label = up to 2,000 series - label with care.

Log Analytics

Log Analytics gives you BigQuery's analytical power inside the Cloud Logging console, with a UI optimized for log data. You enable it on a log bucket (an "analytics-enabled bucket"); Cloud Logging then makes that data queryable in the Log Analytics UI and in BigQuery, without you routing or managing a second copy. You can still query it with the normal Logging query language too.

GotchaAnalytics-enabled bucket vs routing logs to BigQuery

With an analytics-enabled bucket the log data is managed by Cloud Logging: BigQuery ingestion/storage costs are part of your Logging bill, residency and lifecycle stay under Logging, and BigQuery sees it through a read-only view. That's different from a sink that exports a separate copy into BigQuery.

GotchaUpgrading a bucket to Log Analytics is permanent

Create a bucket, choose Upgrade to use Log Analytics. You cannot later downgrade a bucket to remove it.

FactsWho uses Log Analytics
  • DevOps - reduce MTTR: count top requests grouped by response type and severity to diagnose fast.
  • Security - investigate over large volumes (e.g. all audit logs for one user over a month).
  • IT / Network - network insights across GKE, VPC, and firewall logs via advanced log aggregation.

Exporting on-prem or to a SIEM

There is no direct "on-prem" sink. Route to a Pub/Sub topic and pull from your on-prem collector or Splunk/SIEM. Pub/Sub is the bridge for anything off-GCP. See Partner integrations for the full Pub/Sub to Splunk Dataflow reference architecture.

Four-stage flow: events feed into Cloud Logging, then a Pub/Sub topic, and finally out to Splunk.
Streaming logs to a SIEM: events are collected by Cloud Logging, a sink routes them to a Pub/Sub topic, and Splunk (or another SIEM) pulls from Pub/Sub. Pub/Sub is the bridge for any off-GCP destination.