Bitzu

Associate Cloud Engineer ยท Logging and audit logs

How do you filter logs in Logs Explorer and from the CLI?

Logs Explorer, the query language (resource.type, severity, textPayload), gcloud logging read, inspecting a log entry's details.

Key points

  • Write a query of field comparisons such as resource.type="gce_instance" severity>=ERROR textPayload:"timeout".
  • Comparisons next to each other are joined by AND; AND, OR and NOT must be capitalized.
  • The colon does a substring match.
  • From the CLI, gcloud logging read "<filter>" returns entries; by default only the last day (--freshness=1d), newest first, and you can add --limit and --format=json.

Source: https://docs.cloud.google.com/logging/docs/view/logging-query-language

Practice questions

Single choice

Which field do you use in a Logs Explorer query to restrict results to a kind of monitored resource, such as a VM instance?

  1. textPayload
  2. severity
  3. resource.type
  4. timestamp
Show answer

Answer: C. resource.type

resource.type (for example gce_instance) narrows entries to one monitored resource type and also speeds the query up.

Select all that apply

Which statements about the Logging query language are correct?

  1. AND can be omitted between two comparisons
  2. textPayload:"timeout" matches entries containing that text
  3. AND, OR and NOT must be written in capitals
  4. OR has higher precedence than NOT
  5. Lowercase and/or work the same as AND/OR
Show answer

Answer: A. AND can be omitted between two comparisons, B. textPayload:"timeout" matches entries containing that text, C. AND, OR and NOT must be written in capitals

Adjacent comparisons are ANDed, the colon is a substring match, and logical operators must be uppercase. NOT binds tighter than OR, not the other way round, and lowercase operators are not valid.

True or false

True or false: gcloud logging read searches the entire retention period of the bucket by default.

Show answer

Answer: False

False. The default --freshness is 1d, so only entries from roughly the last day are returned unless you widen it.

Practice 8 questions on this topic in Bitzu

Short lessons, instant explanations and spaced review of what you get wrong. Free on iOS and Android.

Download on the App StoreGet it on Google Play

More Associate Cloud Engineer topics in this module