Skip to content

Instantly share code, notes, and snippets.

@TimoBakx
Created May 9, 2019 15:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save TimoBakx/36dd089d0a65c65a36317acfb1b3b871 to your computer and use it in GitHub Desktop.
Save TimoBakx/36dd089d0a65c65a36317acfb1b3b871 to your computer and use it in GitHub Desktop.
<?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')])
);
}
}
<?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);
}
}
<?php
declare(strict_types=1);
namespace App\Util\Logger;
use Psr\Log\LoggerInterface;
interface ExactOnlineLogger extends LoggerInterface
{
}
<?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