Skip to content

Commit 8d7a9ec

Browse files
committed
refactor: consolidate logger methods and clean up Processor detection
1 parent aa87aee commit 8d7a9ec

File tree

1 file changed

+9
-24
lines changed

1 file changed

+9
-24
lines changed

src/Command/WorkerCommand.php

Lines changed: 9 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -160,33 +160,19 @@ protected function getQueueExtension(Arguments $args, LoggerInterface $logger):
160160
* Creates and returns a LoggerInterface object
161161
*
162162
* @param \Cake\Console\Arguments $args Arguments
163+
* @param bool $forceLogger Force logger creation even without verbose flag
163164
* @return \Psr\Log\LoggerInterface
164165
*/
165-
protected function getLogger(Arguments $args): LoggerInterface
166+
protected function getLogger(Arguments $args, bool $forceLogger = false): LoggerInterface
166167
{
167168
$logger = null;
168-
if (!empty($args->getOption('verbose'))) {
169+
if ($forceLogger || !empty($args->getOption('verbose'))) {
169170
$logger = Log::engine((string)$args->getOption('logger'));
170171
}
171172

172173
return $logger ?? new NullLogger();
173174
}
174175

175-
/**
176-
* Get logger for subprocess output.
177-
* Always returns a real logger for subprocess mode to show job logs.
178-
*
179-
* @param \Cake\Console\Arguments $args Arguments
180-
* @return \Psr\Log\LoggerInterface
181-
*/
182-
protected function getSubprocessLogger(Arguments $args): LoggerInterface
183-
{
184-
$loggerName = (string)$args->getOption('logger');
185-
$logger = Log::engine($loggerName);
186-
187-
return $logger ?? new NullLogger();
188-
}
189-
190176
/**
191177
* Creates and returns a Processor object
192178
*
@@ -214,6 +200,11 @@ protected function getProcessor(Arguments $args, ConsoleIo $io, LoggerInterface
214200

215201
// Check subprocess mode before instantiating processor
216202
if ($args->getOption('subprocess') || ($config['subprocess']['enabled'] ?? false)) {
203+
if ($processorClass !== Processor::class && !is_subclass_of($processorClass, Processor::class)) {
204+
$io->error('Subprocess mode is only supported with the default Processor class');
205+
$this->abort();
206+
}
207+
217208
$subprocessConfig = array_merge(
218209
$config['subprocess'] ?? [],
219210
[
@@ -222,13 +213,7 @@ protected function getProcessor(Arguments $args, ConsoleIo $io, LoggerInterface
222213
],
223214
);
224215

225-
if ($processorClass !== Processor::class && !is_subclass_of($processorClass, Processor::class)) {
226-
$io->error('Subprocess mode is only supported with the default Processor class');
227-
$this->abort();
228-
}
229-
230-
// Use a real logger for subprocess output so logs are visible
231-
$subprocessLogger = $this->getSubprocessLogger($args);
216+
$subprocessLogger = $this->getLogger($args, forceLogger: true);
232217
$processor = new SubprocessProcessor($subprocessLogger, $subprocessConfig, $this->container);
233218
} else {
234219
$processor = new $processorClass($logger, $this->container);

0 commit comments

Comments
 (0)