Skip to content
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

PsrMessage DTO for extended context handling #17

Merged
merged 5 commits into from
Jul 16, 2020

Conversation

mrodikov
Copy link
Contributor

PSRTarget is currently cast a logged message to a string, and there is no way to pass the context in any way since Yii does not intend to add the context to the message from outside.

The new DTO solves this problem by, on the one hand, adding the ability to transmit both message and additional context at the same time, and, on the other hand, leaving the ability to use itself for standard Yii log targets by implementing __toString method.

Usage example:

$psrLogger = new \Monolog\Logger('my_logger');
$psrLogger->pushHandler(new \Monolog\Handler\SlackHandler('slack_token', 'logs', null, true, null, \Monolog\Logger::DEBUG));
$psrLogger->pushProcessor(new \Monolog\Processor\PsrLogMessageProcessor()); // PSR-3 message processing

Now we can add additional context to our messages (and use PSR-3 placeholders populated by our context data):

Yii::error(new PsrMessage('Critical message', ['my' => 'context']));
Yii::getLogger()->log(new PsrMessage('Critical message from {process}', [
    'process' => 'BANANA',
    'other' => 'data',
]), Psr\Log\LogLevel::CRITICAL);

Maksim Rodikov and others added 4 commits July 15, 2020 14:58
[*] Message data transfer object now accepted for extended context handling
[*] Message data transfer object now accepted for extended context handling
[*] Message data transfer object now accepted for extended context handling
PsrMessage data transfer object for advanced context handling
@samdark
Copy link
Owner

samdark commented Jul 15, 2020

Looks good to me. Would you please add an example of using it to readme? Then it's good to merge.

@mrodikov
Copy link
Contributor Author

Sure I will (tomorrow)

@mrodikov
Copy link
Contributor Author

Done

@samdark samdark merged commit ccb29ec into samdark:master Jul 16, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants