20
20
use Symfony \Component \Console \ConsoleEvents ;
21
21
use Symfony \Component \Console \Event \ConsoleCommandEvent ;
22
22
use Symfony \Component \Console \Event \ConsoleTerminateEvent ;
23
+ use Symfony \Component \Console \Input \InputInterface ;
23
24
use Symfony \Component \Console \Output \ConsoleOutputInterface ;
24
25
use Symfony \Component \Console \Output \OutputInterface ;
25
26
use Symfony \Component \EventDispatcher \EventSubscriberInterface ;
@@ -64,6 +65,7 @@ public function __construct(
64
65
bool $ bubble = true ,
65
66
array $ verbosityLevelMap = [],
66
67
private array $ consoleFormatterOptions = [],
68
+ private ?InputInterface $ input = null ,
67
69
) {
68
70
parent ::__construct (Level::Debug, $ bubble );
69
71
@@ -74,7 +76,16 @@ public function __construct(
74
76
75
77
public function isHandling (LogRecord $ record ): bool
76
78
{
77
- return $ this ->updateLevel () && parent ::isHandling ($ record );
79
+ return ($ this ->input !== null && $ this ->input ->isInteractive ()) || $ this ->updateLevel () && parent ::isHandling ($ record );
80
+ }
81
+
82
+ public function getBubble (): bool
83
+ {
84
+ if ($ this ->input !== null && $ this ->input ->isInteractive ()) {
85
+ return false ;
86
+ }
87
+
88
+ return parent ::getBubble ();
78
89
}
79
90
80
91
public function handle (LogRecord $ record ): bool
@@ -84,6 +95,11 @@ public function handle(LogRecord $record): bool
84
95
return $ this ->updateLevel () && parent ::handle ($ record );
85
96
}
86
97
98
+ public function setInput (InputInterface $ input ): void
99
+ {
100
+ $ this ->input = $ input ;
101
+ }
102
+
87
103
/**
88
104
* Sets the console output to use for printing logs.
89
105
*/
@@ -108,6 +124,9 @@ public function close(): void
108
124
*/
109
125
public function onCommand (ConsoleCommandEvent $ event ): void
110
126
{
127
+ $ input = $ event ->getInput ();
128
+ $ this ->setInput ($ input );
129
+
111
130
$ output = $ event ->getOutput ();
112
131
if ($ output instanceof ConsoleOutputInterface) {
113
132
$ output = $ output ->getErrorOutput ();
0 commit comments