get('defaultPermissions'); $this->fileManager = new FileManager($defaultPermissions); } protected function write(array $record): void { if (!$this->url) { throw new LogicException( 'Missing logger path. Check logger params in the data/config.php.' ); } $this->errorMessage = null; if (!is_writable($this->url)) { $this->fileManager->checkCreateFile($this->url); } if (is_writable($this->url)) { set_error_handler([$this, 'customErrorHandler']); $this->fileManager->appendContents($this->url, $this->pruneMessage($record)); restore_error_handler(); } if (isset($this->errorMessage)) { throw new UnexpectedValueException( sprintf('File "%s" could not be opened: ' . $this->errorMessage, $this->url) ); } } private function customErrorHandler($code, $msg) { $this->errorMessage = $msg; } protected function pruneMessage(array $record) { $message = (string) $record['message']; if (strlen($message) > $this->maxErrorMessageLength) { $record['message'] = substr($message, 0, $this->maxErrorMessageLength) . '...'; $record['formatted'] = $this->getFormatter()->format($record); } return (string) $record['formatted']; } }