From f52d5979879b17d4bba7abf517e7ed6ef30bd370 Mon Sep 17 00:00:00 2001 From: Christophe Coevoet Date: Tue, 24 Oct 2023 17:49:34 +0200 Subject: [PATCH] Add a WithMonologChannel attribute This attribute is meant to be used by frameworks / integrations to choose which logger instance to inject in a class when they manage several channels, if they decide to use it. This attribute will have no effect in Monolog itself as the wiring of the logger in other classes is not managed by Monolog. --- src/Monolog/Attribute/WithMonologChannel.php | 29 +++++++++++++++++++ .../Attribute/WithMonologChannelTest.php | 15 ++++++++++ 2 files changed, 44 insertions(+) create mode 100644 src/Monolog/Attribute/WithMonologChannel.php create mode 100644 tests/Monolog/Attribute/WithMonologChannelTest.php diff --git a/src/Monolog/Attribute/WithMonologChannel.php b/src/Monolog/Attribute/WithMonologChannel.php new file mode 100644 index 000000000..862e05b33 --- /dev/null +++ b/src/Monolog/Attribute/WithMonologChannel.php @@ -0,0 +1,29 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Monolog\Attribute; + +/** + * A reusable attribute to help configure a class as expecting a given logger channel. + * + * Using it offers no guarantee: it needs to be leveraged by a Monolog third-party consumer. + * + * Using it with the Monolog library only has no effect at all: wiring the logger instance into + * other classes is not managed by Monolog. + */ +#[\Attribute(\Attribute::TARGET_CLASS)] +final class WithMonologChannel +{ + public function __construct( + public readonly string $channel + ) { + } +} diff --git a/tests/Monolog/Attribute/WithMonologChannelTest.php b/tests/Monolog/Attribute/WithMonologChannelTest.php new file mode 100644 index 000000000..74875d7d0 --- /dev/null +++ b/tests/Monolog/Attribute/WithMonologChannelTest.php @@ -0,0 +1,15 @@ +assertSame('fixture', $attribute->channel); + } + +}