Created
May 9, 2019 15:14
-
-
Save TimoBakx/36dd089d0a65c65a36317acfb1b3b871 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
declare(strict_types=1); | |
namespace App\Util\Logger; | |
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface; | |
use Symfony\Component\DependencyInjection\ContainerBuilder; | |
use Symfony\Component\DependencyInjection\Definition; | |
use Symfony\Component\DependencyInjection\Reference; | |
final class CompilerPass implements CompilerPassInterface | |
{ | |
public function process(ContainerBuilder $container) | |
{ | |
$container->setDefinition( | |
ExactOnlineLogger::class, | |
new Definition(DecoratedLogger::class, [new Reference('monolog.logger.exactonline')]) | |
); | |
$container->setDefinition( | |
MailChimpLogger::class, | |
new Definition(DecoratedLogger::class, [new Reference('monolog.logger.mailchimp')]) | |
); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
declare(strict_types=1); | |
namespace App\Util\Logger; | |
use Psr\Log\LoggerInterface; | |
final class DecoratedLogger implements LoggerInterface, ExactOnlineLogger, MailChimpLogger | |
{ | |
/** | |
* @var LoggerInterface | |
*/ | |
private $decorated; | |
public function __construct(LoggerInterface $decorated) | |
{ | |
$this->decorated = $decorated; | |
} | |
public function emergency($message, array $context = []): void | |
{ | |
$this->decorated->emergency($message, $context); | |
} | |
public function alert($message, array $context = []): void | |
{ | |
$this->decorated->alert($message, $context); | |
} | |
public function critical($message, array $context = []): void | |
{ | |
$this->decorated->critical($message, $context); | |
} | |
public function error($message, array $context = []): void | |
{ | |
$this->decorated->error($message, $context); | |
} | |
public function warning($message, array $context = []): void | |
{ | |
$this->decorated->warning($message, $context); | |
} | |
public function notice($message, array $context = []): void | |
{ | |
$this->decorated->notice($message, $context); | |
} | |
public function info($message, array $context = []): void | |
{ | |
$this->decorated->info($message, $context); | |
} | |
public function debug($message, array $context = []): void | |
{ | |
$this->decorated->debug($message, $context); | |
} | |
public function log($level, $message, array $context = []): void | |
{ | |
$this->decorated->log($level, $message, $context); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
declare(strict_types=1); | |
namespace App\Util\Logger; | |
use Psr\Log\LoggerInterface; | |
interface ExactOnlineLogger extends LoggerInterface | |
{ | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
declare(strict_types=1); | |
namespace App\Util\Logger; | |
use Psr\Log\LoggerInterface; | |
interface MailChimpLogger extends LoggerInterface | |
{ | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment