Seldaek/monolog · error · UnexpectedValueException

Writing to the log file failed: {}

Error message

Writing to the log file failed: {}

What it means

Error "Writing to the log file failed: {}" thrown in Seldaek/monolog.

Source

Thrown at src/Monolog/Handler/StreamHandler.php:203

            return $this->customErrorHandler($code, $msg);
        });
        try {
            $this->streamWrite($stream, $record);
        } finally {
            restore_error_handler();
        }
        if ($this->errorMessage !== null) {
            $error = $this->errorMessage;
            // close the resource if possible to reopen it, and retry the failed write
            if (!$this->retrying && $this->url !== null && $this->url !== 'php://memory') {
                $this->retrying = true;
                $this->close();
                $this->write($record);

                return;
            }

            throw new \UnexpectedValueException('Writing to the log file failed: '.$error . Utils::getRecordMessageForException($record));
        }

        $this->retrying = false;
        if ($this->useLocking) {
            flock($stream, LOCK_UN);
        }
    }

    /**
     * Write to stream
     * @param resource $stream
     */
    protected function streamWrite($stream, LogRecord $record): void
    {
        $data = (string) $record->formatted;
        $length = \strlen($data);
        $written = 0;

View on GitHub (pinned to 57eb102834)

When it happens

Trigger: Thrown at src/Monolog/Handler/StreamHandler.php:203 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of Seldaek/monolog@57eb102834 (2026-08-17). Data as JSON: /api/errors/8cf31047198ec75c. Report an issue: GitHub.