Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions app/Dto/EnvironmentLog.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,11 @@ public function isExceptionLog(): bool
return $this->type === LogType::EXCEPTION;
}

public function isErrorLog(): bool
{
return $this->type === LogType::ERROR;
}

public function isSystemLog(): bool
{
return $this->type === LogType::SYSTEM;
Expand Down Expand Up @@ -87,6 +92,23 @@ public function getExceptionData(): ?array
'code' => $this->data['code'] ?? null,
'file' => $this->data['file'] ?? null,
'trace' => $this->data['trace'] ?? null,
'context' => $this->data['context'] ?? null,
'extra' => $this->data['extra'] ?? null,
];
}

public function getErrorData(): ?array
{
if (! $this->isErrorLog() || ! is_array($this->data)) {
return null;
}

return [
'file' => $this->data['file'] ?? null,
'trace' => $this->data['trace'] ?? null,
'channel' => $this->data['channel'] ?? null,
'context' => $this->data['context'] ?? null,
'extra' => $this->data['extra'] ?? null,
];
}

Expand All @@ -110,6 +132,10 @@ public function __toString(): string
}
}

if ($this->isErrorLog() && ($errorData = $this->getErrorData()) && $errorData['file']) {
$output .= " | {$errorData['file']}";
}

return $output;
}

Expand Down
2 changes: 2 additions & 0 deletions app/Enums/LogType.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ enum LogType: string
case ACCESS = 'access';
case APPLICATION = 'application';
case EXCEPTION = 'exception';
case ERROR = 'error';
case SYSTEM = 'system';

public function label(): string
Expand All @@ -20,6 +21,7 @@ public function color(): string
self::ACCESS => 'cyan',
self::APPLICATION => 'green',
self::EXCEPTION => 'red',
self::ERROR => 'red',
self::SYSTEM => 'blue',
};
}
Expand Down
9 changes: 9 additions & 0 deletions app/Prompts/EnvironmentLogsPromptRenderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,15 @@ protected function getBoxParams(EnvironmentLog $log): array
return ['body' => $body, 'info' => $info];
}

if ($log->isErrorLog()) {
$errorData = $log->getErrorData() ?? [];

return [
'body' => $this->getBody($log->message),
'info' => $this->getFooter($errorData['channel'] ?? null, $errorData['file'] ?? null),
];
}

if ($log->isApplicationLog()) {
$json = $this->tryToDecodeJson($log->message);

Expand Down
46 changes: 46 additions & 0 deletions tests/Feature/EnvironmentLogsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use App\Client\Resources\Environments\ListEnvironmentLogsRequest;
use App\Client\Resources\Meta\GetOrganizationRequest;
use App\ConfigRepository;
use App\Dto\EnvironmentLog;
use App\Git;
use Illuminate\Support\Facades\Artisan;
use Saloon\Http\Faking\MockClient;
Expand Down Expand Up @@ -133,3 +134,48 @@ function runEnvironmentLogs(array $options = []): array

expect($this->query)->toBeNull();
});

it('reads error logs and the context the API sends with exceptions', function () {
$entries = [
[
'message' => 'Undefined variable $order',
'level' => 'error',
'type' => 'error',
'logged_at' => '2026-10-15T12:00:00Z',
'data' => [
'file' => '/var/www/html/app/Http/Controllers/CheckoutController.php:42',
'trace' => ['#0 /var/www/html/vendor/laravel/framework/src/Illuminate/Routing/Controller.php(54)'],
'channel' => 'production',
'context' => ['user_id' => 7],
'extra' => null,
],
],
[
'message' => 'Call to a member function format() on null',
'level' => 'error',
'type' => 'exception',
'logged_at' => '2026-10-15T12:00:01Z',
'data' => [
'class' => 'Error',
'code' => 0,
'file' => '/var/www/html/app/Models/Order.php:18',
'trace' => [],
'context' => ['order_id' => 12],
'extra' => ['url' => '/checkout'],
],
],
];

mockEnvironmentLogs($entries, '');

$output = runEnvironmentLogs();

expect(collect($output['logs'])->pluck('type')->all())->toBe(['error', 'exception'])
->and($output['logs'][0]['data']['file'])->toBe('/var/www/html/app/Http/Controllers/CheckoutController.php:42');

$logs = array_map(EnvironmentLog::createFromResponse(...), $entries);

expect($logs[0]->isErrorLog())->toBeTrue()
->and($logs[0]->getErrorData()['channel'])->toBe('production')
->and($logs[1]->getExceptionData()['context'])->toBe(['order_id' => 12]);
});