/** * Writes the log record * * @param LogRecord $record Log record * @return \TYPO3\CMS\Core\Log\Writer\WriterInterface $this * @throws \RuntimeException */ public function writeLog(LogRecord $record) { $data = ''; $recordData = $record->getData(); if (!empty($recordData)) { // According to PSR3 the exception-key may hold an \Exception // Since json_encode() does not encode an exception, we run the _toString() here if (isset($recordData['exception']) && $recordData['exception'] instanceof \Exception) { $recordData['exception'] = (string) $recordData['exception']; } $data = '- ' . json_encode($recordData); } $fieldValues = array('request_id' => $record->getRequestId(), 'time_micro' => $record->getCreated(), 'component' => $record->getComponent(), 'level' => $record->getLevel(), 'message' => $record->getMessage(), 'data' => $data); if (false === $this->getDatabaseConnection()->exec_INSERTquery($this->logTable, $fieldValues)) { throw new \RuntimeException('Could not write log record to database', 1345036334); } return $this; }
/** * Writes the log record * * @param LogRecord $record Log record * @return WriterInterface $this * @throws \RuntimeException */ public function writeLog(LogRecord $record) { $timestamp = date('r', (int) $record->getCreated()); $levelName = LogLevel::getName($record->getLevel()); $data = ''; $recordData = $record->getData(); if (!empty($recordData)) { // According to PSR3 the exception-key may hold an \Exception // Since json_encode() does not encode an exception, we run the _toString() here if (isset($recordData['exception']) && $recordData['exception'] instanceof \Exception) { $recordData['exception'] = (string) $recordData['exception']; } $data = '- ' . print_r($recordData, true); } $message = sprintf('%s [%s] request="%s" component="%s": %s %s', $timestamp, $levelName, $record->getRequestId(), $record->getComponent(), $record->getMessage(), $data); if (false === fwrite(self::$logFileHandles[$this->logFile], $message . LF)) { throw new \RuntimeException('Could not write log record to log file', 1345036335); } return $this; }