Skip to content

fix(handler): fall back to the error log for a read-only log dir - #14

Merged
brianvarskonst merged 1 commit into
mainfrom
fix/unwritable-log-dir
Nov 14, 2026
Merged

brianvarskonst merged 1 commit into
mainfrom
fix/unwritable-log-dir

Conversation

@brianvarskonst

Copy link
Copy Markdown
Member

Summary

DefaultHandlerFactory always built a RotatingFileHandler under %kernel.logs_dir% (default var/log in the project). When a deployment ships the release read-only for the PHP user, the first log call throws UnexpectedValueException (stream could not be opened), so a logged warning becomes a fatal error.

The factory now checks whether the log file's directory, or its nearest existing parent, is writable. If not, the default and security audit handlers use ErrorLogHandler with the same level, so records still reach PHP's error log (php-fpm or the web server collects it). A disabled logs_dir (empty, false, null) still disables the sink.

Tests

  • New test: a read-only project directory gives an ErrorLogHandler that keeps the production level (warning, not debug).
  • phpunit 43/43, phpstan no errors, qa cs clean.

Release: patch, v1.1.6.

Deployments often ship the release read-only for the PHP user, so the
default rotating file under var/log could not be opened and every log
call threw. The default and security audit handlers now write to PHP's
error log in that case.
@brianvarskonst
brianvarskonst merged commit 40f9eb8 into main Nov 14, 2026
3 checks passed
@brianvarskonst
brianvarskonst deleted the fix/unwritable-log-dir branch November 14, 2026 16:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant