zendframework / zend-expressive-swoole

Swoole support for Expressive applications
BSD 3-Clause "New" or "Revised" License
158 stars 14 forks source link

Psr3AccessLogDecorator does not replace placeholders #68

Closed grizzm0 closed 5 years ago

grizzm0 commented 5 years ago

The Psr3AccessLogDecorator does not replace placeholders in Psr3AccessLogDecorator::log().

https://github.com/zendframework/zend-expressive-swoole/blob/69c36f044aa22cf0b202eedeb3fc8f31cfb6f023/src/Log/Psr3AccessLogDecorator.php#L134-L137

https://github.com/zendframework/zend-expressive-swoole/blob/69c36f044aa22cf0b202eedeb3fc8f31cfb6f023/src/Log/StdoutLogger.php#L98-L105

grizzm0 commented 5 years ago

Should we just copy/paste the code or move it to a re-useable method or abstract class?

weierophinney commented 5 years ago

The way PSR-3 is worded is that values provided in $context MAY be used to replace any corresponding placeholders in the message (see section 1.2 of the PSR-3 spec). The StdoutLogger we supply does this, because it's useful, but implementations do not NEED to.

If you use Monolog, for instance, you have to add its PsrLogMessageProcessor to the instance for it to do any replacements. Others, such as apix/log do it out of the box.

As such, if and how placeholders are replaced is up to the PSR-3 logging implementation you choose. If the instance you are using does not support them, decorate your logger's log() method to do so.