Skip to content

Commit 544b1a7

Browse files
Naorayclaude
andauthored
fix(formatters): strip duplicate keys from Extra Data section (#41)
Closes #32 Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 7b4f091 commit 544b1a7

File tree

2 files changed

+69
-0
lines changed

2 files changed

+69
-0
lines changed

src/Issues/Formatters/ExtraFormatter.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,30 @@
22

33
namespace Naoray\LaravelGithubMonolog\Issues\Formatters;
44

5+
use Illuminate\Support\Arr;
6+
57
class ExtraFormatter
68
{
79
public function format(array $extra): string
810
{
11+
// Exclude keys that have dedicated sections to avoid duplicate output
12+
$extra = Arr::except($extra, [
13+
'exception',
14+
'environment',
15+
'request',
16+
'route',
17+
'route_summary',
18+
'user',
19+
'queries',
20+
'job',
21+
'command',
22+
'outgoing_requests',
23+
'session',
24+
'livewire',
25+
'livewire_originating_page',
26+
'inertia',
27+
]);
28+
929
if (empty($extra)) {
1030
return '';
1131
}

tests/Issues/Formatters/ExtraFormatterTest.php

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,3 +38,52 @@
3838
->toContain('"level": 400')
3939
->toContain('"datetime": "2024-01-01 12:00:00"');
4040
});
41+
42+
it('excludes keys that have dedicated sections', function () {
43+
$extra = [
44+
'exception' => ['class' => 'RuntimeException'],
45+
'environment' => ['app_env' => 'testing'],
46+
'request' => ['url' => 'https://example.com'],
47+
'route' => ['name' => 'test.route'],
48+
'route_summary' => '/dashboard',
49+
'user' => ['id' => 123],
50+
'queries' => [],
51+
'job' => ['name' => 'TestJob'],
52+
'command' => ['name' => 'test:command'],
53+
'outgoing_requests' => [],
54+
'session' => ['data' => []],
55+
'livewire' => ['component' => 'App\\Livewire\\Counter'],
56+
'livewire_originating_page' => '/dashboard',
57+
'inertia' => ['page' => '/dashboard'],
58+
'custom_key' => 'custom_value',
59+
];
60+
61+
$result = $this->formatter->format($extra);
62+
63+
expect($result)
64+
->not->toContain('exception')
65+
->not->toContain('environment')
66+
->not->toContain('request')
67+
->not->toContain('"route"')
68+
->not->toContain('route_summary')
69+
->not->toContain('user')
70+
->not->toContain('queries')
71+
->not->toContain('job')
72+
->not->toContain('command')
73+
->not->toContain('outgoing_requests')
74+
->not->toContain('session')
75+
->not->toContain('livewire')
76+
->not->toContain('inertia')
77+
->toContain('custom_key')
78+
->toContain('custom_value');
79+
});
80+
81+
it('returns empty string when all keys are excluded', function () {
82+
$extra = [
83+
'environment' => ['app_env' => 'testing'],
84+
'user' => ['id' => 123],
85+
'route' => ['name' => 'home'],
86+
];
87+
88+
expect($this->formatter->format($extra))->toBe('');
89+
});

0 commit comments

Comments
 (0)