Skip to content

Commit

Permalink
MAGETWO-52767: [Github] Not possible to disable DEBUG logging #4362
Browse files Browse the repository at this point in the history
  • Loading branch information
shiftedreality committed Jun 14, 2016
1 parent 3bea4b9 commit 389a19d
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 15 deletions.
14 changes: 5 additions & 9 deletions app/code/Magento/Developer/Model/Logger/Handler/Debug.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,17 +55,13 @@ public function __construct(
/**
* {@inheritdoc}
*/
public function write(array $record)
public function isHandling(array $record)
{
$storeCode = $this->storeManager->getStore()->getCode();

if (
$this->state->getMode() === State::MODE_PRODUCTION
|| !$this->scopeConfig->getValue('dev/debug/debug_logging', ScopeInterface::SCOPE_STORE, $storeCode)
) {
return;
}

parent::write($record);
return
parent::isHandling($record)
&& $this->state->getMode() === State::MODE_DEVELOPER
&& $this->scopeConfig->getValue('dev/debug/debug_logging', ScopeInterface::SCOPE_STORE, $storeCode);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
use Magento\Store\Api\Data\StoreInterface;
use Magento\Store\Model\ScopeInterface;
use Magento\Store\Model\StoreManagerInterface;
use Monolog\Formatter\FormatterInterface;
use Monolog\Logger;

/**
* Class DebugTest
Expand Down Expand Up @@ -49,6 +51,11 @@ class DebugTest extends \PHPUnit_Framework_TestCase
*/
private $storeMock;

/**
* @var FormatterInterface|\PHPUnit_Framework_MockObject_MockObject
*/
private $formatter;

protected function setUp()
{
$this->filesystemMock = $this->getMockBuilder(DriverInterface::class)
Expand All @@ -62,20 +69,26 @@ protected function setUp()
->getMockForAbstractClass();
$this->storeManagerMock = $this->getMockBuilder(StoreManagerInterface::class)
->getMockForAbstractClass();
$this->formatter = $this->getMockBuilder(FormatterInterface::class)
->getMockForAbstractClass();

$this->storeManagerMock->expects($this->any())
->method('getStore')
->willReturn($this->storeMock);
$this->formatter->expects($this->any())
->method('format')
->willReturn(null);

$this->model = (new ObjectManager($this))->getObject(Debug::class, [
'filesystem' => $this->filesystemMock,
'state' => $this->stateMock,
'scopeConfig' => $this->scopeConfigMock,
'storeManager' => $this->storeManagerMock
]);
$this->model->setFormatter($this->formatter);
}

public function testWrite()
public function testHandle()
{
$this->storeMock->expects($this->once())
->method('getCode')
Expand All @@ -88,10 +101,10 @@ public function testWrite()
->with('dev/debug/debug_logging', ScopeInterface::SCOPE_STORE, 'test_code')
->willReturn(true);

$this->model->write(['formatted' => false]);
$this->model->handle(['formatted' => false, 'level' => Logger::DEBUG]);
}

public function testWriteDisabledByProduction()
public function testHandleDisabledByProduction()
{
$this->storeMock->expects($this->once())
->method('getCode')
Expand All @@ -102,10 +115,10 @@ public function testWriteDisabledByProduction()
$this->scopeConfigMock->expects($this->never())
->method('getValue');

$this->model->write(['formatted' => false]);
$this->model->handle(['formatted' => false, 'level' => Logger::DEBUG]);
}

public function testWriteDisabledByConfig()
public function testHandleDisabledByConfig()
{
$this->storeMock->expects($this->once())
->method('getCode')
Expand All @@ -118,6 +131,19 @@ public function testWriteDisabledByConfig()
->with('dev/debug/debug_logging', ScopeInterface::SCOPE_STORE, 'test_code')
->willReturn(false);

$this->model->write(['formatted' => false]);
$this->model->handle(['formatted' => false, 'level' => Logger::DEBUG]);
}

public function testHandleDisabledByLevel()
{
$this->storeMock->expects($this->once())
->method('getCode')
->willReturn('test_code');
$this->stateMock->expects($this->never())
->method('getMode');
$this->scopeConfigMock->expects($this->never())
->method('getValue');

$this->model->handle(['formatted' => false, 'level' => Logger::API]);
}
}

0 comments on commit 389a19d

Please sign in to comment.