This document discusses the concept of structured logging and the methods for
adding structure to log entry payload fields. When the log payload is formatted
as a JSON object and that object is stored in the jsonPayload field, the log
entry is called a structured log. For these logs, you can construct queries
that search specific JSON paths and you can index specific fields in the
log payload. In contrast, when the log payload is formatted as a string and
stored in the textPayload field, the log entry is unstructured.
You can search the text field, but you can't index its content.
To create structured log entries, do any of the following:
- Call the
entries.writeAPI method and supply a fully formattedLogEntry. - Use the
gcloud logging writecommand.
For more information about these approaches, see the following sections.
Write logs by using the gcloud CLI
You can write log data by using the gcloud CLI. The interface supports unstructured logs and structured logs. When you want to write a structured log, provide the command a serialized JSON object.
For a quickstart, see Write and query log entries with the Google Cloud CLI.
For code examples, see the
gcloud logging write reference.
What's next
To query and view log entries, see View logs by using the Logs Explorer.
To read log entries using the Google Cloud CLI, see Reading log entries.
To read log entries using the Logging API, see the
entries.listmethod.