Permalink
Browse files

Compiler added

add costum appenders
  • Loading branch information...
1 parent 4fc6d75 commit 10028849ff9dc16225714728a006afb485d2e82e Florian Semm committed Nov 25, 2011
Showing with 50 additions and 9 deletions.
  1. +2 −2 DependencyInjection/FSLog4PhpExtension.php
  2. +10 −2 FSLog4PhpBundle.php
  3. +31 −1 Logger.php
  4. +7 −4 Resources/config/services.yml
@@ -23,9 +23,9 @@ public function load(array $configs, ContainerBuilder $container) {
$config = $processor->process($configuration->getConfigTreeBuilder(), $configs);
- $container->getDefinition('php4log.logger')->addMethodCall('configureLogger', array($config));
+ $container->getDefinition('log4php.logger')->addMethodCall('configureLogger', array($config));
- $container->setAlias('logger', 'php4log.logger');
+ $container->setAlias('logger', 'log4php.logger');
}
View
@@ -2,14 +2,22 @@
namespace FS\Log4PhpBundle;
-use Symfony\Component\HttpKernel\Bundle\Bundle;
+use Symfony\Component\DependencyInjection\Compiler\PassConfig;
+
+use FS\Log4PhpBundle\DependencyInjection\Compiler\RegisterAppenderPass;
+use Symfony\Component\HttpKernel\Bundle\Bundle;
+use Symfony\Component\DependencyInjection\ContainerBuilder;
/**
*
* @author Florian Semm
*/
class FSLog4PhpBundle extends Bundle {
-
+ public function build(ContainerBuilder $container) {
+ parent::build($container);
+
+ $container->addCompilerPass(new RegisterAppenderPass(), PassConfig::TYPE_BEFORE_OPTIMIZATION);
+ }
}
?>
View
@@ -22,12 +22,23 @@ class Logger implements LoggerInterface {
*/
private $messages = array();
+ private $container;
+
+ public function __construct($container) {
+ $this->container = $container;
+ }
+
public function configureLogger(array $config) {
Log4PhpWrapper::configure($config, 'LoggerConfiguratorPhp');
$this->logger = Log4PhpWrapper::getRootLogger();
}
+ /**
+ *
+ * @param array $context
+ * @return \Logger
+ */
private function getLogger(array $context = array()) {
$logger = $this->logger;
@@ -36,7 +47,26 @@ private function getLogger(array $context = array()) {
}
return $logger;
- }
+ }
+
+ /**
+ *
+ * @param string $appenderName
+ * @param string $logger
+ */
+ public function addAppender($appenderId, $logger = '') {
+ if (!$this->logger instanceof \Logger) {
+ return;
+ }
+
+ $context = array();
+ if ($logger != '') {
+ $context['app'] = $logger;
+ }
+
+ $logger = $this->getLogger($context);
+ $logger->addAppender($this->container->get($appenderId));
+ }
private function addMessage($message, $priority, $loggerName = 'root') {
$message = array(
@@ -1,10 +1,13 @@
parameters:
- php4log.logger.class: FS\Log4PhpBundle\Logger
+ log4php.logger.class: FS\Log4PhpBundle\Logger
services:
- php4log.logger:
- class: %php4log.logger.class%
+ log4php.logger:
+ class: %log4php.logger.class%
+ arguments: [ @service_container ]
log4php.data_collector.alllogs:
class: FS\Log4PhpBundle\DataCollector\AllLogsDataCollector
arguments: [ @logger ]
tags:
- - { name: data_collector, template: "FSLog4PhpBundle:Collector:logs", id: "alllogs" }
+ - { name: data_collector, template: "FSLog4PhpBundle:Collector:logs", id: "alllogs" }
+
+

0 comments on commit 1002884

Please sign in to comment.