Many programming languages have standard log-writing interfaces that you can reconfigure to use Logging.

<br />

> [!NOTE]
> **Note:**
>
> Instrument your application to collect specific information that helps you understand its
> performance and troubleshoot failures.
> Several open-source instrumentation frameworks collect log, metric, and trace
> data, and can send that data to any vendor, including Google Cloud. For your
> agentic applications, some frameworks can collect your prompts and responses or
> pass context that allows tracing of some remote
> [Google Cloud MCP servers](https://docs.cloud.google.com/mcp/overview.md.txt) calls.
>
> To instrument your application, we recommend that you use an
> open-source, vendor-neutral instrumentation framework, such as
> [OpenTelemetry](https://opentelemetry.io/), instead of
> vendor- and product-specific APIs or client libraries.
> For information about these frameworks, see
> [Observability for application developers](https://docs.cloud.google.com/stackdriver/docs/opentelemetry/application-developers.md.txt) and
> [Choose an instrumentation approach](https://docs.cloud.google.com/stackdriver/docs/instrumentation/choose-approach.md.txt).

## Write logs

To write logs to Cloud Logging, you can do any of
the following:

- Write your logs to existing log files such as `syslog` on your Compute EngineVM instance and use the Ops Agent to send the logs to Cloud Logging. For more information, see [Google Cloud Observability agents](https://docs.cloud.google.com/logging/docs/agent.md.txt).
- Configure a standard logging package to send the logs you write to Logging. For more information, see the following detail pages:
  - Any language: [fluentd](https://www.fluentd.org/)
  - [C#: Using ASP.NET or calling
    the API](https://docs.cloud.google.com/logging/docs/integrate/dotnet)
  - [Java: Using Logback and
    java.util.logging](https://docs.cloud.google.com/logging/docs/setup/java)
  - [Go: Using standard logging](https://docs.cloud.google.com/logging/docs/setup/go.md.txt)
  - [Node.js: Using Winston and Bunyan](https://docs.cloud.google.com/logging/docs/setup/nodejs.md.txt)
  - [PHP: Using PSR-3 logger](https://docs.cloud.google.com/logging/docs/setup/php.md.txt)
  - [Python: Using the standard logging
    facility](https://docs.cloud.google.com/logging/docs/setup/python)
  - [Ruby: Using the Google Cloud Observability
    gem](https://docs.cloud.google.com/logging/docs/setup/ruby)
- Call the Logging API using Logging's [Client Libraries](https://docs.cloud.google.com/logging/docs/reference/libraries.md.txt) for your programming language.
- Call the Logging API REST endpoint directly. See the [Logging API reference documentation](https://docs.cloud.google.com/logging/docs/reference/v2/rest.md.txt).
- Use the [gcloud CLI](https://docs.cloud.google.com/sdk/docs.md.txt). For more information, see the [`gcloud logging`](https://docs.cloud.google.com/logging/docs/reference/tools/gcloud-logging.md.txt) command-line interface.

<br />

> [!NOTE]
> **Note:** Incoming log entries with timestamps that are more than the [logs retention period](https://docs.cloud.google.com/logging/quotas.md.txt#logs_retention_periods) in the past or that are more than 24 hours in the future are discarded.

## Associate trace data with log entries

Log entries can contain information about traces. By including trace data
in log entries, you can correlate logs and traces to enable better
distributed troubleshooting. For information about manual and
automatic capture of trace information in log entries, see
[Integrate with Cloud Logging](https://docs.cloud.google.com/trace/docs/trace-log-integration.md.txt).

## Read logs

To read log entries in Logging, you can do any of
the following:

- In the Google Cloud console, go to the

  **Logs Explorer** page:

  [Go to **Logs Explorer**](https://console.cloud.google.com/logs/query)

  <br />

  If you use the search bar to find this page, then select the result whose subheading is
  **Logging**.

  For more information, see
  [Logs Explorer overview](https://docs.cloud.google.com/logging/docs/view/logs-explorer-interface.md.txt).
- Call the Logging API through
  the [client libraries](https://docs.cloud.google.com/logging/docs/reference/libraries.md.txt) for your
  programming language.

- Call the Logging API REST endpoints directly.
  See the [Logging API reference documentation](https://docs.cloud.google.com/logging/docs/reference/v2/rest.md.txt).

- Use the [gcloud CLI](https://docs.cloud.google.com/sdk/docs.md.txt). For more information, see the
  [`gcloud logging`](https://docs.cloud.google.com/logging/docs/reference/tools/gcloud-logging.md.txt) command-line interface.