Skip to content

Commit

Permalink
#6622 Logger refactoring: lazily create log writers
Browse files Browse the repository at this point in the history
  • Loading branch information
mnapoli committed Dec 1, 2014
1 parent 20e84e7 commit 0f435ee
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions core/Log/LoggerFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ private static function getLogWriters($logConfig, ContainerInterface $container)
return array();
}

$availableWriters = self::getAvailableWriters($container);
$availableWriters = self::getAvailableWriters();

$writerNames = array_map('trim', $writerNames);
$writers = array();
Expand All @@ -70,7 +70,12 @@ private static function getLogWriters($logConfig, ContainerInterface $container)
continue;
}

$writers[$writerName] = $availableWriters[$writerName];
$writer = $availableWriters[$writerName];
if (is_string($writer)) {
$writer = $container->get($writer);
}

$writers[$writerName] = $writer;
}

// Always add the stderr backend
Expand Down Expand Up @@ -114,7 +119,7 @@ private static function getLogLevelFromStringName($name)
}
}

private static function getAvailableWriters(ContainerInterface $container)
private static function getAvailableWriters()
{
$writers = array();

Expand Down Expand Up @@ -146,9 +151,9 @@ private static function getAvailableWriters(ContainerInterface $container)
*/
Piwik::postEvent(Log::GET_AVAILABLE_WRITERS_EVENT, array(&$writers));

$writers['file'] = $container->get('Piwik\Log\Backend\FileBackend');
$writers['screen'] = $container->get('Piwik\Log\Backend\StdOutBackend');
$writers['database'] = $container->get('Piwik\Log\Backend\DatabaseBackend');
$writers['file'] = 'Piwik\Log\Backend\FileBackend';
$writers['screen'] = 'Piwik\Log\Backend\StdOutBackend';
$writers['database'] = 'Piwik\Log\Backend\DatabaseBackend';

return $writers;
}
Expand Down

0 comments on commit 0f435ee

Please sign in to comment.