Skip to content

Commit

Permalink
Apply suggestions from code review
Browse files Browse the repository at this point in the history
  • Loading branch information
Seldaek authored Apr 12, 2024
1 parent df98859 commit a37aa92
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions src/Monolog/Formatter/LineFormatter.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,11 @@ public function __construct(?string $format = null, ?string $dateFormat = null,
parent::__construct($dateFormat);
}

public function basePath(string $path = ''): self
/**
* Setting a base path will hide the base path from exception and stack trace file names to shorten them
* @return $this
*/
public function setBasePath(string $path = ''): self
{
if ($path !== '') {
$path = rtrim($path, DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR;
Expand Down Expand Up @@ -273,7 +277,7 @@ private function formatException(\Throwable $e): string

$file = $e->getFile();
if ($this->basePath !== '') {
$file = str_replace($this->basePath, '', $e->getFile());
$file = preg_replace('{^'.preg_quote($this->basePath).'}', '', $e->getFile());
}

$str .= '): ' . $e->getMessage() . ' at ' . $file . ':' . $e->getLine() . ')';
Expand All @@ -290,7 +294,7 @@ private function stacktracesParser(\Throwable $e): string
$trace = $e->getTraceAsString();

if ($this->basePath !== '') {
$trace = str_replace(' ' . $this->basePath, ' ', $trace);
$trace = preg_replace('{^(#\d+ )' . preg_quote($this->basePath) . '}m', '$1', $trace);
}

if ($this->stacktracesParser !== null) {
Expand Down

0 comments on commit a37aa92

Please sign in to comment.