Skip to content

Commit c2de761

Browse files
committed
MQE-2143: Cleanup mftf.log
1 parent c46c9e5 commit c2de761

File tree

1 file changed

+42
-19
lines changed

1 file changed

+42
-19
lines changed

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

Lines changed: 42 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -7,28 +7,51 @@
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
{
1516
/**
16-
* Prints a deprecation warning, as well as adds a log at the WARNING level during test generation.
17+
* MFTF execution phase
18+
*
19+
* @var string
20+
*/
21+
private $phase;
22+
23+
/**
24+
* MftfLogger constructor.
25+
*
26+
* @param string $name The logging channel
27+
* @param HandlerInterface[] $handlers Optional stack of handlers, the first one in the array is called first, etc.
28+
* @param callable[] $processors Optional array of processors
29+
* @throws TestFrameworkException
30+
*/
31+
public function __construct($name, array $handlers = array(), array $processors = array())
32+
{
33+
parent::__construct($name, $handlers, $processors);
34+
$this->phase = MftfApplicationConfig::getConfig()->getPhase();
35+
}
36+
37+
/**
38+
* 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
{
26-
// Suppress print during unit testing
27-
if (MftfApplicationConfig::getConfig()->getPhase() === MftfApplicationConfig::GENERATION_PHASE) {
28-
$message = "DEPRECATION: " . $message;
29-
if ($verbose) {
30-
print ($message . json_encode($context) . "\n");
31-
}
48+
$message = "DEPRECATION: " . $message;
49+
// print during test generation
50+
if ($this->phase === MftfApplicationConfig::GENERATION_PHASE && $verbose) {
51+
print ($message . json_encode($context) . "\n");
52+
}
53+
// suppress logging during test execution
54+
if ($this->phase !== MftfApplicationConfig::EXECUTION_PHASE) {
3255
parent::warning($message, $context);
3356
}
3457
}
@@ -40,35 +63,35 @@ public function deprecation($message, array $context = [], $verbose = false)
4063
* @param array $context The log context.
4164
* @param boolean $verbose
4265
* @return void
43-
* @throws \Magento\FunctionalTestingFramework\Exceptions\TestFrameworkException
4466
*/
4567
public function criticalFailure($message, array $context = [], $verbose = false)
4668
{
4769
$message = "FAILURE: " . $message;
4870
// Suppress print during unit testing
49-
if (MftfApplicationConfig::getConfig()->getPhase() !== MftfApplicationConfig::UNIT_TEST_PHASE && $verbose) {
71+
if ($this->phase !== MftfApplicationConfig::UNIT_TEST_PHASE && $verbose) {
5072
print ($message . implode("\n", $context) . "\n");
5173
}
5274
parent::critical($message, $context);
5375
}
5476

5577
/**
56-
* Adds a log record at the NOTICE level during test generation.
78+
* Adds a log record at the NOTICE level.
79+
* Suppresses logging during execution phase.
5780
*
5881
* @param string $message
5982
* @param array $context
6083
* @param boolean $verbose
6184
* @return void
62-
* @throws \Magento\FunctionalTestingFramework\Exceptions\TestFrameworkException
6385
*/
6486
public function notification($message, array $context = [], $verbose = false)
6587
{
66-
// Print during generation phase
67-
if (MftfApplicationConfig::getConfig()->getPhase() === MftfApplicationConfig::GENERATION_PHASE) {
68-
$message = "NOTICE: " . $message;
69-
if ($verbose) {
70-
print ($message . implode("\n", $context) . "\n");
71-
}
88+
$message = "NOTICE: " . $message;
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) {
7295
parent::notice($message, $context);
7396
}
7497
}

0 commit comments

Comments
 (0)