Add a PSR-3 logger, and support any PSR-3 logger #265
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Context and history
This PR builds on previous efforts to finally resolve those constraints while ensuring 100% backward compatibility.
Goals
Implementation
I have integrated psr/log with a simple default implementation. The logic follows a "opt-in" flow:
I’ve included exhaustive tests in xPDOLoggingHistoricTest.php to ensure no regressions from the current behaviour.
I started by looking at @Mark-H's branch but I wanted to preserve full backwards compatibility, so used it as inspiration rather than building directly on it. In my code MODX logging works exactly as it currently does, until a custom PSR logger is provided. Once a custom PSR logger is provided, it's assumed that you want PSR-3 output and you opt out of the traditional MODX logging.
Request for feedback
xPDO::$logger. Is this acceptable for ease of use, or should we strictly require the service container for access?xPDOthan I wished to, and there is some duplication to support the current xPDO logging behaviours. Is this level of duplication acceptable to keep the "legacy" side untouched?xPDOLoggerhas a dependency onxPDO. It works, but it feels unclean. Would you prefer a different approach?Remaining Todos
xPDOLoggingHistoricTest.phpandxPDOLoggerTest.phpneed rationalising. I am satisfied thatxPDOLoggingHistoricTest.phpis exhaustive