-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
172 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Tempest\Console\Commands; | ||
|
||
use Tempest\Console\Console; | ||
use Tempest\Console\ConsoleCommand; | ||
use Tempest\Console\Highlight\VarExportLanguage\VarExportLanguage; | ||
use Tempest\Console\Output\TailReader; | ||
use Tempest\Log\LogConfig; | ||
|
||
final readonly class LogServerCommand | ||
{ | ||
public function __construct( | ||
private Console $console, | ||
private LogConfig $logConfig, | ||
) { | ||
} | ||
|
||
#[ConsoleCommand('log:server', aliases: ['ls'])] | ||
public function __invoke(): void | ||
{ | ||
$serverLogPath = $this->logConfig->serverLogPath; | ||
|
||
if (! $serverLogPath) { | ||
$this->console->error("No server log configured in LogConfig"); | ||
|
||
return; | ||
} | ||
|
||
if (! file_exists($serverLogPath)) { | ||
$this->console->error("No valid server log at <em>{$serverLogPath}</em>"); | ||
|
||
return; | ||
} | ||
|
||
$this->console->writeln("<h1>Server</h1> Listening for logs…"); | ||
|
||
(new TailReader())->tail($serverLogPath); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Tempest\Console\Commands; | ||
|
||
use Fiber; | ||
use Tempest\Console\ConsoleArgument; | ||
use Tempest\Console\ConsoleCommand; | ||
|
||
final readonly class TailCommand | ||
{ | ||
public function __construct( | ||
private LogDebugCommand $logDebugCommand, | ||
private LogProjectCommand $logProjectCommand, | ||
private LogServerCommand $logServerCommand, | ||
) {} | ||
|
||
#[ConsoleCommand( | ||
name: 'log:tail', | ||
description: 'Tail multiple logs', | ||
aliases: ['tail'], | ||
)] | ||
public function __invoke( | ||
#[ConsoleArgument(description: 'Include the debug log', aliases: ['-d'])] | ||
?bool $debug = null, | ||
|
||
#[ConsoleArgument(description: 'Include the project log', aliases: ['-p'])] | ||
?bool $project = null, | ||
|
||
#[ConsoleArgument(description: 'Include the server log', aliases: ['-s'])] | ||
?bool $server = null | ||
): void { | ||
$shouldFilter = $debug !== null | ||
|| $project !== null | ||
|| $server !== null; | ||
|
||
/** @var array<array-key, \Tempest\Console\Commands\LogDebugCommand|\Tempest\Console\Commands\LogProjectCommand> $loggers */ | ||
$loggers = array_filter([ | ||
($shouldFilter === false || $debug) ? $this->logDebugCommand : null, | ||
($shouldFilter === false || $project) ? $this->logProjectCommand : null, | ||
($shouldFilter === false || $server) ? $this->logServerCommand : null, | ||
]); | ||
|
||
/** @var Fiber[] $fibers */ | ||
$fibers = []; | ||
|
||
foreach ($loggers as $key => $logger) { | ||
$fiber = new Fiber(fn () => ($logger)()); | ||
$fibers[$key] = $fiber; | ||
$fiber->start(); | ||
} | ||
|
||
while ($fibers !== []) { | ||
foreach ($fibers as $key => $fiber) { | ||
if ($fiber->isSuspended()) { | ||
$fiber->resume(); | ||
} | ||
|
||
if ($fiber->isTerminated()) { | ||
unset($fibers[$key]); | ||
} | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Tests\Tempest\Console\Fixtures; | ||
|
||
use Tempest\Console\ConsoleCommand; | ||
use Tempest\Log\Logger; | ||
|
||
final readonly class LoggerCommand | ||
{ | ||
public function __construct(private Logger $logger) {} | ||
|
||
#[ConsoleCommand('logger')] | ||
public function __invoke(): void | ||
{ | ||
$this->logger->info('From the log'); | ||
} | ||
} |