/** * Writes the log record * * @param \TYPO3\CMS\Core\Log\LogRecord $record Log record * * @return WriterInterface $this */ public function writeLog(\TYPO3\CMS\Core\Log\LogRecord $record) { try { $this->storeLog($record->getMessage(), $record->getComponent(), $record->getLevel(), $record->getData()); } catch (\Exception $e) { $this->handleExceptionDuringLogging($e); } return $this; }
/** * @param LogRecord $logRecord * @return LogRecord */ public function processLogRecord(LogRecord $logRecord) { $data = $logRecord->getData(); if (array_key_exists('loggerComponent', $data)) { $logRecord->setComponent($data['loggerComponent']); unset($data['loggerComponent']); } $logRecord->setData($data); return $logRecord; }
/** * Processes a log record and adds memory usage information. * * @param \TYPO3\CMS\Core\Log\LogRecord $logRecord The log record to process * @return \TYPO3\CMS\Core\Log\LogRecord The processed log record with additional data * @see memory_get_usage() */ public function processLogRecord(\TYPO3\CMS\Core\Log\LogRecord $logRecord) { $bytes = memory_get_usage($this->getRealMemoryUsage()); if ($this->formatSize) { $size = \TYPO3\CMS\Core\Utility\GeneralUtility::formatSize($bytes); } else { $size = $bytes; } $logRecord->addData(array('memoryUsage' => $size)); return $logRecord; }
/** * Formats the log * * @param \TYPO3\CMS\Core\Log\LogRecord $logRecord * @return \TYPO3\CMS\Core\Log\LogRecord */ public function processLogRecord(\TYPO3\CMS\Core\Log\LogRecord $logRecord) { $message = $logRecord->getMessage(); foreach ($this->formatTokens as $token => $formattingMethod) { if (substr($message, 0, strlen($token)) == $token) { $message = substr($message, strlen($token)); $message = $this->{$formattingMethod}(trim($message)); } } $logRecord->setMessage($message); return $logRecord; }
/** * Add debug backtrace information to logRecord * It adds: filepath, line number, class and function name * * @param LogRecord $logRecord The log record to process * @return LogRecord The processed log record with additional data * @see debug_backtrace() */ public function processLogRecord(LogRecord $logRecord) { $trace = $this->getDebugBacktrace(); // skip TYPO3\CMS\Core\Log classes foreach ($trace as $traceEntry) { if (isset($traceEntry['class']) && false !== strpos($traceEntry['class'], 'TYPO3\\CMS\\Core\\Log')) { $trace = $this->shiftBacktraceLevel($trace); } else { break; } } // shift a given number of entries from the trace for ($i = 0; $i < $this->shiftBackTraceLevel; $i++) { // shift only if afterwards there is at least one entry left after. if (count($trace) > 1) { $trace = $this->shiftBacktraceLevel($trace); } } if ($this->appendFullBackTrace) { // Add the line and file of the last entry that has these information // to the first backtrace entry if it does not have this information. // This is required in case we have shifted entries and the first entry // is now a call_user_func that does not contain the line and file information. if (!isset($trace[0]['line'])) { $trace[0] = ['line' => $this->precedingBacktraceLine] + $trace[0]; } if (!isset($trace[0]['file'])) { $trace[0] = ['file' => $this->precedingBacktraceFile] + $trace[0]; } $logRecord->addData(['backtrace' => $trace]); } else { $logRecord->addData(['file' => isset($trace[0]['file']) ? $trace[0]['file'] : null, 'line' => isset($trace[0]['line']) ? $trace[0]['line'] : null, 'class' => isset($trace[0]['class']) ? $trace[0]['class'] : null, 'function' => isset($trace[0]['function']) ? $trace[0]['function'] : null]); } return $logRecord; }
/** * Add debug backtrace information to logRecord * It adds: filepath, line number, class and function name * * @param \TYPO3\CMS\Core\Log\LogRecord $logRecord The log record to process * @return \TYPO3\CMS\Core\Log\LogRecord The processed log record with additional data * @see debug_backtrace() */ public function processLogRecord(\TYPO3\CMS\Core\Log\LogRecord $logRecord) { $trace = debug_backtrace(); // skip first since it's always the current method array_shift($trace); // the call_user_func call is also skipped array_shift($trace); // skip TYPO3\CMS\Core\Log classes // @TODO: Check, if this still works. This was 't3lib_log_' before namespace switch. $i = 0; while (isset($trace[$i]['class']) && FALSE !== strpos($trace[$i]['class'], 'TYPO3\\CMS\\Core\\Log')) { $i++; } // we should have the call source now $logRecord->addData(array('file' => isset($trace[$i]['file']) ? $trace[$i]['file'] : NULL, 'line' => isset($trace[$i]['line']) ? $trace[$i]['line'] : NULL, 'class' => isset($trace[$i]['class']) ? $trace[$i]['class'] : NULL, 'function' => isset($trace[$i]['function']) ? $trace[$i]['function'] : NULL)); return $logRecord; }
/** * Writes the log record * * @param \TYPO3\CMS\Core\Log\LogRecord $record Log record * @return \TYPO3\CMS\Core\Log\Writer\WriterInterface $this * @throws \RuntimeException */ public function writeLog(\TYPO3\CMS\Core\Log\LogRecord $record) { $levelName = \TYPO3\CMS\Core\Log\LogLevel::getName($record->getLevel()); $data = $record->getData(); $data = !empty($data) ? '- ' . json_encode($data) : ''; $message = sprintf('TYPO3 [%s] request="%s" component="%s": %s %s', $levelName, $record->getRequestId(), $record->getComponent(), $record->getMessage(), $data); if (FALSE === error_log($message)) { throw new \RuntimeException('Could not write log record to PHP error log', 1345036336); } return $this; }
/** * 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; }
/** * Writes the log record * * @param LogRecord $record Log record * @return \TYPO3\CMS\Core\Log\Writer\WriterInterface $this * @throws \RuntimeException */ public function writeLog(LogRecord $record) { $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 = '- ' . json_encode($recordData); } $message = sprintf('TYPO3 [%s] request="%s" component="%s": %s %s', $levelName, $record->getRequestId(), $record->getComponent(), $record->getMessage(), $data); if (FALSE === error_log($message)) { throw new \RuntimeException('Could not write log record to PHP error log', 1345036336); } return $this; }
/** * Writes the log record * * @param \TYPO3\CMS\Core\Log\LogRecord $record Log record * * @return WriterInterface $this */ public function writeLog(\TYPO3\CMS\Core\Log\LogRecord $record) { $config = \DMK\Mklog\Factory::getConfigUtility(); // check min log level if (!$config->getGelfEnable() || !$config->getGelfCredentials() || $record->getLevel() > $config->getGelfMinLogLevel()) { return $this; } $options = \tx_rnbase::makeInstance('Tx_Rnbase_Domain_Model_Data', array('credentials' => $config->getGelfCredentials())); $transport = $this->getTransport(); $transport->initialize($options); $message = $this->createDevlogEntry($record->getMessage(), $record->getComponent(), $record->getLevel(), $record->getData()); try { $transport->publish($message); } catch (\Exception $e) { // what todo on transport exception? // usualy we have a emergency and a other logger (file or mail) shold take over return $this; } $transport->shutdown(); return $this; }
/** * Passes the \TYPO3\CMS\Core\Log\LogRecord to all registered writers. * * @param \TYPO3\CMS\Core\Log\LogRecord $record * @return void */ protected function writeLog(\TYPO3\CMS\Core\Log\LogRecord $record) { if (!empty($this->writers[$record->getLevel()])) { foreach ($this->writers[$record->getLevel()] as $writer) { $writer->writeLog($record); } } }
/** * Writes the log record * * @param \TYPO3\CMS\Core\Log\LogRecord $record Log record * @return \TYPO3\CMS\Core\Log\Writer\WriterInterface $this * @throws \Exception */ public function writeLog(\TYPO3\CMS\Core\Log\LogRecord $record) { $this->output->write($this->wrapMessage(vsprintf($record->getMessage(), $record->getData()), $record->getLevel()), TRUE); }
/** * Writes the log record to syslog * * @param LogRecord $record Log record * @return \TYPO3\CMS\Core\Log\Writer\WriterInterface * @throws \RuntimeException */ public function writeLog(LogRecord $record) { if (FALSE === syslog($record->getLevel(), $this->getMessageForSyslog($record))) { throw new \RuntimeException('Could not write log record to syslog', 1345036337); } return $this; }
/** * @return string */ protected function getNamespaceOfLogComponent() { $componentParts = explode('.', $this->logRecord->getComponent()); return $componentParts[1]; }
/** * Processes a log record and adds webserver environment data. * We use the usual "Debug System Information" * * @param \TYPO3\CMS\Core\Log\LogRecord $logRecord The log record to process * @return \TYPO3\CMS\Core\Log\LogRecord The processed log record with additional data * @see \TYPO3\CMS\Core\Utility\GeneralUtility::getIndpEnv() */ public function processLogRecord(\TYPO3\CMS\Core\Log\LogRecord $logRecord) { $logRecord->addData(\TYPO3\CMS\Core\Utility\GeneralUtility::getIndpEnv('_ARRAY')); return $logRecord; }
/** * @test * @param \TYPO3\CMS\Core\Log\LogRecord $record Record Test Data * @dataProvider writerLogsToDatabaseDataProvider */ public function writerLogsToDatabase(\TYPO3\CMS\Core\Log\LogRecord $record) { $logger = $this->createLogger(); $databaseWriter = $this->createWriter(); $logger->addWriter(\TYPO3\CMS\Core\Log\LogLevel::NOTICE, $databaseWriter); $this->databaseStub->expects($this->once())->method('exec_INSERTquery'); $logger->log($record->getLevel(), $record->getMessage()); }