Skip to content

Commit a941db4

Browse files
Cleaned up logging behaviour and fixed bug on setting daemon logger
1 parent 66c4a5a commit a941db4

File tree

3 files changed

+13
-23
lines changed

3 files changed

+13
-23
lines changed

src/Daemon.php

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
use PHPFastCGI\FastCGIDaemon\ConnectionHandler\ConnectionHandlerFactoryInterface;
77
use PHPFastCGI\FastCGIDaemon\Exception\ShutdownException;
88
use Psr\Log\LoggerAwareInterface;
9-
use Psr\Log\LoggerAwareTrait;
109
use Psr\Log\LoggerInterface;
1110
use Psr\Log\NullLogger;
1211

@@ -16,8 +15,6 @@
1615
*/
1716
class Daemon implements DaemonInterface, LoggerAwareInterface
1817
{
19-
use LoggerAwareTrait;
20-
2118
/**
2219
* @var ConnectionPoolInterface
2320
*/
@@ -28,6 +25,11 @@ class Daemon implements DaemonInterface, LoggerAwareInterface
2825
*/
2926
private $connectionHandlerFactory;
3027

28+
/**
29+
* @var LoggerInterface
30+
*/
31+
private $logger;
32+
3133
/**
3234
* Constructor.
3335
*
@@ -41,10 +43,14 @@ public function __construct(ConnectionPoolInterface $connectionPool, ConnectionH
4143
$this->connectionHandlerFactory = $connectionHandlerFactory;
4244

4345
$this->setLogger((null === $logger) ? new NullLogger() : $logger);
46+
}
4447

45-
if ($this->connectionPool instanceof LoggerAwareInterface) {
46-
$this->connectionPool->setLogger($this->logger);
47-
}
48+
/**
49+
* {@inheritdoc}
50+
*/
51+
public function setLogger(LoggerInterface $logger)
52+
{
53+
$this->logger = $logger;
4854

4955
if ($this->connectionHandlerFactory instanceof LoggerAwareInterface) {
5056
$this->connectionHandlerFactory->setLogger($this->logger);

test/Connection/CallableConnectionPool.php

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,12 @@
44

55
use PHPFastCGI\FastCGIDaemon\Connection\ConnectionPoolInterface;
66
use PHPFastCGI\FastCGIDaemon\ConnectionHandler\ConnectionHandlerFactoryInterface;
7-
use Psr\Log\LoggerAwareInterface;
8-
use Psr\Log\LoggerAwareTrait;
9-
use Psr\Log\LoggerInterface;
107

118
/**
129
* Implementation of ConnectionHandlerInterface using callbacks.
1310
*/
14-
class CallableConnectionPool implements ConnectionPoolInterface, LoggerAwareInterface
11+
class CallableConnectionPool implements ConnectionPoolInterface
1512
{
16-
use LoggerAwareTrait;
17-
1813
/**
1914
* @var callable
2015
*/
@@ -37,16 +32,6 @@ public function __construct($callback, $shutdownCallback = null)
3732
$this->shutdownCallback = $shutdownCallback;
3833
}
3934

40-
/**
41-
* Return the current logger
42-
*
43-
* @return LoggerInterface
44-
*/
45-
public function getLogger()
46-
{
47-
return $this->logger;
48-
}
49-
5035
/**
5136
* {@inheritdoc}
5237
*/

test/DaemonTest.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ public function testRun()
3737

3838
// Test loggers have been set
3939
$this->assertSame($logger, $mockConnectionHandlerFactory->getLogger());
40-
$this->assertSame($logger, $mockConnectionPool->getLogger());
4140

4241
try {
4342
$daemon->run();

0 commit comments

Comments
 (0)