/** * @param array $record The Logging Record * @return array */ public function __invoke(array $record) { /** * Look for #TRACE#({.*}) in log messages * if found, record, and clean out of original log message */ preg_match('/#TRACE#({.*})/', $record['message'], $match); if ($match) { $record['extra'] += json_decode($match[1], true); $record['message'] = trim(preg_replace("/{$match[0]}/", '', $record['message'])); } $record['extra']['token'] = $this->requestTrace->getTraceId(); $record['extra']['inboundToken'] = $this->requestTrace->getInboundTraceChain(); $record['extra']['time'] = microtime(true); return $record; }
/** * Logs a response. * * @param Response $response */ protected function logResponse(Response $response) { $response->headers->set('trace-token', TracingRequest::getInstance()->getTraceId()); if ($response instanceof RedirectResponse) { $this->logger->info('< ' . $response->getStatusCode() . ' ' . $response->getTargetUrl()); } else { $this->logger->info('HTTP response: ' . $response->getStatusCode() . ' #TRACE#{"event":"response.send"}'); } }