Skip to content

Commit

Permalink
TracyFileNameProcessor: simplify and speed up computeFileName
Browse files Browse the repository at this point in the history
  • Loading branch information
JanTvrdik committed Aug 25, 2018
1 parent 3c1ea7c commit 38e185a
Showing 1 changed file with 3 additions and 20 deletions.
23 changes: 3 additions & 20 deletions src/MonologProcessors/TracyFileNameProcessor.php
Expand Up @@ -5,16 +5,6 @@

class TracyFileNameProcessor
{
/** @var string */
private $localBlueScreenDirectory;


public function __construct(string $localBlueScreenDirectory)
{
$this->localBlueScreenDirectory = $localBlueScreenDirectory;
}


public function __invoke(array $record): array
{
if (isset($record['context']['exception']) && $record['context']['exception'] instanceof \Throwable) {
Expand All @@ -32,22 +22,15 @@ public function __invoke(array $record): array
private function computeFileName(\Throwable $exception): string
{
$data = [];
while ($exception) {
for (; $exception; $exception = $exception->getPrevious()) {
$data[] = [
get_class($exception), $exception->getMessage(), $exception->getCode(), $exception->getFile(), $exception->getLine(),
array_map(function ($item) { unset($item['args']); return $item; }, $exception->getTrace()),
];
$exception = $exception->getPrevious();
}

$date = date('Y-m-d');
$hash = substr(md5(serialize($data)), 0, 10);
$dir = strtr($this->localBlueScreenDirectory . '/', '\\/', DIRECTORY_SEPARATOR . DIRECTORY_SEPARATOR);
foreach (new \DirectoryIterator($this->localBlueScreenDirectory) as $file) {
if (strpos($file->getBasename(), $hash)) {
return $dir . $file;
}
}

return 'exception--' . date('Y-m-d--H-i') . "--$hash.html";
return "exception--$date--$hash.html";
}
}

0 comments on commit 38e185a

Please sign in to comment.