Skip to content

Commit

Permalink
Merge pull request enlitepro#3 from simon-barton/master
Browse files Browse the repository at this point in the history
Adding processors and moving default monolog service config
  • Loading branch information
Sysaninster committed Feb 28, 2014
2 parents 2d1acfc + 6d3849a commit 18ec518
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 19 deletions.
20 changes: 1 addition & 19 deletions config/module.config.php
Original file line number Diff line number Diff line change
@@ -1,24 +1,6 @@
<?php

return array(
'EnliteMonolog' => array(
// Logger name
'EnliteMonologService' => array(
// name of
'name' => 'default',
// Handlers, it can be service manager alias(string) or config(array)
'handlers' => array(
'default' => array(
'name' => 'Monolog\Handler\StreamHandler',
'args' => array(
'path' => 'data/log/application.log',
'level' => \Monolog\Logger::DEBUG,
'bubble' => true
)
)
)
)
),
'service_manager' => array(
'abstract_factories' => array(
'EnliteMonolog\Service\MonologServiceAbstractFactory'
Expand All @@ -27,4 +9,4 @@
'EnliteMonolog\Service\MonologServiceInitializer'
)
)
);
);
22 changes: 22 additions & 0 deletions config/monolog.global.php.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php

return array(
'EnliteMonolog' => array(
// Logger name
'EnliteMonologService' => array(
// name of
'name' => 'default',
// Handlers, it can be service manager alias(string) or config(array)
'handlers' => array(
'default' => array(
'name' => 'Monolog\Handler\StreamHandler',
'args' => array(
'path' => 'data/log/application.log',
'level' => \Monolog\Logger::DEBUG,
'bubble' => true
)
)
)
)
)
);
19 changes: 19 additions & 0 deletions src/EnliteMonolog/Service/MonologOptions.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@ class MonologOptions extends AbstractOptions
*/
protected $handlers = array();

/**
* @var array
*/
protected $processors = array();

/**
* @param string $name
*/
Expand Down Expand Up @@ -57,6 +62,20 @@ public function getHandlers()
return $this->handlers;
}

/**
* @param array $processors
*/
public function setProcessors($processors = array())
{
$this->processors = $processors;
}

/**
* @return array
*/
public function getProcessors()
{
return $this->processors;
}

}
29 changes: 29 additions & 0 deletions src/EnliteMonolog/Service/MonologServiceFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
namespace EnliteMonolog\Service;


use Closure;
use Monolog\Logger;
use Monolog\Formatter\FormatterInterface;
use RuntimeException;
Expand Down Expand Up @@ -40,6 +41,10 @@ public function createLogger(ServiceLocatorInterface $serviceLocator, MonologOpt
$logger->pushHandler($this->createHandler($serviceLocator, $handler));
}

foreach ($options->getProcessors() as $processor) {
$logger->pushProcessor($this->createProcessor($serviceLocator, $processor));
}

return $logger;
}

Expand Down Expand Up @@ -121,4 +126,28 @@ public function createFormatter(ServiceLocatorInterface $serviceLocator, $format
return new $class();
}
}

/**
* @param ServiceLocatorInterface $serviceLocator
* @param $processor
* @return Closure
*
* @throws RuntimeException
*/
public function createProcessor(ServiceLocatorInterface $serviceLocator, $processor)
{
if ($processor instanceof Closure) {
return $processor;
}

if (is_string($processor)) {
$processor = new $processor();

if (is_callable($processor)) {
return $processor;
}
}

throw new RuntimeException('Unknown processor type, must be a Closure or the FQCN of an invokable class');
}
}

0 comments on commit 18ec518

Please sign in to comment.