Skip to content

Commit

Permalink
* Add #191
Browse files Browse the repository at this point in the history
  • Loading branch information
wagnert committed Oct 20, 2020
1 parent e18d3d6 commit f36db0d
Show file tree
Hide file tree
Showing 4 changed files with 106 additions and 1 deletion.
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
# Version 16.6.0

## Bugfixes

* None

## Features

* Add techdivision/import#191

# Version 16.5.5

## Bugfixes
Expand Down
2 changes: 2 additions & 0 deletions src/Loggers/ErrorLogHandlerFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down
88 changes: 88 additions & 0 deletions src/Loggers/GenericLogHandlerFactory.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
<?php

/**
* TechDivision\Import\Loggers\ErrorLogHandlerFactory
*
* NOTICE OF LICENSE
*
* This source file is subject to the Open Software License (OSL 3.0)
* that is available through the world-wide-web at this URL:
* http://opensource.org/licenses/osl-3.0.php
*
* PHP version 5
*
* @author Martin Eisenführer <[email protected]>
* @copyright 2020 TechDivision GmbH <[email protected]>
* @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 <[email protected]>
* @copyright 2020 TechDivision GmbH <[email protected]>
* @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));
}
}
7 changes: 6 additions & 1 deletion symfony/Resources/config/services.xml
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,13 @@
<argument type="service" id="service_container"/>
<argument type="service" id="import.logger.factory.monolog.handler"/>
</service>
<service id="import.logger.factory.handler.error.log" class="TechDivision\Import\Loggers\ErrorLogHandlerFactory" shared="false">
<service id="import.logger.factory.handler.native.mail.log" class="TechDivision\Import\Loggers\GenericLogHandlerFactory" shared="false">
<argument type="service" id="configuration"/>
<argument type="string">Monolog\Handler\NativeMailerHandler</argument>
</service>
<service id="import.logger.factory.handler.error.log" class="TechDivision\Import\Loggers\GenericLogHandlerFactory" shared="false">
<argument type="service" id="configuration"/>
<argument type="string">Monolog\Handler\ErrorLogHandler</argument>
</service>
<service id="import.logger.factory.handler.swift" class="TechDivision\Import\Loggers\SwiftMailerHandlerFactory" shared="false">
<argument type="service" id="service_container"/>
Expand Down

0 comments on commit f36db0d

Please sign in to comment.