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
{
15
16
/**
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.
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
- // 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 ) {
32
55
parent ::warning ($ message , $ context );
33
56
}
34
57
}
@@ -40,35 +63,35 @@ public function deprecation($message, array $context = [], $verbose = false)
40
63
* @param array $context The log context.
41
64
* @param boolean $verbose
42
65
* @return void
43
- * @throws \Magento\FunctionalTestingFramework\Exceptions\TestFrameworkException
44
66
*/
45
67
public function criticalFailure ($ message , array $ context = [], $ verbose = false )
46
68
{
47
69
$ message = "FAILURE: " . $ message ;
48
70
// Suppress print during unit testing
49
- if (MftfApplicationConfig:: getConfig ()-> getPhase () !== MftfApplicationConfig::UNIT_TEST_PHASE && $ verbose ) {
71
+ if ($ this -> phase !== MftfApplicationConfig::UNIT_TEST_PHASE && $ verbose ) {
50
72
print ($ message . implode ("\n" , $ context ) . "\n" );
51
73
}
52
74
parent ::critical ($ message , $ context );
53
75
}
54
76
55
77
/**
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.
57
80
*
58
81
* @param string $message
59
82
* @param array $context
60
83
* @param boolean $verbose
61
84
* @return void
62
- * @throws \Magento\FunctionalTestingFramework\Exceptions\TestFrameworkException
63
85
*/
64
86
public function notification ($ message , array $ context = [], $ verbose = false )
65
87
{
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 ) {
72
95
parent ::notice ($ message , $ context );
73
96
}
74
97
}
0 commit comments