Skip to content

Commit

Permalink
Ensure private error handler does not cause problems, fixes #1866
Browse files Browse the repository at this point in the history
  • Loading branch information
Seldaek committed Apr 15, 2024
1 parent a30bfe2 commit 233e0b2
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/Monolog/Handler/StreamHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,9 @@ protected function write(array $record): void
}
$this->createDir($url);
$this->errorMessage = null;
set_error_handler([$this, 'customErrorHandler']);
set_error_handler(function (...$args) {
return $this->customErrorHandler(...$args);
});
try {
$stream = fopen($url, 'a');
if ($this->filePermission !== null) {
Expand Down Expand Up @@ -212,7 +214,9 @@ private function createDir(string $url): void
$dir = $this->getDirFromStream($url);
if (null !== $dir && !is_dir($dir)) {
$this->errorMessage = null;
set_error_handler([$this, 'customErrorHandler']);
set_error_handler(function (...$args) {
return $this->customErrorHandler(...$args);
});
$status = mkdir($dir, 0777, true);
restore_error_handler();
if (false === $status && !is_dir($dir) && strpos((string) $this->errorMessage, 'File exists') === false) {
Expand Down

0 comments on commit 233e0b2

Please sign in to comment.