Esempio n. 1
0
 /**
  * Returns the configuration from $TYPO3_CONF_VARS['LOG'] as
  * hierarchical array for different components of the class hierarchy.
  *
  * @param string $configurationType Type of config to return (writer, processor)
  * @param string $loggerName Logger name
  * @throws \Psr\Log\InvalidArgumentException
  * @return array
  */
 protected function getConfigurationForLogger($configurationType, $loggerName)
 {
     // Split up the logger name (dot-separated) into its parts
     $explodedName = explode('.', $loggerName);
     // Search in the $TYPO3_CONF_VARS['LOG'] array
     // for these keys, for example "writerConfiguration"
     $configurationKey = $configurationType . 'Configuration';
     $configuration = $GLOBALS['TYPO3_CONF_VARS']['LOG'];
     $result = $configuration[$configurationKey] ?: array();
     // Walk from general to special (t3lib, t3lib.db, t3lib.db.foo)
     // and search for the most specific configuration
     foreach ($explodedName as $partOfClassName) {
         if (!empty($configuration[$partOfClassName][$configurationKey])) {
             $result = $configuration[$partOfClassName][$configurationKey];
         }
         $configuration = $configuration[$partOfClassName];
     }
     // Validate the config
     foreach ($result as $level => $unused) {
         try {
             LogLevel::validateLevel($level);
         } catch (\Psr\Log\InvalidArgumentException $e) {
             throw new \Psr\Log\InvalidArgumentException('The given severity level "' . htmlspecialchars($level) . '" for ' . $configurationKey . ' of logger "' . $loggerName . '" is not valid.', 1326406447);
         }
     }
     return $result;
 }
Esempio n. 2
0
 /**
  * Adds a log record.
  *
  * @param int|string $level Log level. Value according to \TYPO3\CMS\Core\Log\LogLevel. Alternatively accepts a string.
  * @param string $message Log message.
  * @param array $data Additional data to log
  * @return mixed
  */
 public function log($level, $message, array $data = array())
 {
     $level = LogLevel::normalizeLevel($level);
     LogLevel::validateLevel($level);
     if ($level > $this->minimumLogLevel) {
         return $this;
     }
     /** @var $record \TYPO3\CMS\Core\Log\LogRecord */
     $record = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(LogRecord::class, $this->name, $level, $message, $data);
     $record = $this->callProcessors($record);
     $this->writeLog($record);
     return $this;
 }