Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add NativeMailerHandler from Monolog #197

Merged
merged 5 commits into from
Oct 20, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -31,8 +31,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