-
-
Notifications
You must be signed in to change notification settings - Fork 450
[Core] add PsrLogger and support RFC 5424 log level #5144
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
8749071
a66c18a
a7e7ebd
72a4448
9e06542
06a42a5
f400438
0a4d7bf
63a1c88
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| /** | ||
| * @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\InvalidArgumentException; | ||
| use Psr\Log\LoggerInterface; | ||
| use Psr\Log\LoggerTrait; | ||
| use Psr\Log\LogLevel; | ||
|
|
||
| /** | ||
| * Provides a PSR-3 LoggerInterface implementation that wraps Mage::log(). | ||
| * | ||
| * This class enables integration with PSR-3 compatible logging libraries and tools | ||
| * by forwarding log messages to the native Mage::log() method. It allows Magento | ||
| * modules and external libraries to use standardized logging practices within the | ||
| * OpenMage framework. | ||
| * | ||
| * @package Mage_Core | ||
| */ | ||
| class Mage_Core_Helper_PsrLogger extends Mage_Core_Helper_Abstract implements LoggerInterface | ||
|
Check warning on line 27 in app/code/core/Mage/Core/Helper/PsrLogger.php
|
||
| { | ||
| use LoggerTrait; | ||
|
|
||
| public function log($level, string|\Stringable $message, array $context = []): void | ||
| { | ||
| // unknown log level need to throw an InvalidArgumentException | ||
| $reflectionClass = new ReflectionClass(LogLevel::class); | ||
| if (!in_array($level, $reflectionClass->getConstants())) { | ||
|
Check warning on line 35 in app/code/core/Mage/Core/Helper/PsrLogger.php
|
||
| throw new InvalidArgumentException('Level "' . $level . '" is not defined, use one of: ' . implode(', ', $reflectionClass->getConstants())); | ||
|
Check warning on line 36 in app/code/core/Mage/Core/Helper/PsrLogger.php
|
||
| } | ||
|
|
||
| Mage::log((string) $message, $level, null, false, $context); | ||
| } | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.