Skip to content

Commit 3bb5d62

Browse files
committed
Fixed review issues. Grouped config params. Inject factories for loggers instead of actual loggers in LoggerProxy. Added config path to ConfigOptionsListConstants. Fixed unit tests as needed.
1 parent cbfac52 commit 3bb5d62

File tree

8 files changed

+79
-24
lines changed

8 files changed

+79
-24
lines changed

app/code/Magento/Developer/Console/Command/QueryLogDisableCommand.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ protected function configure()
6161
protected function execute(InputInterface $input, OutputInterface $output)
6262
{
6363
$data = [LoggerProxy::PARAM_ALIAS => LoggerProxy::LOGGER_ALIAS_DISABLED];
64-
$this->deployConfigWriter->saveConfig([ConfigFilePool::APP_ENV => $data]);
64+
$this->deployConfigWriter->saveConfig([ConfigFilePool::APP_ENV => [LoggerProxy::CONF_GROUP_NAME => $data]]);
6565

6666
$output->writeln("<info>". self::SUCCESS_MESSAGE . "</info>");
6767
}

app/code/Magento/Developer/Console/Command/QueryLogEnableCommand.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,9 @@ protected function execute(InputInterface $input, OutputInterface $output)
107107
$data[LoggerProxy::PARAM_QUERY_TIME] = number_format($logQueryTime, 3);
108108
$data[LoggerProxy::PARAM_CALL_STACK] = (int)($logCallStack != 'false');
109109

110-
$this->deployConfigWriter->saveConfig([ConfigFilePool::APP_ENV => $data]);
110+
$configGroup[LoggerProxy::CONF_GROUP_NAME] = $data;
111+
112+
$this->deployConfigWriter->saveConfig([ConfigFilePool::APP_ENV => $configGroup]);
111113

112114
$output->writeln("<info>". self::SUCCESS_MESSAGE . "</info>");
113115
}

app/code/Magento/Developer/Test/Unit/Console/Command/QueryLogDisableCommandTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ public function testExecute()
5151
$this->configWriter
5252
->expects($this->once())
5353
->method('saveConfig')
54-
->with([ConfigFilePool::APP_ENV => $data]);
54+
->with([ConfigFilePool::APP_ENV => [LoggerProxy::CONF_GROUP_NAME => $data]]);
5555

5656
$commandTester = new CommandTester($this->command);
5757
$commandTester->execute([]);

app/code/Magento/Developer/Test/Unit/Console/Command/QueryLogEnableCommandTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ public function testExecuteWithNoParams()
5757
$this->configWriter
5858
->expects($this->any())
5959
->method('saveConfig')
60-
->with([ConfigFilePool::APP_ENV => $data]);
60+
->with([ConfigFilePool::APP_ENV => [LoggerProxy::CONF_GROUP_NAME => $data]]);
6161

6262
$commandTester = new CommandTester($this->command);
6363
$commandTester->execute([]);
@@ -83,7 +83,7 @@ public function testExecuteWithParams()
8383
$this->configWriter
8484
->expects($this->any())
8585
->method('saveConfig')
86-
->with([ConfigFilePool::APP_ENV => $data]);
86+
->with([ConfigFilePool::APP_ENV => [LoggerProxy::CONF_GROUP_NAME => $data]]);
8787

8888
$commandTester = new CommandTester($this->command);
8989
$commandTester->execute(['false', '0.05', 'false']);

