Skip to content

Commit

Permalink
feat: add request and source location
Browse files Browse the repository at this point in the history
Signed-off-by: Andrii Nasinnyk <anasinnyk@macpaw.com>
  • Loading branch information
anasinnyk committed Jun 26, 2020
1 parent 85d0e60 commit d6f2dd3
Showing 1 changed file with 23 additions and 11 deletions.
34 changes: 23 additions & 11 deletions src/GkeFormatter.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,24 +10,28 @@ class GkeFormatter extends JsonFormatter
public function format(array $record): string
{
$request = ServerRequest::fromGlobals();
$debug = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS,5);

return parent::format(
array_merge(
$record['extra'],
isset($record['context']) && isset($record['context']['exception'])
isset($debug[3])
? [
'sourceLocation' => [
'file' => str_split(':', $record['context']['exception']['file'])[0],
'line' => str_split(':', $record['context']['exception']['file'])[1]
]
'sourceLocation' => [
'file' => $debug[3]['file'],
'line' => $debug[3]['line'],
'function' => isset($debug[4]) && isset($debug[4]['class']) && isset($debug[4]['function'])
? sprintf("%s:%s", $debug[4]['class'], $debug[4]['function'])
: (
isset($debug[4]) && isset($debug[4]['function'])
? $debug[4]['function']
: ''
),
]
]
: [],
[
'message' => $record['message'],
'thread' => $record['channel'],
'severity' => $record['level_name'],
'serviceContext' => $record['context'],
'timestamp' => $record['datetime']->getTimestamp(),
preg_match('/cgi/', php_sapi_name())
? [
'httpRequest' => [
'requestMethod' => $request->getMethod(),
'requestUrl' => $request->getUri()->__toString(),
Expand All @@ -38,6 +42,14 @@ public function format(array $record): string
'remoteIp' => $request->getHeaderLine('X-Forwarded-For'),
],
]
: [],
[
'message' => $record['message'],
'thread' => $record['channel'],
'severity' => $record['level_name'],
'serviceContext' => $record['context'],
'timestamp' => $record['datetime']->getTimestamp(),
]
)
);
}
Expand Down

0 comments on commit d6f2dd3

Please sign in to comment.