-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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
Add AsMonologProcessor attribute #1637
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
<?php declare(strict_types=1); | ||
|
||
/* | ||
* This file is part of the Monolog package. | ||
* | ||
* (c) Jordi Boggiano <j.boggiano@seld.be> | ||
* | ||
* 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 or a method as a processor. | ||
* | ||
* 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: processors should still be turned into a callable if | ||
* needed and manually pushed to the loggers and to the processable handlers. | ||
*/ | ||
#[\Attribute(\Attribute::TARGET_CLASS | \Attribute::TARGET_METHOD | \Attribute::IS_REPEATABLE)] | ||
class AsMonologProcessor | ||
{ | ||
/** | ||
* @param string|null $channel The logging channel the processor should be pushed to. | ||
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. In I didn't add any hints about this here because I guess it's just easier to accept everything and let each implementation do what they want. |
||
* @param string|null $handler The handler the processor should be pushed to. | ||
* @param string|null $method The method that processes the records (if the attribute is used at the class level). | ||
*/ | ||
public function __construct( | ||
public ?string $channel = null, | ||
public ?string $handler = null, | ||
public ?string $method = null, | ||
) { | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
<?php declare(strict_types=1); | ||
|
||
/* | ||
* This file is part of the Monolog package. | ||
* | ||
* (c) Jordi Boggiano <j.boggiano@seld.be> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Monolog\Attribute; | ||
|
||
use PHPUnit\Framework\TestCase; | ||
|
||
/** | ||
* @requires PHP 8.0 | ||
*/ | ||
final class AsMonologProcessorTest extends TestCase | ||
{ | ||
public function test(): void | ||
{ | ||
$asMonologProcessor = new AsMonologProcessor('channel', 'handler', 'method'); | ||
$this->assertSame('channel', $asMonologProcessor->channel); | ||
$this->assertSame('handler', $asMonologProcessor->handler); | ||
$this->assertSame('method', $asMonologProcessor->method); | ||
|
||
$asMonologProcessor = new AsMonologProcessor(null, null, null); | ||
$this->assertNull($asMonologProcessor->channel); | ||
$this->assertNull($asMonologProcessor->handler); | ||
$this->assertNull($asMonologProcessor->method); | ||
} | ||
} |
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.
Having
Monolog
in the name is good from an external POV I think. In a project, it gives more information than justAsProcessor
.