In Cloud Logging, a LogEntry object can store a log payload as
either structured data or unstructured text. A structured log entry stores its
payload as a JSON object in the jsonPayload field, whereas an unstructured
log entry stores its payload as a string in the textPayload field.
Formatting your log payload as a JSON object lets you search and query by JSON paths in the Logs Explorer. With unstructured logs, you can search the text string, but you can't query individual keys.
How structured logs are written
How structured log entries are written to Logging depends on your environment and how your logs are collected:
- Logging client libraries: These libraries
write structured logs when you pass a JSON object or map as the payload, or
when they output single-line JSON to
stdoutorstderr.
- Google Cloud CLI or the
Logging API: You can run
gcloud logging writewith the--payload-type=jsonflag (example), or call theentries.writeAPI method with ajsonPayloadobject.
What's next
To query and view log entries, see View logs by using the Logs Explorer.
To read log entries by using the gcloud CLI, see Reading log entries.
To read log entries by using the Logging API, see the
entries.listmethod.