\google\appengine\api\log\LogService

FINAL

The LogService allows an application to query for request and application logs. Application logs are added to a the current request log by calling {@link http://php.net/manual/en/function.syslog.php syslog(int $priority, string $message)}. The $priority used when creating the application log is translated into a different scale of severity used by the LogService based on the following mappings,

  • LOG_DEBUG => LogService::LEVEL_DEBUG
  • LOG_INFO => LogService::LEVEL_INFO
  • LOG_NOTICE => LogService::LEVEL_INFO
  • LOG_WARNING => LogService::LEVEL_WARNING
  • LOG_ERR => LogService::LEVEL_ERROR
  • LOG_CRIT => LogService::LEVEL_CRITICAL
  • LOG_ALERT => LogService::LEVEL_CRITICAL
  • LOG_EMERG => LogService::LEVEL_CRITICAL

When fetching application logs or filtering request logs by severity use the LogService's severity levels.

Uses traits

\google\appengine\api\log\ApiProxyAccess

Constants

LEVEL_DEBUG

Constants for application log levels.

LEVEL_INFO

LEVEL_WARNING

LEVEL_ERROR

LEVEL_CRITICAL

MAX_BATCH_SIZE

The maximum number of request logs returned in each batch.

Methods

fetch

STATIC   

fetch(array $options = array()) : \google\appengine\api\log\Iterator

Get request logs matching the given options in reverse chronological order of request end time.

Parameters

Name Description

$options

array

Optional associateive arrary of filters and modifiers from following:

  • 'start_time': DateTime or numeric The earliest completion time or last-update time for request logs. If the value is numeric it represents microseconds since Unix epoch.
  • 'end_time': DateTime or numeric The latest completion time or last-update time for request logs. If the value is numeric it represents microseconds since Unix epoch.
  • 'offset': string The url-safe offset value from a RequestLog to continue iterating after.
  • 'minimum_log_level': integer Only return request logs containing at least one application log of this severity or higher. Works even if include_app_logs is not true
  • 'include_incomplete': boolean Should incomplete request logs be included. The default is false - only completed logs are returned
  • 'include_app_logs': boolean Should application logs be returned. The default is false - application logs are not returned with their containing request logs.
  • 'versions': array The versions of the default module for which to fetch request logs. Only one of 'versions' and 'module_versions' can be used.
  • 'module_versions': arrary An associative array of module names to versions for which to fetch request logs. Each module name may be mapped to either a single string version or an array of versions.
  • 'batch_size': integer The number of request logs to pre-fetch while iterating.

Returns

\google\appengine\api\log\Iterator

The matching RequestLog items.

fetchById

STATIC   

fetchById(mixed $request_ids, boolean $include_app_logs = true) : array<mixed,\google\appengine\api\log\RequestLog>

Get request logs for the given request log ids and optionally include the application logs addded during each request. Request log ids that are not found are ignored so the returned array may have fewer items than $request_ids.

Parameters

Name Description

$request_ids

mixed

A string request id or an array of string request ids obtained from RequestLog::getRequestId().

$include_app_logs

boolean

Should applicaiton logs be included in the fetched request logs. Defaults to true - application logs are included.

Returns

array<mixed,\google\appengine\api\log\RequestLog>

The request logs for ids that were found.

log

STATIC   

log(integer $severity, string $message)

Add an app log at a particular Google App Engine severity level.

Parameters

Name Description

$severity

integer

The Google App Engine severity level for the log.

$message

string

The message to log.

flush

STATIC   

flush()

Write all buffered log messages to the log storage. Logs may not be immediately available to read.

setAutoFlushEntries

STATIC   

setAutoFlushEntries(integer $entries)

Set the maximum number of log entries to buffer before they are automaticallly flushed upon adding the next log entry.

Parameters

Name Description

$entries

integer

Number of log entries to buffer.

setAutoFlushBytes

STATIC   

setAutoFlushBytes(integer $bytes)

Sets the maximum size of logs to buffer before they are automaticallly flushed upon adding the next log entry.

Parameters

Name Description

$bytes

integer

Size of logs to buffer in bytes.

setLogFlushTimeLimit

STATIC   

setLogFlushTimeLimit(integer $seconds)

Sets the maximum amount of time in seconds before the buffered logs are automatically flushed upon adding the next log entry.

Parameters

Name Description

$seconds

integer

Time in seconds. Use zero or negative value to disable the time limit.

getAppEngineLogLevel

STATIC   

getAppEngineLogLevel(integer $syslog_level) : integer

Translates a PHP syslog priority level into a Google App Engine severity level. Useful when filtering logs by minimum severity level given the syslog level.

Parameters

Name Description

$syslog_level

integer

The priority level passed to syslog.

Returns

integer

The app engine severity level.