Skip to content

Commit

Permalink
Cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
brendt committed May 25, 2024
1 parent 9d93b9e commit 2a83460
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 19 deletions.
31 changes: 12 additions & 19 deletions src/Commands/LogCommands.php → src/Commands/LogDebugCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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;

Expand All @@ -43,19 +30,25 @@ public function debug(): void
return;
}

$this->console->writeln("<h2>Debug</h2> Listening for logs, use <em><strong>lw</strong></em> or <em><strong>ld</strong></em> 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("<h2>Debug</h2> Listening for logs, use <em><strong>lw</strong></em> or <em><strong>ld</strong></em> 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);

Expand Down
31 changes: 31 additions & 0 deletions src/Commands/LogProjectCommand.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php

declare(strict_types=1);

namespace Tempest\Console\Commands;

use Tempest\Console\Console;
use Tempest\Console\ConsoleCommand;
use Tempest\Log\Channels\AppendLogChannel;
use Tempest\Log\LogConfig;

final readonly class LogProjectCommand
{
public function __construct(
private Console $console,
private LogConfig $logConfig,
) {
}

#[ConsoleCommand('log:project', aliases: ['lp'])]
public function __invoke(): void
{
foreach ($this->logConfig->channels as $channel) {
if ($channel instanceof AppendLogChannel) {
passthru("tail -f {$channel->getPath()}");
}
}

$this->console->error("No AppendLogChannel registered");
}
}

0 comments on commit 2a83460

Please # to comment.