-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRepairLogging.php
More file actions
39 lines (33 loc) · 1.03 KB
/
RepairLogging.php
File metadata and controls
39 lines (33 loc) · 1.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
<?php
declare(strict_types=1);
namespace Cortex\JsonRepair\Concerns;
/**
* @mixin \Cortex\JsonRepair\JsonRepairer
*/
trait RepairLogging
{
/**
* Log a repair action with context.
*
* @param string $message Description of the repair action
* @param array<string, mixed> $context Additional context data
*/
private function log(string $message, array $context = []): void
{
$this->logger?->debug($message, array_merge([
'position' => $this->pos,
'context' => $this->getContextSnippet(),
], $context));
}
/**
* Get a snippet of the JSON around the current position for logging context.
*/
private function getContextSnippet(int $window = 15): string
{
$start = max(0, $this->pos - $window);
$end = min(strlen($this->json), $this->pos + $window);
$before = substr($this->json, $start, $this->pos - $start);
$after = substr($this->json, $this->pos, $end - $this->pos);
return $before . '>>>' . $after;
}
}