diff options
author | Matthieu Napoli <matthieu@mnapoli.fr> | 2014-12-04 08:40:19 +0300 |
---|---|---|
committer | Matthieu Napoli <matthieu@mnapoli.fr> | 2014-12-04 08:40:19 +0300 |
commit | 7a9f70830a0d32fd56f381aac47d5ed64bf4ed7a (patch) | |
tree | 683d26fe019d33648da733e625eaa89b83bb85d8 /config | |
parent | a59667bf04c670e26c1116985481e688084efc4f (diff) |
#6622 Logger refactoring: moved all the log config to DI config
Diffstat (limited to 'config')
-rw-r--r-- | config/global.php | 33 |
1 files changed, 32 insertions, 1 deletions
diff --git a/config/global.php b/config/global.php index a5e74ea79e..122428a07e 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'), |