- Access to the GCP Console.
- Permissions to open Cloud Shell and write logs in the project.
If this is your first time opening Cloud Shell, it may take a couple of minutes to provision a temporary VM and workstation. Authorize when prompted.
1) Open Cloud Shell and create a log entry
- In the GCP Console, open Cloud Shell (the terminal at the top-right).
- If prompted, click Authorize and wait for the terminal to become ready.
my-test-log with two JSON fields:
gcloud logging writewrites a single log entry to Cloud Logging.--payload-type=jsontells Cloud Logging the entry payload is structured JSON, so fields likeweatherare indexed injsonPayload.my-test-logis the log name (appears under the Logs Explorer).- The JSON string is the payload; here we include
messageandweatherfields.
New log entries can take a few seconds to appear in Logs Explorer. If your entry does not show up immediately, wait a moment and refresh or re-run your query.
2) Open Logs Explorer and filter by resource
- In the GCP Console search bar, search for “Logs Explorer” and open it.
- Logs Explorer opens with a default time range (for example, the last hour). Adjust the time range if needed.
- Click the resource selector (it may show “All resources”) and choose
globalwhen the log was written from Cloud Shell or the Cloud Console. - Alternatively, pick a specific resource type (for example,
BigQuery,GCE VM Instance,Cloud Function, etc.) to restrict results to that product.
global) ensures you’re searching the right scope for the entry you created.
3) Filtering by other resources (network, VPC)
If you need to search for network-related logs, choose the relevant networking resource in the resource selector (for example, VPC). You can also use a structured filter in the query bar. Example:4) Using the search bar and full-text search
Logs Explorer lets you do both full-text searches and structured field queries.- Full-text search example — find any log mentioning the word
weather:
- Structured field filter example — search the indexed JSON field created by the
--payload-type=jsonoption:
SEARCH() when you’re unsure of exact field names; prefer structured filters like jsonPayload.<field> when you want precise matches and more performant queries.
5) Practical use case: Airflow (Cloud Composer) troubleshooting
For data engineers: when an Airflow job (Cloud Composer) has issues and the Airflow UI doesn’t show logs, check Logs Explorer. Cloud Composer pushes task, scheduler, and worker logs to Cloud Logging, so error messages and stack traces are often available in Logs Explorer even if the UI is unavailable.Quick reference
| Task | Command / Filter | Notes |
|---|---|---|
| Write a JSON log entry | gcloud logging write --payload-type=json my-test-log '{ "message": "My second entry", "weather": "partly cloudy" }' | Writes a single structured log entry to my-test-log. |
| Full-text search | SEARCH("weather") | Finds the term anywhere in the log text or payload. |
| Structured JSON field filter | jsonPayload.weather="partly cloudy" | Query the indexed jsonPayload fields for exact matches. |
| Filter by network ID | resource.labels.network_id="6725867803041032465" | Use when searching for VPC or network-related logs. |
Summary
- Use
gcloud logging writeto create test log entries or rely on services that send logs automatically. - In Logs Explorer, set the time range and choose the correct resource (for example,
global,BigQuery,GCE VM Instance,VPC). - Use
SEARCH("...")for full-text searches andjsonPayload.<field>for structured JSON fields. - Logs Explorer is essential for debugging services (including Cloud Composer / Airflow) and locating error traces.
Links and References
- Cloud Logging overview
- gcloud logging write documentation
- Cloud Shell documentation
- Cloud Composer (Airflow) logging