Skip to content

Commit

Permalink
Set StreamHandler stream chunk size, fixes Seldaek#1552
Browse files Browse the repository at this point in the history
This ensures atomic log record writing to the output stream.
  • Loading branch information
dsch authored and robocoder committed May 24, 2022
1 parent 52ebd23 commit 2b79e01
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/Monolog/Handler/StreamHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@
*/
class StreamHandler extends AbstractProcessingHandler
{
const MAX_CHUNK_SIZE = 2147483647;

/** @var resource|null */
protected $stream;
protected $url;
private $errorMessage;
Expand All @@ -45,6 +48,7 @@ public function __construct($stream, $level = Logger::DEBUG, $bubble = true, $fi
parent::__construct($level, $bubble);
if (is_resource($stream)) {
$this->stream = $stream;
stream_set_chunk_size($this->stream, self::MAX_CHUNK_SIZE);
} elseif (is_string($stream)) {
$this->url = Utils::canonicalizePath($stream);
} else {
Expand Down Expand Up @@ -109,6 +113,7 @@ protected function write(array $record)

throw new \UnexpectedValueException(sprintf('The stream or file "%s" could not be opened in append mode: '.$this->errorMessage, $this->url));
}
stream_set_chunk_size($this->stream, self::MAX_CHUNK_SIZE);
}

if ($this->useLocking) {
Expand Down

0 comments on commit 2b79e01

Please sign in to comment.