Skip to content

Commit

Permalink
Define custom logger class that simply extended monolog logger in ord…
Browse files Browse the repository at this point in the history
…er to have one interface only and use autowiring
  • Loading branch information
LucaGallinari committed Oct 3, 2022
1 parent 5ee4b2b commit b3fe61f
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 16 deletions.
8 changes: 6 additions & 2 deletions services.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,12 @@ services:
arguments:
- 'text/html'

Psr\Log\LoggerInterface:
class: \Monolog\Logger
Psr\Log\LoggerInterface: '@webgriffe_esb_logger'

Webgriffe\Esb\LoggerResettableInterface: '@webgriffe_esb_logger'

webgriffe_esb_logger:
class: \Webgriffe\Esb\Logger\LoggerResettable
arguments: [ 'esb', ['@Monolog\Handler\StreamHandler', '@Monolog\Handler\ErrorLogHandler', '@Monolog\Handler\NativeMailerHandler'] ]
public: true

Expand Down
11 changes: 11 additions & 0 deletions src/Logger/LoggerResettable.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?php

declare(strict_types=1);

namespace Webgriffe\Esb\Logger;

use Monolog\Logger;

final class LoggerResettable extends Logger implements LoggerResettableInterface
{
}
12 changes: 12 additions & 0 deletions src/Logger/LoggerResettableInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?php

declare(strict_types=1);

namespace Webgriffe\Esb\Logger;

use Monolog\ResettableInterface;
use Psr\Log\LoggerInterface;

interface LoggerResettableInterface extends LoggerInterface, ResettableInterface
{
}
10 changes: 3 additions & 7 deletions src/ProducerInstance.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@
use function Amp\call;
use Amp\Loop;
use Amp\Promise;
use Monolog\ResettableInterface;
use Psr\Log\LoggerInterface;
use Webgriffe\Esb\Logger\LoggerResettableInterface;
use Webgriffe\Esb\Model\FlowConfig;
use Webgriffe\Esb\Model\Job;
use Webgriffe\Esb\Model\ProducedJobEvent;
Expand All @@ -32,7 +31,7 @@ final class ProducerInstance implements ProducerInstanceInterface
private $producer;

/**
* @var LoggerInterface&ResettableInterface
* @var LoggerResettableInterface
*/
private $logger;

Expand All @@ -51,14 +50,11 @@ final class ProducerInstance implements ProducerInstanceInterface
*/
private $queueManager;

/**
* @param LoggerInterface&ResettableInterface $logger
*/
public function __construct(
FlowConfig $flowConfig,
ProducerInterface $producer,
?BeanstalkClient $beanstalkClient,
$logger,
LoggerResettableInterface $logger,
HttpProducersServer $httpProducersServer,
CronProducersServer $cronProducersServer,
?ElasticSearch $elasticSearch,
Expand Down
10 changes: 3 additions & 7 deletions src/WorkerInstance.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,8 @@
use function Amp\call;
use function Amp\delay;
use Amp\Promise;
use Monolog\ResettableInterface;
use Psr\Log\LoggerInterface;
use Webgriffe\Esb\Exception\FatalQueueException;
use Webgriffe\Esb\Logger\LoggerResettableInterface;
use Webgriffe\Esb\Model\ErroredJobEvent;
use Webgriffe\Esb\Model\FlowConfig;
use Webgriffe\Esb\Model\JobInterface;
Expand Down Expand Up @@ -38,7 +37,7 @@ final class WorkerInstance implements WorkerInstanceInterface
private $worker;

/**
* @var LoggerInterface&ResettableInterface
* @var LoggerResettableInterface
*/
private $logger;

Expand All @@ -52,15 +51,12 @@ final class WorkerInstance implements WorkerInstanceInterface
*/
private static $workCounts = [];

/**
* @param LoggerInterface&ResettableInterface $logger
*/
public function __construct(
FlowConfig $flowConfig,
int $instanceId,
WorkerInterface $worker,
?BeanstalkClient $beanstalkClient,
$logger,
LoggerResettableInterface $logger,
?ElasticSearch $elasticSearch,
WorkerQueueManagerInterface $queueManager = null
) {
Expand Down

0 comments on commit b3fe61f

Please sign in to comment.