-
-
Notifications
You must be signed in to change notification settings - Fork 238
Remove legacy code paths #519
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
Merged
+20
−48
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 |
---|---|---|
|
@@ -19,10 +19,8 @@ | |
use Monolog\Processor\PsrLogMessageProcessor; | ||
use Monolog\ResettableInterface; | ||
use Symfony\Bridge\Monolog\Handler\FingersCrossed\HttpCodeActivationStrategy; | ||
use Symfony\Bridge\Monolog\Logger as LegacyLogger; | ||
use Symfony\Bridge\Monolog\Processor\SwitchUserTokenProcessor; | ||
use Symfony\Bridge\Monolog\Processor\TokenProcessor; | ||
use Symfony\Bridge\Monolog\Processor\WebProcessor; | ||
use Symfony\Component\Config\FileLocator; | ||
use Symfony\Component\DependencyInjection\Argument\BoundArgument; | ||
use Symfony\Component\DependencyInjection\ChildDefinition; | ||
|
@@ -31,18 +29,15 @@ | |
use Symfony\Component\DependencyInjection\Loader\PhpFileLoader; | ||
use Symfony\Component\DependencyInjection\Reference; | ||
use Symfony\Component\HttpKernel\DependencyInjection\Extension; | ||
use Symfony\Component\HttpKernel\Log\DebugLoggerConfigurator; | ||
use Symfony\Contracts\HttpClient\HttpClientInterface; | ||
|
||
/** | ||
* MonologExtension is an extension for the Monolog library. | ||
* | ||
* @author Jordi Boggiano <j.boggiano@seld.be> | ||
* @author Christophe Coevoet <stof@notk.org> | ||
* | ||
* @final since 3.9.0 | ||
*/ | ||
class MonologExtension extends Extension | ||
final class MonologExtension extends Extension | ||
{ | ||
private $nestedHandlers = []; | ||
|
||
|
@@ -61,10 +56,6 @@ public function load(array $configs, ContainerBuilder $container) | |
$loader = new PhpFileLoader($container, new FileLocator(__DIR__.'/../../config')); | ||
$loader->load('monolog.php'); | ||
|
||
if (!class_exists(DebugLoggerConfigurator::class)) { | ||
$container->getDefinition('monolog.logger_prototype')->setClass(LegacyLogger::class); | ||
} | ||
|
||
$container->setParameter('monolog.use_microseconds', $config['use_microseconds']); | ||
|
||
$handlers = []; | ||
|
@@ -95,43 +86,35 @@ public function load(array $configs, ContainerBuilder $container) | |
|
||
$container->setParameter('monolog.additional_channels', $config['channels'] ?? []); | ||
|
||
if (interface_exists(ProcessorInterface::class)) { | ||
$container->registerForAutoconfiguration(ProcessorInterface::class) | ||
->addTag('monolog.processor'); | ||
} else { | ||
$container->registerForAutoconfiguration(WebProcessor::class) | ||
->addTag('monolog.processor'); | ||
} | ||
if (interface_exists(ResettableInterface::class)) { | ||
$container->registerForAutoconfiguration(ResettableInterface::class) | ||
->addTag('kernel.reset', ['method' => 'reset']); | ||
} | ||
$container->registerForAutoconfiguration(ProcessorInterface::class) | ||
->addTag('monolog.processor'); | ||
$container->registerForAutoconfiguration(ResettableInterface::class) | ||
->addTag('kernel.reset', ['method' => 'reset']); | ||
Comment on lines
+89
to
+92
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Min Monolog always has these interfaces. |
||
$container->registerForAutoconfiguration(TokenProcessor::class) | ||
->addTag('monolog.processor'); | ||
|
||
if (interface_exists(HttpClientInterface::class)) { | ||
$handlerAutoconfiguration = $container->registerForAutoconfiguration(HandlerInterface::class); | ||
$handlerAutoconfiguration->setBindings($handlerAutoconfiguration->getBindings() + [ | ||
HttpClientInterface::class => new BoundArgument(new Reference('monolog.http_client'), false), | ||
]); | ||
} | ||
|
||
if (80000 <= \PHP_VERSION_ID) { | ||
$container->registerAttributeForAutoconfiguration(AsMonologProcessor::class, static function (ChildDefinition $definition, AsMonologProcessor $attribute, \Reflector $reflector): void { | ||
$tagAttributes = get_object_vars($attribute); | ||
if ($reflector instanceof \ReflectionMethod) { | ||
if (isset($tagAttributes['method'])) { | ||
throw new \LogicException(\sprintf('AsMonologProcessor attribute cannot declare a method on "%s::%s()".', $reflector->class, $reflector->name)); | ||
} | ||
|
||
$tagAttributes['method'] = $reflector->getName(); | ||
$container->registerAttributeForAutoconfiguration(AsMonologProcessor::class, static function (ChildDefinition $definition, AsMonologProcessor $attribute, \Reflector $reflector): void { | ||
$tagAttributes = get_object_vars($attribute); | ||
if ($reflector instanceof \ReflectionMethod) { | ||
if (isset($tagAttributes['method'])) { | ||
throw new \LogicException(\sprintf('AsMonologProcessor attribute cannot declare a method on "%s::%s()".', $reflector->class, $reflector->name)); | ||
} | ||
|
||
$definition->addTag('monolog.processor', $tagAttributes); | ||
}); | ||
$container->registerAttributeForAutoconfiguration(WithMonologChannel::class, static function (ChildDefinition $definition, WithMonologChannel $attribute): void { | ||
$definition->addTag('monolog.logger', ['channel' => $attribute->channel]); | ||
}); | ||
} | ||
$tagAttributes['method'] = $reflector->getName(); | ||
} | ||
|
||
$definition->addTag('monolog.processor', $tagAttributes); | ||
}); | ||
$container->registerAttributeForAutoconfiguration(WithMonologChannel::class, static function (ChildDefinition $definition, WithMonologChannel $attribute): void { | ||
$definition->addTag('monolog.logger', ['channel' => $attribute->channel]); | ||
}); | ||
} | ||
|
||
/** | ||
|
@@ -899,23 +882,12 @@ private function getHandlerClassByType($handlerType) | |
|
||
private function buildPsrLogMessageProcessor(ContainerBuilder $container, array $processorOptions): string | ||
{ | ||
static $hasConstructorArguments; | ||
|
||
if (!isset($hasConstructorArguments)) { | ||
$reflectionConstructor = (new \ReflectionClass(PsrLogMessageProcessor::class))->getConstructor(); | ||
$hasConstructorArguments = null !== $reflectionConstructor && $reflectionConstructor->getNumberOfParameters() > 0; | ||
unset($reflectionConstructor); | ||
} | ||
|
||
$processorId = 'monolog.processor.psr_log_message'; | ||
$processorArguments = []; | ||
|
||
unset($processorOptions['enabled']); | ||
|
||
if (!empty($processorOptions)) { | ||
if (!$hasConstructorArguments) { | ||
throw new \RuntimeException('Monolog 1.26 or higher is required for the "date_format" and "remove_used_context_fields" options to be used.'); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Min Monolog always has |
||
} | ||
if ($processorOptions) { | ||
$processorArguments = [ | ||
$processorOptions['date_format'] ?? null, | ||
$processorOptions['remove_used_context_fields'] ?? false, | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Min Symfony always has this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was added in Symfony 6.4 with symfony/symfony#51284. I wonder if we should think about bumping the minimum required version of Symfony components in the
3.x
branch to 6.4 and do some of the clean up work there already.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm ok with the idea, if needed I'll open a PR that bumps Symfony in 3.x.