Пример #1
0
 /**
  * @internal
  *
  * @param LogReadRequest $request The underlying protocol buffer.
  */
 public function __construct(\google\appengine\LogReadRequest $request)
 {
     $this->request = $request;
     // Remember start position to allow rewind() to return.
     if ($request->hasOffset()) {
         $this->origin = $request->getOffset();
     }
 }
Пример #2
0
 /**
  * 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
  * <code>$request_ids</code>.
  *
  * @param mixed $request_ids A string request id or an array of string request
  * ids obtained from <code>RequestLog::getRequestId()</code>.
  * @param boolean $include_app_logs Should applicaiton logs be included in the
  * fetched request logs. Defaults to true - application logs are included.
  *
  * @return RequestLog[] The request logs for ids that were found.
  */
 public static function fetchById($request_ids, $include_app_logs = true)
 {
     $request = new LogReadRequest();
     $request->setAppId(getenv('APPLICATION_ID'));
     if (!is_bool($include_app_logs)) {
         throw new \InvalidArgumentException('Parameter $include_app_logs must be boolean but was ' . typeOrClass($include_app_logs));
     }
     $request->setIncludeAppLogs($include_app_logs);
     self::setDefaultModuleVersion($request);
     if (is_string($request_ids)) {
         if (!preg_match(self::$REQUEST_ID_REGEX, $request_ids)) {
             throw new \InvalidArgumentException("Invalid request id " . htmlspecialchars($request_ids));
         }
         $request->addRequestId($request_ids);
     } else {
         if (is_array($request_ids)) {
             foreach ($request_ids as $id) {
                 if (!is_string($id)) {
                     throw new \InvalidArgumentException('Request id must be a string but was ' . self::typeOrClass($id));
                 }
                 if (!preg_match(self::$REQUEST_ID_REGEX, $id)) {
                     throw new \InvalidArgumentException("Invalid request id " . htmlspecialchars($id));
                 }
                 $request->addRequestId($id);
             }
         } else {
             throw new \InvalidArgumentException('Expected a string or an array of strings but was ' . self::typeOrClass($value));
         }
     }
     $response = self::readLogs($request);
     $result = [];
     foreach ($response->getLogList() as $log) {
         $result[] = new RequestLog($log);
     }
     return $result;
 }
Пример #3
0
 public function testFetchByIdsWithAppLogs()
 {
     $ids = [];
     $request = new LogReadRequest();
     $request->setAppId(self::APPLICATION_ID);
     $request->setIncludeAppLogs(true);
     $request->addModuleVersion()->setVersionId(self::MAJOR_VERSION);
     $response = new LogReadResponse();
     for ($i = 0; $i < 5; $i++) {
         $ids[] = sprintf('%d', $i);
         $request->addRequestId(sprintf('%d', $i));
         $this->populateLogPb($response->addLog(), $i);
     }
     $this->apiProxyMock->expectCall(self::RPC_PACKAGE, self::RPC_READ_METHOD, $request, $response);
     $index = 0;
     foreach (LogService::fetchById($ids, true) as $log) {
         $this->checkRequestLog($log, $index);
         $index++;
     }
     $this->assertEquals(5, $index);
     $this->apiProxyMock->verify();
 }