diff --git a/config/global.php b/config/global.php index a5e74ea79e8b3ebcb3e26cac2f512df753118518..122428a07e91dc4c10e549393118376b513592de 100644 --- a/config/global.php +++ b/config/global.php @@ -3,6 +3,7 @@ use Interop\Container\ContainerInterface; use Piwik\Common; use Piwik\Log; +use Piwik\Log\Backend\StdErrBackend; use Piwik\Log\Formatter\AddRequestIdFormatter; use Piwik\Log\Formatter\ErrorHtmlFormatter; use Piwik\Log\Formatter\ErrorTextFormatter; @@ -30,7 +31,8 @@ return array( }), // Log - 'Piwik\Log' => DI\factory(array('Piwik\Log\LoggerFactory', 'createLogger')), + 'Piwik\Log' => DI\object() + ->constructor(DI\link('log.handlers'), DI\link('log.level.piwik'), DI\link('log.processors')), 'log.level.monolog' => DI\factory(function (ContainerInterface $c) { return Log::getMonologLevel($c->get('log.level.piwik')); }), @@ -57,6 +59,35 @@ return array( } return false; }), + 'log.handlers' => DI\factory(function (ContainerInterface $c) { + if ($c->has('old_config.log.log_writers')) { + $writerNames = $c->get('old_config.log.log_writers'); + } + if (empty($writerNames)) { + return array(); + } + + $classes = array( + 'file' => 'Piwik\Log\Backend\FileBackend', + 'screen' => 'Piwik\Log\Backend\StdOutBackend', + 'database' => 'Piwik\Log\Backend\DatabaseBackend', + ); + + $writerNames = array_map('trim', $writerNames); + $writers = array(); + foreach ($writerNames as $writerName) { + if (isset($classes[$writerName])) { + $class = $classes[$writerName]; + $writers[$writerName] = $c->get($class); + } + } + + // Always add the stderr backend + $isLoggingToStdOut = isset($writers['screen']); + $writers['stderr'] = new StdErrBackend($c->get('log.formatter.html'), $isLoggingToStdOut); + + return $writers; + }), 'log.processors' => array( DI\link('Piwik\Log\Processor\ClassNameProcessor'), DI\link('Piwik\Log\Processor\SprintfProcessor'), diff --git a/core/Log/LoggerFactory.php b/core/Log/LoggerFactory.php deleted file mode 100644 index fe783cb42c94feaa636865030ad8e1c59f5fe475..0000000000000000000000000000000000000000 --- a/core/Log/LoggerFactory.php +++ /dev/null @@ -1,63 +0,0 @@ -<?php -/** - * Piwik - free/libre analytics platform - * - * @link http://piwik.org - * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later - */ - -namespace Piwik\Log; - -use Interop\Container\ContainerInterface; -use Piwik\Config; -use Piwik\Log; -use Piwik\Log\Backend\StdErrBackend; - -class LoggerFactory -{ - /** - * @param ContainerInterface $container - * @return Log - */ - public static function createLogger(ContainerInterface $container) - { - $logConfig = Config::getInstance()->log; - - $logLevel = $container->get('log.level.piwik'); - $writers = self::getLogWriters($logConfig, $container); - $processors = $container->get('log.processors'); - - return new Log($writers, $logLevel, $processors); - } - - private static function getLogWriters($logConfig, ContainerInterface $container) - { - $writerNames = @$logConfig[Log::LOG_WRITERS_CONFIG_OPTION]; - - if (empty($writerNames)) { - return array(); - } - - $classes = array( - 'file' => 'Piwik\Log\Backend\FileBackend', - 'screen' => 'Piwik\Log\Backend\StdOutBackend', - 'database' => 'Piwik\Log\Backend\DatabaseBackend', - ); - - $writerNames = array_map('trim', $writerNames); - $writers = array(); - - foreach ($writerNames as $writerName) { - if (isset($classes[$writerName])) { - $class = $classes[$writerName]; - $writers[$writerName] = $container->get($class); - } - } - - // Always add the stderr backend - $isLoggingToStdOut = isset($writers['screen']); - $writers['stderr'] = new StdErrBackend($container->get('log.formatter.html'), $isLoggingToStdOut); - - return $writers; - } -}