Skip to content

MQE-2143: Cleanup mftf.log #718

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
May 29, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 39 additions & 12 deletions src/Magento/FunctionalTestingFramework/Util/Logger/MftfLogger.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

/**
Expand All @@ -38,34 +63,36 @@ 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.
* 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);
}
}