2020use Symfony \Component \Console \ConsoleEvents ;
2121use Symfony \Component \Console \Event \ConsoleCommandEvent ;
2222use Symfony \Component \Console \Event \ConsoleTerminateEvent ;
23+ use Symfony \Component \Console \Input \InputInterface ;
2324use Symfony \Component \Console \Output \ConsoleOutputInterface ;
2425use Symfony \Component \Console \Output \OutputInterface ;
2526use Symfony \Component \EventDispatcher \EventSubscriberInterface ;
@@ -64,6 +65,7 @@ public function __construct(
6465 bool $ bubble = true ,
6566 array $ verbosityLevelMap = [],
6667 private array $ consoleFormatterOptions = [],
68+ private ?InputInterface $ input = null ,
6769 ) {
6870 parent ::__construct (Level::Debug, $ bubble );
6971
@@ -74,7 +76,16 @@ public function __construct(
7476
7577 public function isHandling (LogRecord $ record ): bool
7678 {
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 ();
7889 }
7990
8091 public function handle (LogRecord $ record ): bool
@@ -84,6 +95,11 @@ public function handle(LogRecord $record): bool
8495 return $ this ->updateLevel () && parent ::handle ($ record );
8596 }
8697
98+ public function setInput (InputInterface $ input ): void
99+ {
100+ $ this ->input = $ input ;
101+ }
102+
87103 /**
88104 * Sets the console output to use for printing logs.
89105 */
@@ -108,6 +124,9 @@ public function close(): void
108124 */
109125 public function onCommand (ConsoleCommandEvent $ event ): void
110126 {
127+ $ input = $ event ->getInput ();
128+ $ this ->setInput ($ input );
129+
111130 $ output = $ event ->getOutput ();
112131 if ($ output instanceof ConsoleOutputInterface) {
113132 $ output = $ output ->getErrorOutput ();
0 commit comments