-
Notifications
You must be signed in to change notification settings - Fork 1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
NEXT-23811 - Implement configurable log handling for plugins, fixes #…
- Loading branch information
Showing
4 changed files
with
94 additions
and
3 deletions.
There are no files selected for viewing
9 changes: 9 additions & 0 deletions
9
changelog/_unreleased/2022-10-13-implement-configurable-plugin-log-handling.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
--- | ||
title: Implement consideration of log configuration for plugins | ||
issue: NEXT-23811 | ||
author: Alexander Wink | ||
author_email: [email protected] | ||
author_github: @jinnoflife | ||
--- | ||
# Core | ||
* Changed handling of LoggerFactory to consider log configuration of project |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
<?php declare(strict_types=1); | ||
|
||
namespace Shopware\Tests\Unit\Core\Framework\Log; | ||
|
||
use Monolog\Handler\NullHandler; | ||
use Monolog\Handler\RotatingFileHandler; | ||
use Monolog\Logger; | ||
use Shopware\Core\Framework\Log\LoggerFactory; | ||
|
||
/** | ||
* @internal | ||
* | ||
* @covers \Shopware\Core\Framework\Log\LoggerFactory | ||
*/ | ||
class LoggerFactoryTest extends \PHPUnit\Framework\TestCase | ||
{ | ||
public function testNullLogHandler(): void | ||
{ | ||
$providedHandler = [new NullHandler()]; | ||
$mainLogger = new Logger('test_logger', $providedHandler); | ||
$loggerFactory = new LoggerFactory('test_case', $mainLogger); | ||
|
||
/** @var \Monolog\Logger $createdLogger */ | ||
$createdLogger = $loggerFactory->createRotating('test_file_path'); | ||
$usedHandler = $createdLogger->getHandlers(); | ||
|
||
static::assertCount(1, $usedHandler); | ||
static::assertInstanceOf(RotatingFileHandler::class, current($usedHandler), 'Handler differs from excpected'); | ||
} | ||
|
||
public function testRotatingFileLogHandler(): void | ||
{ | ||
$providedHandler = [new RotatingFileHandler('test')]; | ||
$mainLogger = new Logger('test_logger', $providedHandler); | ||
$loggerFactory = new LoggerFactory('test_case', $mainLogger); | ||
|
||
/** @var \Monolog\Logger $createdLogger */ | ||
$createdLogger = $loggerFactory->createRotating('test_file_path'); | ||
$usedHandler = $createdLogger->getHandlers(); | ||
|
||
static::assertCount(1, $usedHandler); | ||
static::assertInstanceOf(RotatingFileHandler::class, current($usedHandler), 'Handler differs from excpected'); | ||
} | ||
|
||
public function testMultipleLogHandlers(): void | ||
{ | ||
$providedHandler = [ | ||
new RotatingFileHandler('test'), | ||
new NullHandler(), | ||
]; | ||
$mainLogger = new Logger('test_logger', $providedHandler); | ||
$loggerFactory = new LoggerFactory('test_case', $mainLogger); | ||
|
||
/** @var \Monolog\Logger $createdLogger */ | ||
$createdLogger = $loggerFactory->createRotating('test_file_path'); | ||
$usedHandler = $createdLogger->getHandlers(); | ||
|
||
static::assertCount(\count($providedHandler), $usedHandler); | ||
static::assertSame($providedHandler, $usedHandler, 'Handler differs from excpected'); | ||
} | ||
} |