7
7
namespace Magento \FunctionalTestingFramework \Util \Logger ;
8
8
9
9
use Magento \FunctionalTestingFramework \Config \MftfApplicationConfig ;
10
- use Monolog \Handler \StreamHandler ;
10
+ use Magento \FunctionalTestingFramework \Exceptions \TestFrameworkException ;
11
+ use Monolog \Handler \HandlerInterface ;
11
12
use Monolog \Logger ;
12
13
13
14
class MftfLogger extends Logger
14
15
{
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
+
15
37
/**
16
38
* Prints a deprecation warning, as well as adds a log at the WARNING level.
39
+ * Suppresses logging during execution phase.
17
40
*
18
41
* @param string $message The log message.
19
42
* @param array $context The log context.
20
43
* @param boolean $verbose
21
44
* @return void
22
- * @throws \Magento\FunctionalTestingFramework\Exceptions\TestFrameworkException
23
45
*/
24
46
public function deprecation ($ message , array $ context = [], $ verbose = false )
25
47
{
26
48
$ 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 ) {
29
51
print ($ message . json_encode ($ context ) . "\n" );
30
52
}
31
- parent ::warning ($ message , $ context );
53
+ // suppress logging during test execution
54
+ if ($ this ->phase !== MftfApplicationConfig::EXECUTION_PHASE ) {
55
+ parent ::warning ($ message , $ context );
56
+ }
32
57
}
33
58
34
59
/**
@@ -38,34 +63,36 @@ public function deprecation($message, array $context = [], $verbose = false)
38
63
* @param array $context The log context.
39
64
* @param boolean $verbose
40
65
* @return void
41
- * @throws \Magento\FunctionalTestingFramework\Exceptions\TestFrameworkException
42
66
*/
43
67
public function criticalFailure ($ message , array $ context = [], $ verbose = false )
44
68
{
45
69
$ message = "FAILURE: " . $ message ;
46
70
// Suppress print during unit testing
47
- if (MftfApplicationConfig:: getConfig ()-> getPhase () !== MftfApplicationConfig::UNIT_TEST_PHASE && $ verbose ) {
71
+ if ($ this -> phase !== MftfApplicationConfig::UNIT_TEST_PHASE && $ verbose ) {
48
72
print ($ message . implode ("\n" , $ context ) . "\n" );
49
73
}
50
74
parent ::critical ($ message , $ context );
51
75
}
52
76
53
77
/**
54
78
* Adds a log record at the NOTICE level.
79
+ * Suppresses logging during execution phase.
55
80
*
56
81
* @param string $message
57
82
* @param array $context
58
83
* @param boolean $verbose
59
84
* @return void
60
- * @throws \Magento\FunctionalTestingFramework\Exceptions\TestFrameworkException
61
85
*/
62
86
public function notification ($ message , array $ context = [], $ verbose = false )
63
87
{
64
88
$ 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 );
68
96
}
69
- parent ::notice ($ message , $ context );
70
97
}
71
98
}
0 commit comments