Skip to content

Commit

Permalink
feat(Generator): add logger property
Browse files Browse the repository at this point in the history
- Added a logger property to the Generator class.
- Initialized the logger in the constructor.
- Used the logger in the defaultRunningCallback method to log process  output.
- Updated the defaultRunningCallback to use the logger instead of the output.
  • Loading branch information
[email protected] committed Oct 15, 2024
1 parent b270a86 commit 3ecde9c
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions app/Generators/Generator.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,11 @@ abstract class Generator implements GeneratorContract
*/
protected $output;

/**
* @var \Symfony\Component\Console\Logger\ConsoleLogger
*/
protected $logger;

/**
* @var \Symfony\Component\Console\Helper\HelperSet
*/
Expand All @@ -52,6 +57,7 @@ public function __construct(array $config)
{
$this->config = $config;
$this->output = tap(clone resolve(OutputStyle::class))->setVerbosity(OutputInterface::VERBOSITY_DEBUG);
$this->logger = $this->newConsoleLogger();
$this->helperSet = (function () {
return $this->getArtisan()->getHelperSet();
})->call(Artisan::getFacadeRoot());
Expand Down Expand Up @@ -97,11 +103,9 @@ public function processHelperRun(

public function defaultRunningCallback(): callable
{
$logger = $this->newConsoleLogger();

return static function (string $type, string $data) use ($logger): void {
// Process::OUT === $type ? $this->output->write($data) : $this->output->write("<fg=red>$data</>");
Process::OUT === $type ? $logger->info($data) : $logger->error($data);
return function (string $type, string $data): void {
// Process::OUT === $type ? $this->logger->info($data) : $this->logger->error($data);
Process::OUT === $type ? $this->output->write($data) : $this->output->write("<fg=red>$data</>");
};
}

Expand Down

0 comments on commit 3ecde9c

Please sign in to comment.