From f57b87c1041398794f19b96d72f68d2782710460 Mon Sep 17 00:00:00 2001 From: Soumya Unnikrishnan Date: Wed, 27 May 2020 14:39:04 -0500 Subject: [PATCH 1/3] MQE-2143: Cleanup mftf.log Changed deprecation and notices to log only during test generation --- .../Util/Logger/MftfLogger.php | 26 +++++++++++-------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/src/Magento/FunctionalTestingFramework/Util/Logger/MftfLogger.php b/src/Magento/FunctionalTestingFramework/Util/Logger/MftfLogger.php index 0e8c1e17f..c7f6b44e7 100644 --- a/src/Magento/FunctionalTestingFramework/Util/Logger/MftfLogger.php +++ b/src/Magento/FunctionalTestingFramework/Util/Logger/MftfLogger.php @@ -13,7 +13,7 @@ class MftfLogger extends Logger { /** - * Prints a deprecation warning, as well as adds a log at the WARNING level. + * Prints a deprecation warning, as well as adds a log at the WARNING level during test generation. * * @param string $message The log message. * @param array $context The log context. @@ -23,12 +23,14 @@ class MftfLogger extends Logger */ public function deprecation($message, array $context = [], $verbose = false) { - $message = "DEPRECATION: " . $message; // Suppress print during unit testing - if (MftfApplicationConfig::getConfig()->getPhase() !== MftfApplicationConfig::UNIT_TEST_PHASE && $verbose) { - print ($message . json_encode($context) . "\n"); + if (MftfApplicationConfig::getConfig()->getPhase() === MftfApplicationConfig::GENERATION_PHASE) { + $message = "DEPRECATION: " . $message; + if ($verbose) { + print ($message . json_encode($context) . "\n"); + } + parent::warning($message, $context); } - parent::warning($message, $context); } /** @@ -51,7 +53,7 @@ public function criticalFailure($message, array $context = [], $verbose = false) } /** - * Adds a log record at the NOTICE level. + * Adds a log record at the NOTICE level during test generation. * * @param string $message * @param array $context @@ -61,11 +63,13 @@ public function criticalFailure($message, array $context = [], $verbose = false) */ public function notification($message, array $context = [], $verbose = false) { - $message = "NOTICE: " . $message; - // Suppress print during unit testing - if (MftfApplicationConfig::getConfig()->getPhase() !== MftfApplicationConfig::UNIT_TEST_PHASE && $verbose) { - print ($message . implode("\n", $context) . "\n"); + // Print during generation phase + if (MftfApplicationConfig::getConfig()->getPhase() === MftfApplicationConfig::GENERATION_PHASE) { + $message = "NOTICE: " . $message; + if ($verbose) { + print ($message . implode("\n", $context) . "\n"); + } + parent::notice($message, $context); } - parent::notice($message, $context); } } From c2de761f7bd7bf0d7a1de52e58b7d9d1ac5030ac Mon Sep 17 00:00:00 2001 From: Soumya Unnikrishnan Date: Thu, 28 May 2020 10:13:17 -0500 Subject: [PATCH 2/3] MQE-2143: Cleanup mftf.log --- .../Util/Logger/MftfLogger.php | 61 +++++++++++++------ 1 file changed, 42 insertions(+), 19 deletions(-) diff --git a/src/Magento/FunctionalTestingFramework/Util/Logger/MftfLogger.php b/src/Magento/FunctionalTestingFramework/Util/Logger/MftfLogger.php index c7f6b44e7..0c374800a 100644 --- a/src/Magento/FunctionalTestingFramework/Util/Logger/MftfLogger.php +++ b/src/Magento/FunctionalTestingFramework/Util/Logger/MftfLogger.php @@ -7,28 +7,51 @@ namespace Magento\FunctionalTestingFramework\Util\Logger; use Magento\FunctionalTestingFramework\Config\MftfApplicationConfig; -use Monolog\Handler\StreamHandler; +use Magento\FunctionalTestingFramework\Exceptions\TestFrameworkException; +use Monolog\Handler\HandlerInterface; use Monolog\Logger; class MftfLogger extends Logger { /** - * Prints a deprecation warning, as well as adds a log at the WARNING level during test generation. + * MFTF execution phase + * + * @var string + */ + private $phase; + + /** + * MftfLogger constructor. + * + * @param string $name The logging channel + * @param HandlerInterface[] $handlers Optional stack of handlers, the first one in the array is called first, etc. + * @param callable[] $processors Optional array of processors + * @throws TestFrameworkException + */ + public function __construct($name, array $handlers = array(), array $processors = array()) + { + parent::__construct($name, $handlers, $processors); + $this->phase = MftfApplicationConfig::getConfig()->getPhase(); + } + + /** + * Prints a deprecation warning, as well as adds a log at the WARNING level. + * Suppresses logging during execution phase. * * @param string $message The log message. * @param array $context The log context. * @param boolean $verbose * @return void - * @throws \Magento\FunctionalTestingFramework\Exceptions\TestFrameworkException */ public function deprecation($message, array $context = [], $verbose = false) { - // Suppress print during unit testing - if (MftfApplicationConfig::getConfig()->getPhase() === MftfApplicationConfig::GENERATION_PHASE) { - $message = "DEPRECATION: " . $message; - if ($verbose) { - print ($message . json_encode($context) . "\n"); - } + $message = "DEPRECATION: " . $message; + // print during test generation + if ($this->phase === MftfApplicationConfig::GENERATION_PHASE && $verbose) { + print ($message . json_encode($context) . "\n"); + } + // suppress logging during test execution + if ($this->phase !== MftfApplicationConfig::EXECUTION_PHASE) { parent::warning($message, $context); } } @@ -40,35 +63,35 @@ public function deprecation($message, array $context = [], $verbose = false) * @param array $context The log context. * @param boolean $verbose * @return void - * @throws \Magento\FunctionalTestingFramework\Exceptions\TestFrameworkException */ public function criticalFailure($message, array $context = [], $verbose = false) { $message = "FAILURE: " . $message; // Suppress print during unit testing - if (MftfApplicationConfig::getConfig()->getPhase() !== MftfApplicationConfig::UNIT_TEST_PHASE && $verbose) { + if ($this->phase !== MftfApplicationConfig::UNIT_TEST_PHASE && $verbose) { print ($message . implode("\n", $context) . "\n"); } parent::critical($message, $context); } /** - * Adds a log record at the NOTICE level during test generation. + * Adds a log record at the NOTICE level. + * Suppresses logging during execution phase. * * @param string $message * @param array $context * @param boolean $verbose * @return void - * @throws \Magento\FunctionalTestingFramework\Exceptions\TestFrameworkException */ public function notification($message, array $context = [], $verbose = false) { - // Print during generation phase - if (MftfApplicationConfig::getConfig()->getPhase() === MftfApplicationConfig::GENERATION_PHASE) { - $message = "NOTICE: " . $message; - if ($verbose) { - print ($message . implode("\n", $context) . "\n"); - } + $message = "NOTICE: " . $message; + // print during test generation + if ($this->phase === MftfApplicationConfig::GENERATION_PHASE && $verbose) { + print ($message . json_encode($context) . "\n"); + } + // suppress logging during test execution + if ($this->phase !== MftfApplicationConfig::EXECUTION_PHASE) { parent::notice($message, $context); } } From b29afaff40880076cbc954f96760bba4253594f6 Mon Sep 17 00:00:00 2001 From: Soumya Unnikrishnan Date: Thu, 28 May 2020 11:56:23 -0500 Subject: [PATCH 3/3] MQE-2143: Cleanup mftf.log fixed static-checks --- .../FunctionalTestingFramework/Util/Logger/MftfLogger.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Magento/FunctionalTestingFramework/Util/Logger/MftfLogger.php b/src/Magento/FunctionalTestingFramework/Util/Logger/MftfLogger.php index 0c374800a..5955235ce 100644 --- a/src/Magento/FunctionalTestingFramework/Util/Logger/MftfLogger.php +++ b/src/Magento/FunctionalTestingFramework/Util/Logger/MftfLogger.php @@ -23,12 +23,12 @@ class MftfLogger extends Logger /** * MftfLogger constructor. * - * @param string $name The logging channel - * @param HandlerInterface[] $handlers Optional stack of handlers, the first one in the array is called first, etc. - * @param callable[] $processors Optional array of processors + * @param string $name + * @param HandlerInterface[] $handlers + * @param callable[] $processors * @throws TestFrameworkException */ - public function __construct($name, array $handlers = array(), array $processors = array()) + public function __construct($name, array $handlers = [], array $processors = []) { parent::__construct($name, $handlers, $processors); $this->phase = MftfApplicationConfig::getConfig()->getPhase();