Skip to content

Commit b0fcc50

Browse files
aymanrbclaude
andcommitted
Enrich log messages with file path, text size, template count, and match outcome
Previous log messages showed only raw JSON of extracted data and a bare template path, making it hard to debug parsing issues in production. Log messages now include: file path and byte size in parseFileContent(), text length and template count with similarity mode in parseText(), template basename on each attempt, key count on a successful match, and an explicit no-match info log when no template fits. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent ccba5af commit b0fcc50

1 file changed

Lines changed: 18 additions & 2 deletions

File tree

src/TextParser.php

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ public function parseFileContent(string $filePath, bool $findMatchingTemplate =
3737
throw new InvalidParseFileException($filePath);
3838
}
3939

40+
$this->logger->debug(sprintf('Parsing file: %s (%d bytes)', $filePath, strlen($fileContents)));
41+
4042
return $this->parseText($fileContents, $findMatchingTemplate);
4143
}
4244

@@ -52,15 +54,29 @@ public function parseText(string $text, bool $findMatchingTemplate = false): Par
5254

5355
$parsableTemplates = $this->templatesHelper->getTemplates($text, $findMatchingTemplate);
5456

57+
$this->logger->debug(sprintf(
58+
'Attempting to parse %d character(s) against %d template(s) [similarity=%s]',
59+
strlen($text),
60+
count($parsableTemplates),
61+
$findMatchingTemplate ? 'on' : 'off'
62+
));
63+
5564
foreach ($parsableTemplates as $templatePath => $templatePattern) {
56-
$this->logger->debug(sprintf('Parsing against template: %s', $templatePath));
65+
$this->logger->debug(sprintf('Trying template: %s', basename($templatePath)));
5766

5867
if ($this->extractData($text, $templatePattern)) {
5968
$this->parseResults->setAppliedTemplateFile($templatePath);
69+
$this->logger->info(sprintf(
70+
'Match found: template "%s" extracted %d key(s)',
71+
basename($templatePath),
72+
$this->parseResults->countResults()
73+
));
6074
}
6175
}
6276

63-
$this->logger->info(sprintf('Data extracted: %s', json_encode($this->parseResults->getParsedRawData())));
77+
if ($this->parseResults->getAppliedTemplateFile() === null) {
78+
$this->logger->info('No template matched the provided text');
79+
}
6480

6581
return $this->parseResults;
6682
}

0 commit comments

Comments
 (0)