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 Stackdriver Logs Viewer.
When your application handles a request, it can also
write its own logging messages to
stderr. These files are
automatically collected and can be viewed in the Logs Viewer. Only the most
recent entries to
stderr are retained, in order
to limit their size.
The request and application logs for your app are collected by a Stackdriver Logging agent. See Quota Policy for the logs retention policy and for the maximum size of log entries. If you want to store your logs for a longer period, 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.
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:
||Shows audit log information.|
||Shows nginx logs specifically for health checks. Reduces noise in the request logs.|
||Shows logs from the nginx proxy as they are passed through to the app.|
||Standard output from your app.|
||Standard error from your container.|
||Information logged when setup fails. If your application fails to run, check this log.|
||Operational events related to instances.|
||Information logged on shutdown.|
||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 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.
You can obtain diagnostic information when your application's Docker container is stopped. For example, 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
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.
To view logs written by apps running in the flexible environment, use the Logs Viewer:
Visit the Logs Viewer page in the Google Cloud Platform Console.
From the log type pulldown menu, pick the log type (
vm.crash, etc.), that you want to view.
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:
path:/foo.* useragent:.*Chrome.*gets logs for all requests to a path starting with
/foothat were issued from a Chrome browser.
Reading logs via API
There is no API for reading App Engine logs created in the flexible environment.