Skip to content

Write logs to a file when the --log option is provided#4113

Open
lacatoire wants to merge 1 commit intophpDocumentor:masterfrom
lacatoire:fix/issue-1872-log-file-handler
Open

Write logs to a file when the --log option is provided#4113
lacatoire wants to merge 1 commit intophpDocumentor:masterfrom
lacatoire:fix/issue-1872-log-file-handler

Conversation

@lacatoire
Copy link
Copy Markdown
Contributor

Wire up the --log CLI option so it actually creates the requested log file.

The option was declared in Application::getDefaultInputDefinition() but never consumed: no Monolog handler was attached, so the file was never created (see #1872).

This change:

  • pushes a Monolog\Handler\StreamHandler for the --log path when the option is provided
  • picks the handler level from the console verbosity to mirror what is already shown on screen (warning by default, notice at -v, info at -vv, debug at -vvv)
  • disables file logging entirely when -q / --quiet is passed, matching the intent captured in Transform.php
  • ships three new unit tests covering the happy path, the missing-option case, the quiet case and the verbosity-to-level mapping

The v2 <logging> XML node only accepts <level> and never had a <paths> child; the v3 config schema has no logging node at all. Fixing that XML path is out of scope for this PR.

Fixes #1872.

@lacatoire lacatoire force-pushed the fix/issue-1872-log-file-handler branch from 75ef2ae to f5e9e7d Compare April 17, 2026 11:20
The option was declared in Application::getDefaultInputDefinition but
never consumed, so a user passing --log foo.log saw the option in --help
yet no file was ever written (see phpDocumentor#1872).

Wire a LogConfigurator event listener that, on ConsoleEvents::COMMAND,
pushes a Monolog StreamHandler for the requested path. The handler
level follows the console verbosity (notice, -v info, -vv/-vvv debug)
and --quiet disables file logging entirely, matching the intent
captured in Transform.php. Paths are canonicalised through Monolog
Utils so a relative and an absolute form dedup to the same handler on
nested ConsoleEvents::COMMAND dispatches, and the same dedup is applied
to the ConsoleLogHandler to avoid duplicate console output.

Covered by new unit tests for missing / empty / quiet cases, the
verbosity-to-level mapping, the nested-dispatch and relative-path
dedups, and distinct log files producing two handlers. A functional
test runs phpdoc with --log and asserts the target receives a stable
log line.

Fixes phpDocumentor#1872
@lacatoire lacatoire force-pushed the fix/issue-1872-log-file-handler branch from f5e9e7d to 598d18b Compare April 17, 2026 11:38
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.

Log files not created

1 participant