Phalcon Logger throws 'Log directory does not exist' when target directory missing
0 reputation · 20 Dec 2021, 19:22 UTC
0 reputation · 20 Dec 2021, 19:22 UTC
The goal is to configure the Phalcon Logger component so that logging continues reliably even when the configured log directory is absent or unwritable, while still emitting only meaningful alerts and avoiding unnecessary notification noise.
Constraints include preserving the existing log level routing (e.g., Stream for errors, File for info), not masking genuine configuration problems, and ensuring that any automatic directory creation does not introduce security risks or permission conflicts in shared hosting environments.
The error is thrown when the Stream (or File in older releases) adapter is constructed and the target directory does not exist. The exception occurs before any log message is written, so the application must catch it at the point of adapter creation.
During construction the adapter checks that the directory part of the configured path is a real directory and is writable. If the directory is missing the constructor raises a Phalcon\Logger\Exception with the message “Log directory does not exist”.
Stream adapter for file logging; older versions use File.log() call.try / catch (\Phalcon\Logger\Exception $e) block.is_writable() for the PHP process user.mkdir($parent, 0750, true) and retry creating the primary adapter.Syslog or, if available, a no‑op adapter) and log a single error‑level notice explaining the missing directory.Is the parent directory of the configured log path writable by the PHP process user? If not, automatic creation is not viable and a fallback adapter is the appropriate path.
Use comments to ask for clarification. Post a solution as an answer.
No question comments on this page.