TYPO3 CMS  TYPO3_6-2
LogManager.php
Go to the documentation of this file.
1 <?php
2 namespace TYPO3\CMS\Core\Log;
3 
26 
30  const CONFIGURATION_TYPE_WRITER = 'writer';
34  const CONFIGURATION_TYPE_PROCESSOR = 'processor';
40  protected $loggers = array();
41 
47  protected $rootLogger = NULL;
48 
52  public function __construct() {
53  $this->rootLogger = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Log\\Logger', '');
54  $this->loggers[''] = $this->rootLogger;
55  }
56 
62  public function reset() {
63  $this->loggers = array();
64  }
65 
78  public function getLogger($name = '') {
80  $logger = NULL;
81  // Transform namespaces and underscore class names to the dot-name style
82  $separators = array('_', '\\');
83  $name = str_replace($separators, '.', $name);
84  if (isset($this->loggers[$name])) {
85  $logger = $this->loggers[$name];
86  } else {
87  // Lazy instantiation
89  $logger = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Log\\Logger', $name);
90  $this->loggers[$name] = $logger;
91  $this->setWritersForLogger($logger);
92  $this->setProcessorsForLogger($logger);
93  }
94  return $logger;
95  }
96 
103  public function registerLogger($name) {
104  $this->loggers[$name] = NULL;
105  }
106 
112  public function getLoggerNames() {
113  return array_keys($this->loggers);
114  }
115 
123  protected function setWritersForLogger(\TYPO3\CMS\Core\Log\Logger $logger) {
124  $configuration = $this->getConfigurationForLogger(self::CONFIGURATION_TYPE_WRITER, $logger->getName());
125  foreach ($configuration as $severityLevel => $writer) {
126  foreach ($writer as $logWriterClassName => $logWriterOptions) {
128  $logWriter = NULL;
129  try {
130  $logWriter = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance($logWriterClassName, $logWriterOptions);
131  $logger->addWriter($severityLevel, $logWriter);
132  } catch (\RangeException $e) {
133  $logger->warning('Instantiation of LogWriter "' . $logWriterClassName . '" failed for logger ' . $logger->getName() . ' (' . $e->getMessage() . ')');
134  }
135  }
136  }
137  }
138 
146  protected function setProcessorsForLogger(\TYPO3\CMS\Core\Log\Logger $logger) {
147  $configuration = $this->getConfigurationForLogger(self::CONFIGURATION_TYPE_PROCESSOR, $logger->getName());
148  foreach ($configuration as $severityLevel => $processor) {
149  foreach ($processor as $logProcessorClassName => $logProcessorOptions) {
151  $logProcessor = NULL;
152  try {
153  $logProcessor = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance($logProcessorClassName, $logProcessorOptions);
154  $logger->addProcessor($severityLevel, $logProcessor);
155  } catch (\RangeException $e) {
156  $logger->warning('Instantiation of LogProcessor "' . $logProcessorClassName . '" failed for logger ' . $logger->getName() . ' (' . $e->getMessage() . ')');
157  }
158  }
159  }
160  }
161 
171  protected function getConfigurationForLogger($configurationType, $loggerName) {
172  // Split up the logger name (dot-separated) into its parts
173  $explodedName = explode('.', $loggerName);
174  // Search in the $TYPO3_CONF_VARS['LOG'] array
175  // for these keys, for example "writerConfiguration"
176  $configurationKey = $configurationType . 'Configuration';
177  $configuration = $GLOBALS['TYPO3_CONF_VARS']['LOG'];
178  $result = $configuration[$configurationKey] ?: array();
179  // Walk from general to special (t3lib, t3lib.db, t3lib.db.foo)
180  // and search for the most specific configuration
181  foreach ($explodedName as $partOfClassName) {
182  if (!empty($configuration[$partOfClassName][$configurationKey])) {
183  $result = $configuration[$partOfClassName][$configurationKey];
184  }
185  $configuration = $configuration[$partOfClassName];
186  }
187  // Validate the config
188  foreach ($result as $level => $unused) {
189  try {
191  } catch (\RangeException $e) {
192  throw new \RangeException('The given severity level "' . htmlspecialchars($level) . '" for ' . $configurationKey . ' of logger "' . $loggerName . '" is not valid.', 1326406447);
193  }
194  }
195  return $result;
196  }
197 
198 }
static validateLevel($level)
Definition: LogLevel.php:134
if($list_of_literals) if(!empty($literals)) if(!empty($literals)) $result
Analyse literals to prepend the N char to them if their contents aren&#39;t numeric.
if(!defined('TYPO3_MODE')) $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_userauth.php']['logoff_pre_processing'][]
getConfigurationForLogger($configurationType, $loggerName)
Definition: LogManager.php:171