app/etc/di.xml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1320,10 +1320,10 @@
13201320
</type>
13211321
<type name="Magento\Framework\DB\Logger\LoggerProxy">
13221322
<arguments>
1323-
<argument name="loggerAlias" xsi:type="init_parameter">\Magento\Framework\DB\Logger\LoggerProxy::PARAM_ALIAS</argument>
1324-
<argument name="logAllQueries" xsi:type="init_parameter">\Magento\Framework\DB\Logger\LoggerProxy::PARAM_LOG_ALL</argument>
1325-
<argument name="logQueryTime" xsi:type="init_parameter">\Magento\Framework\DB\Logger\LoggerProxy::PARAM_QUERY_TIME</argument>
1326-
<argument name="logCallStack" xsi:type="init_parameter">\Magento\Framework\DB\Logger\LoggerProxy::PARAM_CALL_STACK</argument>
1323+
<argument name="loggerAlias" xsi:type="init_parameter">Magento\Framework\Config\ConfigOptionsListConstants::CONFIG_PATH_DB_LOGGER_OUTPUT</argument>
1324+
<argument name="logAllQueries" xsi:type="init_parameter">Magento\Framework\Config\ConfigOptionsListConstants::CONFIG_PATH_DB_LOGGER_LOG_EVERYTHING</argument>
1325+
<argument name="logQueryTime" xsi:type="init_parameter">Magento\Framework\Config\ConfigOptionsListConstants::CONFIG_PATH_DB_LOGGER_QUERY_TIME_THRESHOLD</argument>
1326+
<argument name="logCallStack" xsi:type="init_parameter">Magento\Framework\Config\ConfigOptionsListConstants::CONFIG_PATH_DB_LOGGER_INCLUDE_STACKTRACE</argument>
13271327
</arguments>
13281328
</type>
13291329

lib/internal/Magento/Framework/Config/ConfigOptionsListConstants.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,10 @@ class ConfigOptionsListConstants
3030
const CONFIG_PATH_DB = 'db';
3131
const CONFIG_PATH_RESOURCE = 'resource';
3232
const CONFIG_PATH_CACHE_TYPES = 'cache_types';
33+
const CONFIG_PATH_DB_LOGGER_OUTPUT = 'db_logger/output';
34+
const CONFIG_PATH_DB_LOGGER_LOG_EVERYTHING = 'db_logger/log_everything';
35+
const CONFIG_PATH_DB_LOGGER_QUERY_TIME_THRESHOLD = 'db_logger/query_time_threshold';
36+
const CONFIG_PATH_DB_LOGGER_INCLUDE_STACKTRACE = 'db_logger/include_stacktrace';
3337
/**#@-*/
3438

3539
/**#@+

lib/internal/Magento/Framework/DB/Logger/LoggerProxy.php

Lines changed: 34 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,27 +5,34 @@
55
*/
66
namespace Magento\Framework\DB\Logger;
77

