From 2a8346096c79ca342dd6919f303427b1df0dcaf3 Mon Sep 17 00:00:00 2001 From: brendt Date: Sat, 25 May 2024 09:03:58 +0200 Subject: [PATCH] Cleanup --- .../{LogCommands.php => LogDebugCommand.php} | 31 +++++++------------ src/Commands/LogProjectCommand.php | 31 +++++++++++++++++++ 2 files changed, 43 insertions(+), 19 deletions(-) rename src/Commands/{LogCommands.php => LogDebugCommand.php} (71%) create mode 100644 src/Commands/LogProjectCommand.php diff --git a/src/Commands/LogCommands.php b/src/Commands/LogDebugCommand.php similarity index 71% rename from src/Commands/LogCommands.php rename to src/Commands/LogDebugCommand.php index a73a62e..f3b7a71 100644 --- a/src/Commands/LogCommands.php +++ b/src/Commands/LogDebugCommand.php @@ -8,10 +8,9 @@ use Tempest\Console\ConsoleCommand; use Tempest\Console\Highlight\VarExportLanguage\VarExportLanguage; use Tempest\Highlight\Highlighter; -use Tempest\Log\Channels\AppendLogChannel; use Tempest\Log\LogConfig; -final readonly class LogCommands +final readonly class LogDebugCommand { public function __construct( private Console $console, @@ -20,20 +19,8 @@ public function __construct( ) { } - #[ConsoleCommand('log:project', aliases: ['lp'])] - public function project(): void - { - foreach ($this->logConfig->channels as $channel) { - if ($channel instanceof AppendLogChannel) { - passthru("tail -f {$channel->getPath()}"); - } - } - - $this->console->error("No AppendLogChannel registered"); - } - #[ConsoleCommand('log:debug', aliases: ['ld'])] - public function debug(): void + public function __invoke(): void { $debugLogPath = $this->logConfig->debugLogPath; @@ -43,19 +30,25 @@ public function debug(): void return; } - $this->console->writeln("

Debug

Listening for logs, use lw or ld to start"); + $dir = pathinfo($debugLogPath, PATHINFO_DIRNAME); + + if (! is_dir($dir)) { + mkdir($dir); + } if (! file_exists($debugLogPath)) { touch($debugLogPath); } - $handle = @fopen($debugLogPath, "r"); + $handle = fopen($debugLogPath, "r"); + + $this->console->writeln("

Debug

Listening for logs, use lw or ld to start"); fseek($handle, -1, SEEK_END); $offset = ftell($handle); - /** @phpstan-ignore-next-line */ - while(true) { + /** @phpstan-ignore-next-line */ + while (true) { fseek($handle, -1, SEEK_END); $newOffset = ftell($handle); diff --git a/src/Commands/LogProjectCommand.php b/src/Commands/LogProjectCommand.php new file mode 100644 index 0000000..ddf4484 --- /dev/null +++ b/src/Commands/LogProjectCommand.php @@ -0,0 +1,31 @@ +logConfig->channels as $channel) { + if ($channel instanceof AppendLogChannel) { + passthru("tail -f {$channel->getPath()}"); + } + } + + $this->console->error("No AppendLogChannel registered"); + } +}