diff --git a/src/Loggers/ErrorLogHandlerFactory.php b/src/Loggers/ErrorLogHandlerFactory.php index 6f06c9c1..7d0e38ce 100644 --- a/src/Loggers/ErrorLogHandlerFactory.php +++ b/src/Loggers/ErrorLogHandlerFactory.php @@ -34,6 +34,8 @@ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) * @link https://github.com/techdivision/import * @link http://www.techdivision.com + * + * @deprecated use GenericLogHandlerFactory */ class ErrorLogHandlerFactory implements HandlerFactoryInterface { diff --git a/src/Loggers/GenericLogHandlerFactory.php b/src/Loggers/GenericLogHandlerFactory.php new file mode 100644 index 00000000..c00ccbe7 --- /dev/null +++ b/src/Loggers/GenericLogHandlerFactory.php @@ -0,0 +1,88 @@ + + * @copyright 2020 TechDivision GmbH + * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) + * @link https://github.com/techdivision/import + * @link http://www.techdivision.com + */ + +namespace TechDivision\Import\Loggers; + +use TechDivision\Import\Utils\ConfigurationUtil; +use TechDivision\Import\Utils\ConfigurationKeys; +use TechDivision\Import\Configuration\ConfigurationInterface; +use TechDivision\Import\Configuration\Logger\HandlerConfigurationInterface; + +/** + * Error Log Handler factory implementation. + * + * @author Martin Eisenführer + * @copyright 2020 TechDivision GmbH + * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) + * @link https://github.com/techdivision/import + * @link http://www.techdivision.com + */ +class GenericLogHandlerFactory implements HandlerFactoryInterface +{ + + /** + * The log level to use. + * + * @var string + */ + protected $defaultLogLevel; + + /** + * The log level to use. + * + * @var string + */ + protected $handlerClassName; + + /** + * Initialize the processor with the actual configuration instance + * + * @param ConfigurationInterface $configuration the actual configuration instance + * @param string $handlerClassName Classname for monolog Logger handler + */ + public function __construct(ConfigurationInterface $configuration, $handlerClassName) + { + $this->defaultLogLevel = $configuration->getLogLevel(); + $this->handlerClassName = $handlerClassName; + } + + /** + * Creates a new formatter instance based on the passed configuration. + * + * @param \TechDivision\Import\Configuration\Logger\HandlerConfigurationInterface $handlerConfiguration The handler configuration + * + * @return \Monolog\Handler\HandlerInterface The handler instance + */ + public function factory(HandlerConfigurationInterface $handlerConfiguration) + { + + // load the params + $params = $handlerConfiguration->getParams(); + + // set the default log level, if not already set explicitly + if (!isset($params[ConfigurationKeys::LEVEL])) { + $params[ConfigurationKeys::LEVEL] = $this->defaultLogLevel; + } + + // create and return the handler instance + $reflectionClass = new \ReflectionClass($this->handlerClassName); + return $reflectionClass->newInstanceArgs(ConfigurationUtil::prepareConstructorArgs($reflectionClass, $params)); + } +} diff --git a/symfony/Resources/config/services.xml b/symfony/Resources/config/services.xml index 55661c75..a5d61fb1 100644 --- a/symfony/Resources/config/services.xml +++ b/symfony/Resources/config/services.xml @@ -31,8 +31,13 @@ - + + Monolog\Handler\NativeMailerHandler + + + + Monolog\Handler\ErrorLogHandler