{"record":{"id":"f6cc86cab4e8834c","repo":"symfony/http-kernel","slug":"unable-to-open-s","errorCode":null,"errorMessage":"Unable to open \"%s\".","messagePattern":"Unable to open \"(.+?)\"\\.","errorType":"exception","errorClass":"InvalidArgumentException","httpStatus":null,"severity":"error","filePath":"Log/Logger.php","lineNumber":77,"sourceCode":"     */\n    public function __construct(?string $minLevel = null, $output = null, ?callable $formatter = null, private readonly ?RequestStack $requestStack = null, bool $debug = false)\n    {\n        $minLevel ??= match ((int) ($_ENV['SHELL_VERBOSITY'] ?? $_SERVER['SHELL_VERBOSITY'] ?? 0)) {\n            -1 => LogLevel::ERROR,\n            1 => LogLevel::NOTICE,\n            2 => LogLevel::INFO,\n            3 => LogLevel::DEBUG,\n            default => null === $output || 'php://stdout' === $output || 'php://stderr' === $output ? LogLevel::ERROR : LogLevel::WARNING,\n        };\n\n        if (!isset(self::LEVELS[$minLevel])) {\n            throw new InvalidArgumentException(\\sprintf('The log level \"%s\" does not exist.', $minLevel));\n        }\n\n        $this->minLevelIndex = self::LEVELS[$minLevel];\n        $this->formatter = null !== $formatter ? $formatter(...) : $this->format(...);\n        if ($output && false === $this->handle = \\is_string($output) ? @fopen($output, 'a') : $output) {\n            throw new InvalidArgumentException(\\sprintf('Unable to open \"%s\".', $output));\n        }\n        $this->debug = $debug;\n    }\n\n    public function enableDebug(): void\n    {\n        $this->debug = true;\n    }\n\n    public function log($level, $message, array $context = []): void\n    {\n        if (!isset(self::LEVELS[$level])) {\n            throw new InvalidArgumentException(\\sprintf('The log level \"%s\" does not exist.', $level));\n        }\n\n        if (self::LEVELS[$level] < $this->minLevelIndex) {\n            return;\n        }","sourceCodeStart":59,"sourceCodeEnd":95,"githubUrl":"https://github.com/symfony/http-kernel/blob/aa3a39d7286a62cdfea98f0e69c651a3da6e36cf/Log/Logger.php#L59-L95","documentation":"The Log\\Logger constructor opens the configured output target (a file path or URL) with fopen(..., 'a'); if that fails it throws InvalidArgumentException with this message. It means the logger cannot write to the destination provided.","triggerScenarios":"Passing a $output string path that cannot be opened in append mode: nonexistent directory, missing write permission, invalid wrapper/URL, or a non-resource/non-null $output value that is falsy-mapped to false.","commonSituations":"Log directory doesn't exist or isn't writable by the PHP user; var/log not writable in containers; wrong stream wrapper (e.g. 'file://typo'); SELinux/AppArmor blocking writes; disk permissions after deployment.","solutions":["Create the log directory and grant write permission to the PHP process user (chown/chmod var/log)","Verify the output path/stream wrapper is correct","Run the app as a user with write access to the target","Check SELinux/container volume mount permissions"],"exampleFix":"// before\nnew Logger(LogLevel::ERROR, '/var/log/app/app.log'); // dir missing\n\n// after\nif (!is_dir('/var/log/app')) { mkdir('/var/log/app', 0775, true); }\nnew Logger(LogLevel::ERROR, '/var/log/app/app.log');","handlingStrategy":"validation","validationCode":"$dir = dirname($output);\nif (!is_dir($dir) && !@mkdir($dir, 0775, true)) { throw new \\RuntimeException(\"Cannot create log dir: $dir\"); }\nif (!is_writable($dir)) { throw new \\RuntimeException(\"Log dir not writable: $dir\"); }","typeGuard":null,"tryCatchPattern":"try { $logger = new \\Symfony\\Component\\HttpKernel\\Log\\Logger($minLevel, $output); } catch (\\InvalidArgumentException $e) { error_log('Logger output unavailable: '.$e->getMessage()); $logger = new \\Symfony\\Component\\HttpKernel\\Log\\Logger($minLevel, 'php://stderr'); }","preventionTips":["Ensure log directories exist and are writable by the PHP user before boot","Use a fallback stream (php://stderr) in containers","Check volume mounts and SELinux policies in deployment","Pre-create log dirs in Dockerfile/entrypoint"],"tags":["logging","filesystem","file-open","permissions"],"backgroundTag":"file-open-failed","analyzedSha":"aa3a39d7286a62cdfea98f0e69c651a3da6e36cf","analyzedAt":"2026-09-13T18:03:36.509Z","contentChangedAt":"2026-09-13T18:03:36.509Z","schemaVersion":2},"datasetVersion":"2026-09-16T09:17:16.951Z"}