diff --git a/bundles/best_practices.rst b/bundles/best_practices.rst index 431a267db97..12e1a923e87 100644 --- a/bundles/best_practices.rst +++ b/bundles/best_practices.rst @@ -461,6 +461,11 @@ to the service id. For example, in MonologBundle, an alias is created from ``Psr\Log\LoggerInterface`` to ``logger`` so that the ``LoggerInterface`` type-hint can be used for autowiring. +.. versionadded:: 4.2 + + Since Monolog Bundle 3.5 each channel bind into container by type-hinted alias. + More info in the part about :ref:`how to autowire monolog channels `. + Services should not use autowiring or autoconfiguration. Instead, all services should be defined explicitly. diff --git a/console/commands_as_services.rst b/console/commands_as_services.rst index 000dffeca48..652329d13dc 100644 --- a/console/commands_as_services.rst +++ b/console/commands_as_services.rst @@ -53,6 +53,11 @@ the command class will automatically be registered as a service and passed the ` argument (thanks to autowiring). In other words, *just* by creating this class, everything works! You can call the ``app:sunshine`` command and start logging. +.. versionadded:: 4.2 + + Since Monolog Bundle 3.5 each channel bind into container by type-hinted alias. + More info in the part about :ref:`how to autowire monolog channels `. + .. caution:: You *do* have access to services in ``configure()``. However, if your command is diff --git a/controller.rst b/controller.rst index 2513b5d3faf..0def47a0bc7 100644 --- a/controller.rst +++ b/controller.rst @@ -275,6 +275,11 @@ the argument by its name: ]) ; +.. versionadded:: 4.2 + + Since Monolog Bundle 3.5 each channel bind into container by type-hinted alias. + More info in the part about :ref:`how to autowire monolog channels `. + Like with all services, you can also use regular :ref:`constructor injection ` in your controllers. diff --git a/logging.rst b/logging.rst index c54b30f7c0d..c026a4a3c4b 100644 --- a/logging.rst +++ b/logging.rst @@ -353,6 +353,11 @@ specific channel (``app`` by default), use the ``monolog.logger`` tag with the ``channel`` property as explained in the :ref:`Dependency Injection reference `. +.. versionadded:: 4.2 + + Since Monolog Bundle 3.5 each channel bind into container by type-hinted alias. + More info in the part about :ref:`how to autowire monolog channels `. + Adding extra Data to each Log (e.g. a unique request token) ----------------------------------------------------------- diff --git a/logging/channels_handlers.rst b/logging/channels_handlers.rst index 200f9504ea0..4bc10c87c16 100644 --- a/logging/channels_handlers.rst +++ b/logging/channels_handlers.rst @@ -18,6 +18,11 @@ the channel). in the container (use the ``php bin/console debug:container monolog`` command to see a full list) and those are injected into different services. +.. versionadded:: 4.2 + + Since Monolog Bundle 3.5 each channel bind into container by type-hinted alias. + More info in the part about :ref:`how to autowire monolog channels `. + .. _logging-channel-handler: Switching a Channel to a different Handler @@ -172,3 +177,26 @@ Symfony automatically registers one service per channel (in this example, the channel ``foo`` creates a service called ``monolog.logger.foo``). In order to inject this service into others, you must update the service configuration to :ref:`choose the specific service to inject `. + +.. _monolog-autowire-channels: + +How to autowire logger channels +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +.. versionadded:: 4.2 + + This feature available since MonologBundle 3.5 + +Each channel already bind into container by type-hinted alias. +Just use method variables, which follows next naming template ``Psr\Log\LoggerInterface $Logger``. +For example, you have ``App\Log\CustomLogger`` service which tagged by ``app`` logger channel +as described in part :ref:`Logging with a custom logging channel `. +Now you can remove service configuration at all and change constructor signature: + +.. code-block:: diff + + - public function __construct(LoggerInterface $logger) + + public function __construct(LoggerInterface $appLogger) + { + $this->logger = $appLogger; + } diff --git a/quick_tour/the_architecture.rst b/quick_tour/the_architecture.rst index 19d77648f7d..1f01f4cacc9 100644 --- a/quick_tour/the_architecture.rst +++ b/quick_tour/the_architecture.rst @@ -52,6 +52,11 @@ But wait! Something *very* cool just happened. Symfony read the ``LoggerInterfac type-hint and automatically figured out that it should pass us the Logger object! This is called *autowiring*. +.. versionadded:: 4.2 + + Furthermore, since Monolog Bundle 3.5 each channel bind into container by type-hinted alias. + More info in the part about :ref:`how to autowire monolog channels `. + Every bit of work that's done in a Symfony app is done by an *object*: the Logger object logs things and the Twig object renders templates. These objects are called *services* and they are *tools* that help you build rich features. diff --git a/reference/configuration/monolog.rst b/reference/configuration/monolog.rst index cf6eb53e443..71a17729ea1 100644 --- a/reference/configuration/monolog.rst +++ b/reference/configuration/monolog.rst @@ -8,6 +8,11 @@ The MonologBundle integrates the Monolog :doc:`logging ` library in Symfony applications. All these options are configured under the ``monolog`` key in your application configuration. +.. versionadded:: 4.2 + + Since Monolog Bundle 3.5 each channel bind into container by type-hinted alias. + More info in the part about :ref:`how to autowire monolog channels `. + .. code-block:: terminal # displays the default config values defined by Symfony diff --git a/reference/dic_tags.rst b/reference/dic_tags.rst index 73a735c736e..476a6a7012e 100644 --- a/reference/dic_tags.rst +++ b/reference/dic_tags.rst @@ -534,6 +534,11 @@ channel when injecting the logger in a service. the corresponding logger service from the service container directly (see :ref:`monolog-channels-config`). +.. versionadded:: 4.2 + + Since Monolog Bundle 3.5 each channel bind into container by type-hinted alias. + More info in the part about :ref:`how to autowire monolog channels `. + .. _dic_tags-monolog-processor: monolog.processor diff --git a/service_container.rst b/service_container.rst index fc5405c1d7e..8a00c557eea 100644 --- a/service_container.rst +++ b/service_container.rst @@ -616,6 +616,13 @@ But, you can control this and pass in a different logger: This tells the container that the ``$logger`` argument to ``__construct`` should use service whose id is ``monolog.logger.request``. +.. versionadded:: 4.2 + + Since Monolog Bundle 3.5 each channel already into container by type-hinted alias. + Instead of explicit declare configuration ``$logger: '@monolog.logger.request'`` + just use variable in the constructor signature: ``Psr\Log\LoggerInterface $requestLogger``. + More info in the part about :ref:`how to autowire monolog channels `. + .. _container-debug-container: For a full list of *all* possible services in the container, run: @@ -714,6 +721,11 @@ argument for *any* service defined in this file! You can bind arguments by name (e.g. ``$adminEmail``), by type (e.g. ``Psr\Log\LoggerInterface``) or both (e.g. ``Psr\Log\LoggerInterface $requestLogger``). +.. versionadded:: 4.2 + + Since Monolog Bundle 3.5 each channel already bind into container by type-hinted alias. + More info in the part about :ref:`how to autowire monolog channels `. + The ``bind`` config can also be applied to specific services or when loading many services at once (i.e. :ref:`service-psr4-loader`). diff --git a/service_container/3.3-di-changes.rst b/service_container/3.3-di-changes.rst index 7aed2e63980..5ef2db9b69d 100644 --- a/service_container/3.3-di-changes.rst +++ b/service_container/3.3-di-changes.rst @@ -392,8 +392,15 @@ create the class:: } Great! In Symfony 3.2 or lower, you would now need to register this as a service -in ``services.yaml`` and tag it with ``kernel.event_subscriber``. In Symfony 3.3, -you're already done! The service is :ref:`automatically registered `. +in ``services.yaml`` and tag it with ``kernel.event_subscriber``. +In Symfony 3.3, you're already done! + +.. versionadded:: 4.2 + + Furthermore, since Monolog Bundle 3.5 each channel bind into container by type-hinted alias. + More info in the part about :ref:`how to autowire monolog channels `. + +The service is :ref:`automatically registered `. And thanks to ``autoconfigure``, Symfony automatically tags the service because it implements ``EventSubscriberInterface``. diff --git a/service_container/autowiring.rst b/service_container/autowiring.rst index 0e1fad1aed1..19ba0583ffa 100644 --- a/service_container/autowiring.rst +++ b/service_container/autowiring.rst @@ -248,6 +248,11 @@ class is type-hinted. adds an alias: ``Psr\Log\LoggerInterface`` that points to the ``logger`` service. This is why arguments type-hinted with ``Psr\Log\LoggerInterface`` can be autowired. +.. versionadded:: 4.2 + + Since Monolog Bundle 3.5 each channel bind into container by type-hinted alias. + More info in the part about :ref:`how to autowire monolog channels `. + .. _autowiring-interface-alias: Working with Interfaces