forked from Seldaek/monolog
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a WithMonologChannel attribute (Seldaek#1847)
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.
- Loading branch information
Showing
2 changed files
with
44 additions
and
0 deletions.
There are no files selected for viewing
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,29 @@ | ||
<?php declare(strict_types=1); | ||
|
||
/* | ||
* This file is part of the Monolog package. | ||
* | ||
* (c) Jordi Boggiano <[email protected]> | ||
* | ||
* 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 | ||
) { | ||
} | ||
} |
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,15 @@ | ||
<?php | ||
|
||
namespace Monolog\Attribute; | ||
|
||
use PHPUnit\Framework\TestCase; | ||
|
||
class WithMonologChannelTest extends TestCase | ||
{ | ||
public function test(): void | ||
{ | ||
$attribute = new WithMonologChannel('fixture'); | ||
$this->assertSame('fixture', $attribute->channel); | ||
} | ||
|
||
} |