Skip to content

Add Magento 2.4.8 compatibility via Monolog 3.x support#7

Open
mohaelmrabet wants to merge 1 commit intomasterfrom
feature/magento-2-4-8-compatibility
Open

Add Magento 2.4.8 compatibility via Monolog 3.x support#7
mohaelmrabet wants to merge 1 commit intomasterfrom
feature/magento-2-4-8-compatibility

Conversation

@mohaelmrabet
Copy link
Contributor

Magento 2.4.8 requires Monolog 3.x, which introduces breaking changes: log level constants now return Level enum instead of integers.

Changes

  • composer.json: Extend monolog constraint to ^2.0 || ^3.0
  • StdoutHandler: Use integer log levels directly (compatible with both versions)
  • LogLevel source model: Runtime detection via class_exists(Level::class) to access enum values in Monolog 3.x
// Monolog 3.x
['value' => Level::Debug->value, 'label' => __('DEBUG')]

// Monolog 2.x fallback
['value' => Logger::DEBUG, 'label' => __('DEBUG')]

Compatibility

Magento Monolog
2.4.6-2.4.7 2.x ✓
2.4.8 3.x ✓

Also fixes incorrect config path in test (general/logging/log_level vs log_stream_settings/logging/log_level).

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment on lines +28 to +35
['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'],
Copy link

Copilot AI Dec 2, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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:

  1. Use ->getText() on the labels before comparison, or
  2. Expect Phrase objects in the expected array

Example fix:

$expectedOptions = [
    ['value' => 100, 'label' => __('DEBUG')],
    // ... etc
];
Suggested change
['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')],

Copilot uses AI. Check for mistakes.
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