Example #1
0
 public function processRecord(array $record)
 {
     $request = $this->requestStack->getCurrentRequest();
     if ($request) {
         $record['http'] = ['url' => sprintf('[%s] [%s]', $request->getMethod(), $request->getRequestUri())];
         if (count($request->query->all())) {
             $record['http']['get'] = $request->query->all();
         }
         if (count($request->request->all())) {
             $record['http']['post'] = $request->request->all();
         }
         $content = $request->getContent();
         if ($content) {
             if (strlen($content) < 1024) {
                 $record['http']['json'] = json_decode($content, true);
             } else {
                 $record['http']['json'] = $this->s3Uploader->uploadString('json-params', $content);
             }
         }
         if (isset($_SERVER['REMOTE_ADDR'])) {
             $record['http']['ip'] = $_SERVER['REMOTE_ADDR'];
         }
         if (isset($_SERVER['HTTP_X_USER_AGENT'])) {
             $record['http']['userAgent'] = $_SERVER['HTTP_X_USER_AGENT'];
         } elseif (isset($_SERVER['HTTP_USER_AGENT'])) {
             $record['http']['userAgent'] = $_SERVER['HTTP_USER_AGENT'];
         }
     }
     if (php_sapi_name() == 'cli') {
         if (!empty($_SERVER['argv'])) {
             $record['cliCommand'] = implode(' ', $_SERVER['argv']);
         }
     }
     return $record;
 }
Example #2
0
 public function processRecord(array $record)
 {
     if (empty($record['component'])) {
         $record['component'] = $this->componentName;
     }
     $record['runId'] = $this->runId;
     $record['pid'] = getmypid();
     $record['priority'] = $record['level_name'];
     if ($this->tokenData) {
         $record['token'] = ['id' => $this->tokenData['id'], 'description' => $this->tokenData['description'], 'owner' => ['id' => $this->tokenData['owner']['id'], 'name' => $this->tokenData['owner']['name']]];
     }
     if (isset($record['context']['exceptionId'])) {
         $record['exceptionId'] = $record['context']['exceptionId'];
     }
     if (isset($record['context']['exception'])) {
         /** @var \Exception $e */
         $e = $record['context']['exception'];
         if ($e instanceof \Exception && !$e instanceof SimpleException) {
             $flattenException = FlattenException::create($e);
             $eHandler = new ExceptionHandler(true);
             $html = $eHandler->getHtml($flattenException);
             $record['exception'] = ['class' => get_class($e), 'message' => $e->getMessage(), 'code' => $e->getCode(), 'attachment' => $this->s3Uploader->uploadString('exception', $html, 'text/html')];
         }
     }
     $json = json_encode($record);
     if (strlen($json) < 1024) {
         return $record;
     } else {
         $record['attachment'] = $this->s3Uploader->uploadString('log', $json, 'application/json');
         if (mb_strlen($record['message']) > 256) {
             $record['message'] = mb_substr($record['message'], 0, 256);
         }
         $allowedFields = ['message', 'component', 'runId', 'pid', 'priority', 'level', 'attachment', 'exception', 'exceptionId', 'token', 'cliCommand', 'http', 'job', 'app'];
         foreach (array_keys($record) as $fieldName) {
             if (!in_array($fieldName, $allowedFields)) {
                 unset($record[$fieldName]);
             }
         }
         if (isset($record['http'])) {
             $allowedFields = ['url', 'userAgent', 'ip'];
             foreach (array_keys($record['http']) as $fieldName) {
                 if (!in_array($fieldName, $allowedFields)) {
                     unset($record['http'][$fieldName]);
                 }
             }
         }
         if (isset($record['job'])) {
             $allowedFields = ['id'];
             foreach (array_keys($record['job']) as $fieldName) {
                 if (!in_array($fieldName, $allowedFields)) {
                     unset($record['job'][$fieldName]);
                 }
             }
         }
         return $record;
     }
 }