Please note that the contents of this offline web site may be out of date. To access the most recent documentation visit the online version .
Note that links that point to online resources are green in color and will open in a new window.
We would love it if you could give us feedback about this material by filling this form (You have to be online to fill it)



Logs PHP API Overview

  1. Overview
  2. Quotas and limits

Overview

The Logs API provides access to the application and request logs for your application. (You can also access the logs for your application in the UI by clicking Logs in the left navigation pane in the Admin Console .)

The Logs PHP API is invoked whenever the built-in PHP function syslog() is called. For example:

if (authorizedUser()) {
  echo '<p>Welcome authorized user</p>';
  syslog(LOG_INFO, 'Authorized access');
} else {
  echo 'Go away unauthorized user<p />';
  syslog(LOG_WARNING, "Unauthorized access");
}

You do not need to call openlog() or closelog() before writing to syslog . Calls to these functions will be ignored.

Log categories: request logs and app logs

There are two categories of log data: request logs and application logs. A request log is written for each request handled by your app, and contains information such as the app ID, HTTP version, and so forth.

Getting log data

The general process of getting logs is as follows:

  1. Use fetch() to return an iterator for the request logs.
  2. In each iteration, process each RequestLog as desired.
  3. Optionally, use getAppLogs() to get the list of related AppLogs.
  4. If you retrieved the app logs list, for each AppLogLine , process the AppLog property data as desired.

Sample code

The following sample reads request logs between given start and end times and verifies that the given messages and levels are contained sequentially in the app logs. The response will be 'PASS' if all expected messages and levels are matched against app logs.

use google\appengine\api\log\LogService;

// LogService API usage sample to display application logs for last 24 hours.

$options = [
  // Fetch last 24 hours of log data
  'start_time' => (time() - (24 * 60 * 60)) * 1e6,
  // End time is Now
  'end_time' => time() * 1e6,
  // Include all Application Logs (i.e. your debugging output)
  'include_app_logs' => true,
  // Filter out log records based on severity
  'minimum_log_level' => LogService::LEVEL_INFO,
];

$logs = LogService::fetch($options);

foreach ($logs as $log) {
  echo '<ul>REQUEST LOG';
  echo '<li>IP: ', $log->getIp(), '</li>',
         '<li>Status: ', $log->getStatus(), '</li>',
         '<li>Method: ', $log->getMethod(), '</li>',
         '<li>Resource: ', $log->getResource(), '</li>';
  $end_date_time = $log->getEndDateTime();
  echo '<li>Date: ',$end_date_time->format('c'), '</li>';

  $app_logs = $log->getAppLogs();

  foreach ($app_logs as $app_log) {
    echo '<ul>APP LOG';
    echo '<li>Message: ', $app_log->getMessage(), '</li>';
    $app_log_date_time = $app_log->getDateTime();
    echo '<li>Date: ', $app_log_date_time->format('c'), '</li></ul>';
  }
  echo '</ul>';
}

Quotas and limits

Your application is affected by the following logs-related quotas :

  • Logs data retrieved via the Logs API.
  • Log storage, also called logs retention .

Quota for data retrieved

The first 100 megabytes of logs data retrieved per day via the Logs API calls are free. After this amount is exceeded, no further Logs API calls will succeed unless billing is enabled for your app. If billing is enabled for your app, data in excess of 100 megabytes results in charges of $0.12/GB.

Logs storage

You can control how much log data your application stores by means of its log retention settings in the Admin Console . By default, logs are stored for an application free of charge with the following per-application limits: a maximum of 1 gigabyte for a maximum of up to 90 days. If either limit is exceeded, more recent logs will be shown and older logs will be deleted to stay within the size limit. Logs older than the maximum retention time are also deleted.

If your app has billing enabled, you can pay for higher log size limits by specifying the desired maximum log size in gigabytes in the Admin Console . You can also set the retention time by specifying the desired number of days to keep logs, up to a maximum of 365 days. The cost of this extra log storage is $0.026 per gigabyte utilized per month.

Limit Amount Cost past free threshold
Maximum days storage per log 90 days free, 365 days if paid $0.026 per gigabyte utilized per month
Maximum total logs storage 1 gigabyte free, unlimited if paid $0.026 per gigabyte utilized per month

Authentication required

You need to be signed in with Google+ to do that.

Signing you in...

Google Developers needs your permission to do that.