Example #1
0
 /**
  * @param CM_Log_Record $record
  * @return array
  */
 protected function _formatRecord(CM_Log_Record $record)
 {
     $levelsMapping = array_flip(CM_Log_Logger::getLevels());
     $context = $record->getContext();
     $result = ['message' => (string) $record->getMessage(), 'level' => strtolower($levelsMapping[$record->getLevel()]), 'timestamp' => $record->getCreatedAt()->format('Y-m-d\\TH:i:s.uO')];
     $result = array_merge($result, $this->_contextFormatter->formatContext($context));
     return $result;
 }
Example #2
0
 /**
  * @param string          $method
  * @param CM_Janus_Server $server
  * @param string          $path
  * @param array|null      $body
  * @return string
  * @throws CM_Exception_Invalid
  */
 protected function _request($method, CM_Janus_Server $server, $path, array $body = null)
 {
     $context = CM_Service_Manager::getInstance()->getLogger()->getContext();
     $appContext = $this->_contextFormatter->formatAppContext($context);
     $url = $server->getHttpAddress() . $path;
     $body = (array) $body;
     $options = ['query' => ['context' => CM_Util::jsonEncode($appContext)], 'body' => $body, 'headers' => ['Server-Key' => $server->getKey()]];
     $request = $this->_httpClient->createRequest($method, $url, $options);
     try {
         $response = $this->_httpClient->send($request);
     } catch (GuzzleHttp\Exception\TransferException $e) {
         throw new CM_Exception_Invalid('Fetching contents from url failed', null, ['url' => $url, 'originalExceptionMessage' => $e->getMessage()]);
     }
     $body = $response->getBody();
     if (null === $body) {
         throw new CM_Exception_Invalid('Empty response body');
     }
     return $body->getContents();
 }