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; }
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'], 'token' => $this->tokenData['token'], '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) { $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, 'text/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; } }
/** * @covers \Keboola\Syrup\Aws\S3\Uploader::getClient * @covers \Keboola\Syrup\Aws\S3\Uploader::uploadString * @covers \Keboola\Syrup\Aws\S3\Uploader::uploadFile */ public function testS3Uploader() { $s3Uploader = new Uploader(['aws-access-key' => SYRUP_AWS_KEY, 'aws-secret-key' => SYRUP_AWS_SECRET, 'aws-region' => SYRUP_AWS_REGION, 's3-upload-path' => SYRUP_S3_BUCKET]); $fileName = uniqid(); $resultUrl = $s3Uploader->uploadString($fileName, uniqid()); $this->assertStringStartsWith('https://connection.keboola.com/admin/utils/logs?file=', $resultUrl); $this->assertStringEndsWith($fileName, $resultUrl); $temp = new Temp(); $fileInfo = $temp->createTmpFile(); $file = $fileInfo->openFile('a'); $file->fwrite(uniqid()); $resultUrl = $s3Uploader->uploadFile($fileInfo->getRealPath()); $this->assertStringStartsWith('https://connection.keboola.com/admin/utils/logs?file=', $resultUrl); $this->assertStringEndsWith($fileInfo->getFilename(), $resultUrl); }