Skip to content

Commit e8bc533

Browse files
authored
Merge pull request #718 from magento/MQE-2143
MQE-2143: Cleanup mftf.log
2 parents 1491ba9 + b29afaf commit e8bc533

File tree

1 file changed

+39
-12
lines changed

1 file changed

+39
-12
lines changed

src/Magento/FunctionalTestingFramework/Util/Logger/MftfLogger.php

Lines changed: 39 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,28 +7,53 @@
77
namespace Magento\FunctionalTestingFramework\Util\Logger;
88

99
use Magento\FunctionalTestingFramework\Config\MftfApplicationConfig;
10-
use Monolog\Handler\StreamHandler;
10+
use Magento\FunctionalTestingFramework\Exceptions\TestFrameworkException;
11+
use Monolog\Handler\HandlerInterface;
1112
use Monolog\Logger;
1213

1314
class MftfLogger extends Logger
1415
{
16+
/**
17+
* MFTF execution phase
18+
*
19+
* @var string
20+
*/
21+
private $phase;
22+
23+
/**
24+
* MftfLogger constructor.
25+
*
26+
* @param string $name
27+
* @param HandlerInterface[] $handlers
28+
* @param callable[] $processors
29+
* @throws TestFrameworkException
30+
*/
31+
public function __construct($name, array $handlers = [], array $processors = [])
32+
{
33+
parent::__construct($name, $handlers, $processors);
34+
$this->phase = MftfApplicationConfig::getConfig()->getPhase();
35+
}
36+
1537
/**
1638
* Prints a deprecation warning, as well as adds a log at the WARNING level.
39+
* Suppresses logging during execution phase.
1740
*
1841
* @param string $message The log message.
1942
* @param array $context The log context.
2043
* @param boolean $verbose
2144
* @return void
22-
* @throws \Magento\FunctionalTestingFramework\Exceptions\TestFrameworkException
2345
*/
2446
public function deprecation($message, array $context = [], $verbose = false)
2547
{
2648
$message = "DEPRECATION: " . $message;
27-
// Suppress print during unit testing
28-
if (MftfApplicationConfig::getConfig()->getPhase() !== MftfApplicationConfig::UNIT_TEST_PHASE && $verbose) {
49+
// print during test generation
50+
if ($this->phase === MftfApplicationConfig::GENERATION_PHASE && $verbose) {
2951
print ($message . json_encode($context) . "\n");
3052
}
31-
parent::warning($message, $context);
53+
// suppress logging during test execution
54+
if ($this->phase !== MftfApplicationConfig::EXECUTION_PHASE) {
55+
parent::warning($message, $context);
56+
}
3257
}
3358

3459
/**
@@ -38,34 +63,36 @@ public function deprecation($message, array $context = [], $verbose = false)
3863
* @param array $context The log context.
3964
* @param boolean $verbose
4065
* @return void
41-
* @throws \Magento\FunctionalTestingFramework\Exceptions\TestFrameworkException
4266
*/
4367
public function criticalFailure($message, array $context = [], $verbose = false)
4468
{
4569
$message = "FAILURE: " . $message;
4670
// Suppress print during unit testing
47-
if (MftfApplicationConfig::getConfig()->getPhase() !== MftfApplicationConfig::UNIT_TEST_PHASE && $verbose) {
71+
if ($this->phase !== MftfApplicationConfig::UNIT_TEST_PHASE && $verbose) {
4872
print ($message . implode("\n", $context) . "\n");
4973
}
5074
parent::critical($message, $context);
5175
}
5276

5377
/**
5478
* Adds a log record at the NOTICE level.
79+
* Suppresses logging during execution phase.
5580
*
5681
* @param string $message
5782
* @param array $context
5883
* @param boolean $verbose
5984
* @return void
60-
* @throws \Magento\FunctionalTestingFramework\Exceptions\TestFrameworkException
6185
*/
6286
public function notification($message, array $context = [], $verbose = false)
6387
{
6488
$message = "NOTICE: " . $message;
65-
// Suppress print during unit testing
66-
if (MftfApplicationConfig::getConfig()->getPhase() !== MftfApplicationConfig::UNIT_TEST_PHASE && $verbose) {
67-
print ($message . implode("\n", $context) . "\n");
89+
// print during test generation
90+
if ($this->phase === MftfApplicationConfig::GENERATION_PHASE && $verbose) {
91+
print ($message . json_encode($context) . "\n");
92+
}
93+
// suppress logging during test execution
94+
if ($this->phase !== MftfApplicationConfig::EXECUTION_PHASE) {
95+
parent::notice($message, $context);
6896
}
69-
parent::notice($message, $context);
7097
}
7198
}

0 commit comments

Comments
 (0)