Skip to content
Draft
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 17 additions & 1 deletion app/Mage.php
Original file line number Diff line number Diff line change
Expand Up @@ -870,7 +870,7 @@ public static function isInstalled($options = [])
* log facility (??)
*
* @param array|object|string $message
* @param null|int|Level::* $level
* @param null|int|Level::*|string $level
* @param null|string $file
* @param bool $forceLog
*/
Expand Down Expand Up @@ -906,8 +906,24 @@ public static function log($message, $level = null, $file = '', $forceLog = fals
$levelValue = $level->value;
} elseif (is_null($level)) {
$levelValue = Level::Debug->value;
} elseif (is_string($level) && !is_numeric($level)) {
// PSR 3 Log level
$levelValue = Level::fromName($level)->value;
} else {
$levelValue = (int) $level;
// change RFC_5424 Log Level into Monolog.
if ($levelValue >= 0 && $levelValue <= 7) {
$levelValue = (match ($levelValue) {
7 => Level::Debug,
6 => Level::Info,
5 => Level::Notice,
4 => Level::Warning,
3 => Level::Error,
2 => Level::Critical,
1 => Level::Alert,
0 => Level::Emergency,
})->value;
}
}

if (!self::$_isDeveloperMode && $levelValue > $maxLogLevel && !$forceLog) {
Expand Down
26 changes: 26 additions & 0 deletions app/code/core/Mage/Core/Helper/PsrLogger.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php

/**
* @copyright For copyright and license information, read the COPYING.txt file.
* @link /COPYING.txt
* @license Open Software License (OSL 3.0)
* @package Mage_Core
*/

use Psr\Log\LoggerInterface;
use Psr\Log\LoggerTrait;

/**
* PsrLogger model
*
* @package Mage_Core
*/
class Mage_Core_Helper_PsrLogger extends Mage_Core_Helper_Abstract implements LoggerInterface
{
use LoggerTrait;

public function log($level, string|\Stringable $message, array $context = []): void
{
Mage::log((string) $message, $level, null, false, $context);
}
}
Comment on lines 27 to 41
Copy link

Copilot AI Dec 9, 2025

Choose a reason for hiding this comment

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

The new Mage_Core_Helper_PsrLogger class lacks test coverage. Since other helpers in the same directory have unit tests (e.g., tests/unit/Mage/Core/Helper/DataTest.php), this class should also have a corresponding test file. Consider adding tests/unit/Mage/Core/Helper/PsrLoggerTest.php to verify:

  • The log() method correctly calls Mage::log() with the expected parameters
  • PSR-3 log levels (debug, info, warning, error, etc.) are properly passed through
  • The $context array is correctly forwarded
  • String and Stringable messages are handled correctly

Copilot uses AI. Check for mistakes.
Loading