8-
class LoggerProxy extends LoggerAbstract
8+
use Magento\Framework\DB\LoggerInterface;
9+
10+
class LoggerProxy implements LoggerInterface
911
{
12+
/**
13+
* Configuration group name
14+
*/
15+
const CONF_GROUP_NAME = 'db_logger';
16+
1017
/**
1118
* Logger alias param name
1219
*/
13-
const PARAM_ALIAS = 'db_logger_mode';
20+
const PARAM_ALIAS = 'output';
1421

1522
/**
1623
* Logger log all param name
1724
*/
18-
const PARAM_LOG_ALL = 'db_logger_all';
25+
const PARAM_LOG_ALL = 'log_everything';
1926

2027
/**
2128
* Logger query time param name
2229
*/
23-
const PARAM_QUERY_TIME = 'db_logger_query_time';
30+
const PARAM_QUERY_TIME = 'query_time_threshold';
2431

2532
/**
2633
* Logger call stack param name
2734
*/
28-
const PARAM_CALL_STACK = 'db_logger_stack';
35+
const PARAM_CALL_STACK = 'include_stacktrace';
2936

3037
/**
3138
* File logger alias
@@ -38,41 +45,45 @@ class LoggerProxy extends LoggerAbstract
3845
const LOGGER_ALIAS_DISABLED = 'disabled';
3946

4047
/**
41-
* @var LoggerAbstract
48+
* @var LoggerInterface
4249
*/
4350
private $logger;
4451

4552
/**
4653
* LoggerProxy constructor.
47-
* @param File $file
48-
* @param Quiet $quiet
54+
* @param FileFactory $fileFactory
55+
* @param QuietFactory $quietFactory
4956
* @param bool $loggerAlias
5057
* @param bool $logAllQueries
5158
* @param float $logQueryTime
5259
* @param bool $logCallStack
5360
*/
5461
public function __construct(
55-
File $file,
56-
Quiet $quiet,
62+
FileFactory $fileFactory,
63+
QuietFactory $quietFactory,
5764
$loggerAlias,
5865
$logAllQueries = true,
5966
$logQueryTime = 0.001,
6067
$logCallStack = true
6168
) {
6269
switch ($loggerAlias) {
6370
case self::LOGGER_ALIAS_FILE:
64-
$this->logger = $file;
71+
$this->logger = $fileFactory->create(
72+
[
73+
'logAllQueries' => $logAllQueries,
74+
'logQueryTime' => $logQueryTime,
75+
'logCallStack' => $logCallStack,
76+
]
77+
);
6578
break;
6679
default:
67-
$this->logger = $quiet;
80+
$this->logger = $quietFactory->create();
6881
break;
6982
}
70-
71-
parent::__construct($logAllQueries, $logQueryTime, $logCallStack);
7283
}
7384

7485
/**
75-
* @return LoggerAbstract|Quiet
86+
* @return LoggerInterface
7687
*/
7788
public function getLogger()
7889
{
@@ -110,4 +121,12 @@ public function critical(\Exception $e)
110121
{
111122
$this->logger->critical($e);
112123
}
124+
125+
/**
126+
* @return void
127+
*/
128+
public function startTimer()
129+
{
130+
$this->logger->startTimer();
131+
}
113132
}

lib/internal/Magento/Framework/DB/Test/Unit/DB/Logger/LoggerProxyTest.php

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66

77
namespace Magento\Framework\Test\Unit\DB\Logger;
88

9+
use Magento\Framework\DB\Logger\FileFactory;
10+
use Magento\Framework\DB\Logger\QuietFactory;
911
use Magento\Framework\DB\Logger\LoggerProxy;
1012
use Magento\Framework\DB\Logger\File;
1113
use Magento\Framework\DB\Logger\Quiet;
@@ -36,9 +38,23 @@ public function setUp()
3638
*/
3739
public function testNewWithAliasFile()
3840
{
41+
$fileLoggerMock = $this->getMockBuilder(File::class)
42+
->disableOriginalConstructor()
43+
->getMock();
44+
45+
$fileLoggerFactoryMock = $this->getMockBuilder(FileFactory::class)
46+
->disableOriginalConstructor()
47+
->setMethods(['create'])
48+
->getMock();
49+
50+
$fileLoggerFactoryMock->expects($this->once())
51+
->method('create')
52+
->willReturn($fileLoggerMock);
53+
3954
$this->loggerProxy = $this->objectManager->getObject(
4055
LoggerProxy::class,
4156
[
57+
'fileFactory' => $fileLoggerFactoryMock,
4258
'loggerAlias' => LoggerProxy::LOGGER_ALIAS_FILE,
4359
]
4460
);
@@ -51,9 +67,23 @@ public function testNewWithAliasFile()
5167
*/
5268
public function testNewWithAliasDisabled()
5369
{
70+
$quietLoggerMock = $this->getMockBuilder(Quiet::class)
71+
->disableOriginalConstructor()
72+
->getMock();
73+
74+
$quietLoggerFactoryMock = $this->getMockBuilder(QuietFactory::class)
75+
->disableOriginalConstructor()
76+
->setMethods(['create'])
77+
->getMock();
78+
79+
$quietLoggerFactoryMock->expects($this->once())
80+
->method('create')
81+
->willReturn($quietLoggerMock);
82+
5483
$this->loggerProxy = $this->objectManager->getObject(
5584
LoggerProxy::class,
5685
[
86+
'quietFactory' => $quietLoggerFactoryMock,
5787
'loggerAlias' => LoggerProxy::LOGGER_ALIAS_DISABLED,
5888
]
5989
);

0 commit comments

Comments
 (0)