Writing Application Logs

When a request is sent to your application running in App Engine, request and response details are logged automatically, and can be viewed in the Google Cloud Platform Console Logs Viewer.

When your application handles a request, it can also write its own logging messages to stdout and stderr. These files are automatically collected and can be viewed in the Logs Viewer. Only the most recent entries to stdout and stderr are retained, in order to limit their size.

The request and application logs for your app are collected by a Cloud Logging agent and are kept for a maximum of 90 days, up to a maximum size of 1GB. If you want to store your logs for a longer period or store a larger size than 1GB, you can export your logs to Cloud Storage. You can also export your logs to BigQuery and Pub/Sub for further processing.

For a list of available logs you can use, see below.

Runtime logs

In addition to App Engine-generated request logs, apps running in the flexible environment can write additional logs. The following are some of the logs that are configured by default:

Log name Purpose
activity Shows audit log information.
nginx.health_check Shows nginx logs specifically for health checks. Reduces noise in the request logs.
nginx.request Shows logs from the nginx proxy as they are passed through to the app.
stdout Standard output from your app.
stderr Standard error from your container.
vm.crash Information logged when setup fails. If your application fails to run, check this log.
vm.events Operational events related to instances.
vm.shutdown Information logged on shutdown.
vm.syslog The VM syslog, outside of the Docker container.

VM events logging

You can gain more insight into events related to your App Engine flexible environment instances using the vm.events stream in Cloud Logging. The following events are logged in this stream:

  • Instance was created
  • Instance was terminated (and why, reported on a best-effort basis)
  • Instance health check aggregate statistics reported approximately every minute
  • Instance unlocked for debugging or Instance was accessed via SSH

These logs might be interleaved, and without general formatting. Your application should not rely on programmatic parsing of these logs.

Shutdown logs

You can obtain diagnostic information when your application's Docker container is stopped. For exmple, this might happen if an app is unresponsive due to a deadlock or high load and has stopped returning requests, including health checks.

To help diagnose issues you can obtain debug information, such as thread traces and heap statistics, from the Docker container through Stackdriver Logging (available in stdout stream).

Shutdown logging for the application container is built into the JVM. For more information, see the documentation.

Writing application logs

Write your application logs using stdout for output and stderr for errors. Note that this does not provide log levels that you can use for filtering in the Logs Viewer; however, the Logs Viewer does provide other filtering, such as text, timestamp, etc.

Viewing logs

To view logs written by apps running in the flexible environment, use the Logs Viewer:

  1. Visit the Logs Viewer page in the Google Cloud Platform Console.

  2. From the log type pulldown menu, pick the log type (stdout, stderr, vm.crash, etc.), that you want to view.

  3. Use the desired filter to retrieve the logs you want to see. You can filter by various combinations of time, log level, module, and log filter label or regular expression.

    Notice that labels are regular expressions for filtering the logs by logging fields. Valid labels include the following:

    • day
    • month
    • year
    • hour
    • minute
    • second
    • tzone
    • remotehost
    • identd_user
    • user
    • status
    • bytes
    • referrer
    • useragent
    • method
    • path
    • querystring
    • protocol
    • request_id

    For example, path:/foo.* useragent:.*Chrome.* gets logs for all requests to a path starting with /foo that were issued from a Chrome browser.

Reading logs via API

There is no API for reading App Engine logs created in the flexible environment.

Send feedback about...

App Engine flexible environment for Java docs