Cloud Logging supports write- and read-time aggregation of log entries. Configure log sinks to route entries to a centralized log bucket (write-time), and configure log scopes to query logs across projects (read-time).
Log storage and views
When you create a project, folder, or organization, Cloud Logging
automatically creates two log buckets, _Required and _Default.
If default resource settings for Cloud Logging are configured, then
the system sets the location and encryption key based on
those settings. Otherwise, the system selects a location and uses a
Google-owned and Google-managed encryption key. After a log bucket exists, you can't
change its location or encryption model.
By default, the _Required and _Default log sinks route log entries to the
log buckets of the same names. You can modify the _Default log sink.
Every log bucket has a system-created log view, _AllLogs, which includes every
log entry. The _Default log bucket has a second log view, _Default; this
view excludes Data Access audit logs.
Cloud Logging lets you create custom log buckets and log views and change which log entries are stored and how they are routed.
Configure write-time aggregation using log sinks
To centralize log storage across multiple Google Cloud projects, we recommend these steps:
Select a dedicated project to store your log data.
Route log entries to that dedicated project.
In the dedicated project, store operational logs in the
_Defaultlog bucket. If you centralize required logs, store them in a custom log bucket whose name includesAudit, regardless of capitalization. Required logs are audit logs that are always collected and stored.
For information about other routing options, see
Route to a project versus a log bucket
and Custom versus _Default log buckets.
Select a project that is dedicated to storing your log data
Choose a dedicated Google Cloud project whose lifecycle you manage. Don't store
centralized telemetry in a Google-managed project, such as a google-mpf-* or
google-mpo-* management project. Google Cloud deletes those
projects—along with your log buckets and configuration—when you
disable the capability or delete its capability configuration:
- Standard project (recommended): A standard project is a project that you create. You manage its lifecycle. Use a standard project when you don't govern the boundary with a self-managed management project.
- Self-managed management project (recommended): A self-managed management project is a project that you create and then convert to a management project by creating a capability configuration that designates it. For cross-project boundaries, the capability configuration attaches one or more boundaries. You manage its lifecycle. Use this option when you govern the boundary with a self-managed management project.
Google-managed project (not recommended): Google Cloud creates this project automatically when you enable application management on a folder, or when you create a capability configuration without specifying a standard project. The project ID follows the pattern
google-mpf-*orgoogle-mpo-*. Google Cloud deletes the project if you disable the capability or delete the capability configuration.Don't use a Google-managed project to centralize your log data. Instead, create a standard Google Cloud project anywhere in your organization to store your centralized logs. If you plan to convert that project into a self-managed management project, create it directly under the parent folder or organization of your capability configuration.
Route log entries to the dedicated project
How you route log entries from source resources to your dedicated project depends on your resource hierarchy:
Centralize logs for a folder: Create a folder-level aggregated sink with the dedicated project as its destination and configure these settings:
- Leave the inclusion filter empty to match all log entries.
- Route log entries from child resources.
- Enable sink interception so child sinks, except for the
_Requiredsinks in originating resources, don't also route matching entries. - If the dedicated project resides in the folder, then add an exclusion filter for that project so the aggregated sink doesn't route the dedicated project's own logs back to itself.
You can also create organization-level aggregated sinks; see Aggregated sinks overview.
Centralize logs for specific or tag-bounded projects: Update the
_Defaultlog sink in each source project to route log entries to the dedicated project. This update routes only non-required logs because the_Defaultsink excludes required logs by default. To centralize required logs as well, either remove exclusions from the_Defaultlog sink or create a custom log sink whose inclusion filter matches the_Requiredlog sink's inclusion filter.
Configure sinks for your centralization use case
In your dedicated project, store operational logs in _Default and, if you
centralize required logs, route them to a custom bucket such as
CentralizedAudit:
Operational logs (
_Default): Store operational logs in the_Defaultlog bucket rather than creating a custom log bucket, because services that build dashboards or compute performance metrics expect operational log data in_Default. No sink changes are needed; the pre-configured_Defaultsink matches all non-required log entries and routes them to_Default.If you want to use SQL to analyze the stored log data, then upgrade the
_Defaultlog bucket to use Observability Analytics.Required logs (
CentralizedAudit): Because the built-in_Requiredsink only matches entries that originate in the dedicated project, create a custom sink and a custom log bucket to store incoming required logs forwarded from source projects. Don't store centralized required logs in the_Defaultlog bucket.Create a custom log bucket,
CentralizedAudit, upgrade it to use Observability Analytics, and configure its retention period.Create a custom log sink,
routeAudit, targeting theCentralizedAuditbucket, and set its inclusion filter to match the_Requiredsink's filter.Add an exclusion filter for the dedicated project so its own required logs aren't stored in both
_RequiredandCentralizedAudit. Omit this exclusion only if you wantCentralizedAuditto retain required logs for all projects in one log bucket.
Configure read-time aggregation using log scopes
To configure read-time aggregation:
Identify the project where you want to view your log data. This project might be different from the project where you store your centralized log data.
If you use a management project, then use it to view your log, metric, and trace data.
In your viewing project, create a custom log scope, add the relevant log views, and set it as the default log scope.
When you open Logs Explorer, the page queries the listed views and displays data you have permission to see.
A log scope can list at most 100 log views, though you can create multiple log scopes and switch between them from the Logs Explorer toolbar.
For more information, see Configure observability scopes for multi-project queries.
Roles required to view log data
Principals who view centralized logs need permissions on both the log views in your storage project and the log scopes in your viewing project:
- Access log entries in views: Grant
Logs View Accessor (
roles/logging.viewAccessor) to let principals query custom views and views on custom log buckets. To restrict access to specific log entries, grant this role on custom views, on the system-created_AllLogsand_Defaultviews, or on the storage project with an IAM condition. For more information, see Grant access to a log view. - Select and query log scopes: Grant
Logs Viewer (
roles/logging.viewer) on the viewing project so principals can select log scopes in Logs Explorer. This grant applies only to the viewing project and doesn't grant access to logs stored in a separate storage project.
Architectural choices for write-time aggregation
The following sections provide detailed comparisons of the routing and storage options available during write-time aggregation.
Route to a project versus a log bucket
The destination of an intercepting aggregated sink must be a project. Non-intercepting aggregated sinks and project-level sinks can route log entries to a project or to a log bucket in any project.
| Routing option | Advantages | Disadvantages |
|---|---|---|
|
Route to another standard project or to a self-managed management project (recommended)
Best when: you centralize log data across a folder or organization, need central alerts or metrics, or want to eliminate duplicate child storage. |
|
|
|
Route directly to a log bucket in another project
Best when: individual projects export directly to central storage without central alerting or project-scoped metrics. |
|
|
Custom versus _Default log buckets
Store operational logs in the destination project's _Default bucket so
services that build dashboards or compute performance metrics can find the log
data. If you need to control the location or CMEK for this bucket, configure
default resource settings for Cloud Logging before you create the destination project.
If you centralize required logs, create a custom log bucket whose name
includes Audit, regardless of capitalization, rather than using _Default.
Unlike _Default, custom buckets let you choose any supported storage region
and CMEK at creation time and can be deleted later.
What's next
For more information, see the following documents:
- Centralized observability best practices
- Configure default resource settings for Cloud Logging
- Configure observability scopes for multi-project queries
- Configure log buckets
- Configure log views on a log bucket
- Aggregate and store your organization's logs