Add Magento 2.4.8 compatibility via Monolog 3.x support#7
Add Magento 2.4.8 compatibility via Monolog 3.x support#7mohaelmrabet wants to merge 1 commit intomasterfrom
Conversation
There was a problem hiding this comment.
Pull request overview
This PR adds Magento 2.4.8 compatibility by supporting Monolog 3.x, which introduces breaking changes where log level constants return Level enum objects instead of integers. The implementation uses a backward-compatible approach that works with both Monolog 2.x (used in Magento 2.4.6-2.4.7) and Monolog 3.x (required for Magento 2.4.8).
Key changes:
- Extended Monolog dependency constraint to support both major versions (
^2.0 || ^3.0) - Implemented runtime detection in LogLevel source model to use enum values when available
- Refactored StdoutHandler and tests to use integer log levels directly for cross-version compatibility
Reviewed changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| composer.json | Updated monolog constraint to ^2.0 || ^3.0 for Magento 2.4.8 compatibility |
| src/Logger/StdoutHandler.php | Replaced Logger::INFO constant with integer value (200) for cross-version compatibility |
| src/Model/Config/Source/LogLevel.php | Added runtime detection with class_exists(Level::class) to support both Monolog 2.x constants and 3.x enum values |
| src/Test/Unit/Logger/StdoutHandlerTest.php | Updated to use hardcoded integer log levels and added helper method to extract values from both int and Level types; fixed incorrect config path |
| src/Test/Unit/Model/Config/Source/LogLevelTest.php | Replaced Monolog constant references with hardcoded integer values for version-independent testing |
| README.md | Updated version badge to reflect support for Magento 2.4.6 through 2.4.8 |
| CHANGELOG.md | Documented Monolog 3.x support and backward compatibility changes |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| ['value' => 100, 'label' => 'DEBUG'], | ||
| ['value' => 200, 'label' => 'INFO'], | ||
| ['value' => 250, 'label' => 'NOTICE'], | ||
| ['value' => 300, 'label' => 'WARNING'], | ||
| ['value' => 400, 'label' => 'ERROR'], | ||
| ['value' => 500, 'label' => 'CRITICAL'], | ||
| ['value' => 550, 'label' => 'ALERT'], | ||
| ['value' => 600, 'label' => 'EMERGENCY'], |
There was a problem hiding this comment.
The test expects plain string labels (e.g., 'label' => 'DEBUG') but the actual LogLevel::toOptionArray() method returns Phrase objects via __('DEBUG'). This assertion will fail because Phrase objects don't equal strings directly.
The test should either:
- Use
->getText()on the labels before comparison, or - Expect
Phraseobjects in the expected array
Example fix:
$expectedOptions = [
['value' => 100, 'label' => __('DEBUG')],
// ... etc
];| ['value' => 100, 'label' => 'DEBUG'], | |
| ['value' => 200, 'label' => 'INFO'], | |
| ['value' => 250, 'label' => 'NOTICE'], | |
| ['value' => 300, 'label' => 'WARNING'], | |
| ['value' => 400, 'label' => 'ERROR'], | |
| ['value' => 500, 'label' => 'CRITICAL'], | |
| ['value' => 550, 'label' => 'ALERT'], | |
| ['value' => 600, 'label' => 'EMERGENCY'], | |
| ['value' => 100, 'label' => __('DEBUG')], | |
| ['value' => 200, 'label' => __('INFO')], | |
| ['value' => 250, 'label' => __('NOTICE')], | |
| ['value' => 300, 'label' => __('WARNING')], | |
| ['value' => 400, 'label' => __('ERROR')], | |
| ['value' => 500, 'label' => __('CRITICAL')], | |
| ['value' => 550, 'label' => __('ALERT')], | |
| ['value' => 600, 'label' => __('EMERGENCY')], |
Magento 2.4.8 requires Monolog 3.x, which introduces breaking changes: log level constants now return
Levelenum instead of integers.Changes
^2.0 || ^3.0class_exists(Level::class)to access enum values in Monolog 3.xCompatibility
Also fixes incorrect config path in test (
general/logging/log_levelvslog_stream_settings/logging/log_level).