diff --git a/src/Magento/FunctionalTestingFramework/Util/Logger/MftfLogger.php b/src/Magento/FunctionalTestingFramework/Util/Logger/MftfLogger.php index 0e8c1e17f..5955235ce 100644 --- a/src/Magento/FunctionalTestingFramework/Util/Logger/MftfLogger.php +++ b/src/Magento/FunctionalTestingFramework/Util/Logger/MftfLogger.php @@ -7,28 +7,53 @@ 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 { + /** + * MFTF execution phase + * + * @var string + */ + private $phase; + + /** + * MftfLogger constructor. + * + * @param string $name + * @param HandlerInterface[] $handlers + * @param callable[] $processors + * @throws TestFrameworkException + */ + public function __construct($name, array $handlers = [], array $processors = []) + { + 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) { $message = "DEPRECATION: " . $message; - // Suppress print during unit testing - if (MftfApplicationConfig::getConfig()->getPhase() !== MftfApplicationConfig::UNIT_TEST_PHASE && $verbose) { + // print during test generation + if ($this->phase === MftfApplicationConfig::GENERATION_PHASE && $verbose) { print ($message . json_encode($context) . "\n"); } - parent::warning($message, $context); + // suppress logging during test execution + if ($this->phase !== MftfApplicationConfig::EXECUTION_PHASE) { + parent::warning($message, $context); + } } /** @@ -38,13 +63,12 @@ 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); @@ -52,20 +76,23 @@ public function criticalFailure($message, array $context = [], $verbose = false) /** * 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) { $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 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); } - parent::notice($message, $context); } }