Python 2.7 has reached end of supportand will bedeprecatedon January 31, 2026. After deprecation, you won't be able to deploy Python 2.7applications, even if your organization previously used an organization policy tore-enable deployments of legacy runtimes. Your existing Python2.7 applications will continue to run and receive traffic after theirdeprecation date. We recommend thatyoumigrate to the latest supported version of Python.

Reading and Writing Application Logs

Overview

When a request is sent to your app, a request log is automatically written byApp Engine. During the handling of the request, your app can also writeapplication logs. In this page, you'll learn how to write application logsfrom your application, how toview logging in theGoogle Cloud console, and how to understand the request log data that App Enginewrites during the request.

For information about downloading log data, seeOverview of logs exports.

Important: Be aware that logs by default do not persist when you use thedevelopment app server. For information on how to make logs persist, seeThe development server and Logs API.

Request logs vs application logs

There are two categories of log data: request logs and application logs. A request log is automatically written by App Engine for each request handled by your app, and contains information such as the project ID, HTTP version, and so forth. For a complete list of available properties for request logs, seeRequestLog. Seealso therequest log table for descriptions of the request log fields.

Each request log contains a list of application logs (AppLog) associated with that request, returned in theRequestLog.app_logs property. Each app log contains the time the log was written, the log message, and the log level.

Note: A request log can only hold 1000 app logs. If you add more than 1000, the older logs will not be retained.

Writing application logs

Important: Individual log entries from an application have a 16KB limit.Nothing beyond this limit will be written to the app log.You may find it useful to read the documentation for the standard Python loggingmodule atPython.org.

The Python logging module allows a developer to log 5 levels of severity. :

  • Debug
  • Info
  • Warning
  • Error
  • Critical

The following example shows how to use the different logging levels:

importloggingimportwebapp2classMainPage(webapp2.RequestHandler):defget(self):logging.debug('This is a debug message')logging.info('This is an info message')logging.warning('This is a warning message')logging.error('This is an error message')logging.critical('This is a critical message')try:raiseValueError('This is a sample value error.')exceptValueError:logging.exception('A example exception log.')self.response.out.write('Logging example.')app=webapp2.WSGIApplication([('/',MainPage)],debug=True)

Log URL format in the Google Cloud console

See the following sample URL for an example of the log URL format in the Google Cloud console:

https://console.cloud.google.com/logs?filters=request_id:000000db00ff00ff827e493472570001737e73686966746361727331000168656164000100

Note: The URL no longer includes thefilter_type.

Reading logs in the console

Note: the logs described here are shown as visible in the Log Viewer.

To view logs written by apps running in the standard environment, use theLogs Explorer.

A typical App Engine log contains data in theApache combined log format,along with some special App Engine fields, as shown in the following sample log:

192.0.2.0-test[27/Jun/2014:09:11:47-0700]"GET / HTTP/1.1"200414"http://www.example.com/index.html"Mozilla/5.0(X11;Linuxx86_64)AppleWebKit/537.36(KHTML,likeGecko)Chrome/35.0.1916.153Safari/537.36""1-dot-calm-sylph-602.appspot.com"ms=195cpu_ms=42cpm_usd=0.000046loading_request=1instance=00c61b117cfeb66f973d7df1b7f4ae1f064dapp_engine_release=

Understanding request log fields

The following table lists the fields in order of occurrence along with adescription:

Field OrderField NameAlways Present?Description
1Client addressYesClient IP address. Example:192.0.2.0
2RFC 1413 identityNoRFC 1413 identity of the client. This is nearly always the character-
3UserNoPresent only if the app uses the Users API and the user is logged in. This value is the "nickname" portion of the Google Account, for example, if the Google Account istest@example.com, the nickname that is logged in this field istest.
4TimestampYesRequest timestamp. Example:[27/Jun/2014:09:11:47 -0700]
5Request querystringYesFirst line of the request, containing method, path, and HTTP version. Example:GET / HTTP/1.1
6HTTP Status CodeYesReturned HTTP status code. Example:200
7Response sizeYesResponse size in bytes. Example:414
8Referrer pathNoIf there is no referrer, the log contains no path, but only-. Example referrer path:"http://www.example.com/index.html".
9User-agentYesIdentifies the browser and operating system to the web server. Example:Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/35.0.1916.153 Safari/537.36
10HostnameYesThe hostname used by the client to connect to the App Engine application. Example : (1-dot-calm-sylph-602.appspot.com)
11Wallclock timeYesTotal clock time in milliseconds spent by App Engine on the request. This time duration does not include time spent between the client and the server running the instance of your application. Example:ms=195.
12CPU millisecondsYesCPU milliseconds required to fulfill the request. This is the number of milliseconds spent by the CPU actually executing your application code, expressed in terms of a baseline 1.2 GHz Intel x86 CPU. If the CPU actually used is faster than the baseline, the CPU milliseconds can be larger than the actual clock time defined above. Example:cpu_ms=42
13Exit codeNoOnly present if the instance shut down after getting the request. In the formatexit_code=XXX whereXXX is a 3 digit number corresponding to the reason the instance shut down. The exit codes are not documented since they are primarily intended to help Google spot and fix issues.
14Estimated costYesDEPRECATED. Estimated cost of 1000 requests just like this one, in USD. Example:cpm_usd=0.000046
15Queue nameNoThe name of the task queue used. Only present if request used a task queue. Example:queue_name=default
16Task nameNoThe name of the task executed in the task queue for this request. Only present if the request resulted in the queuing of a task. Example:task_name=7287390692361099748
17Pending queueNoOnly present if a request spent some time in a pending queue. If there are many of these in your logs and/or the values are high, it might be an indication that you need more instances to serve your traffic. Example:pending_ms=195
18Loading requestNoOnly present if the request is a loading request. This means an instance had to be started up. Ideally, your instances should be up and healthy for as long as possible, serving large numbers of requests before being recycled and needing to be started again. Which means you shouldn't see too many of these in your logs. Example:loading_request=1.
19InstanceYesUnique identifier for the instance that handles the request. Example:instance=00c61b117cfeb66f973d7df1b7f4ae1f064d
20VersionYesThe current App Engine release version used in production App Engine:

Quotas and limits

Your application is affected by the followinglogs-related quotas:

  • Logs data retrieved via the Logs API.
  • Log ingestion allotment and retention.

Quota for data retrieved

The first 100 megabytes of logs data retrieved per day via the Logs API callsare free. Data in excess of 100 megabytes results in charges of$0.12/GB.

Logs ingestion allotment

Logging for App Engine apps is provided byGoogle Cloud Observability.SeeGoogle Cloud Observability Pricing formore information on logging costs and limits. For long-term storage of logs, youcanexport logs from Google Cloud Observabilityto Cloud Storage, BigQuery, and Pub/Sub.

The development server and Logs API

Important:

By default, logs are stored in memory only in thedevelopment server and are accessible if you wish to test the Logs API feature. If you wish topersist logs from the development server to disk at a location of your ownchoosing, supply the desired path and filename to the--logs_path command lineoption as follows:

python2[DEVAPPSERVER_ROOT]/google_appengine/dev_appserver.py--logs_path=your-path/your-logfile-nameyour-app-directory

Except as otherwise noted, the content of this page is licensed under theCreative Commons Attribution 4.0 License, and code samples are licensed under theApache 2.0 License. For details, see theGoogle Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.

Last updated 2025-12-15 UTC.