0

I am wondering what the exact use it for the interpolate function when you have a PSR-3 logger. I know how it works by looking at this reference:

https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-3-logger-interface.md#12-message

But so far I cannot seem to think up of a use-case for it yet. Why would you not simply interpolate it like you normally do? Instead they opt to use a context array with placeholders.

If somebody could tell me why this would be helpful, over just putting the variable straight in there I would be grateful.

Thanks.

Stephan-v
  • 19,255
  • 31
  • 115
  • 201

1 Answers1

2

I don't know whether I understand your question completly, anyways: Every method accepts an array as context data. This is meant to hold any extraneous information that does not fit well in a string.

To replace every placeholder in the array we need a method, this is interpolate()

PSR-3 | 1.3 - Context

Xatenev
  • 6,383
  • 3
  • 18
  • 42
  • Well in the end if you use interpolation you will end up with the array data in the string anyways. So why not directly put it in there. But I have been playing around with it for a while and it could be helpful as a sort of alias. Since you might not want to put things like: ```{$object->method()}``` things into your string directly since it might make for a big and unclear string when you do this multiple times. Thanks for taking your time! – Stephan-v Dec 12 '16 at 10:27
  • @Stephan-v there are many reasons why it makes sense: 1. to avoid having to roll your own interpolation system. 2. to reuse entries from the extra context (most of the time, you want the extra info in both the context and the message) 3. some logging system need to identify the logging message (typically with pattern matching etc), this is easier done when the message is not changing all the time. – Christian Oct 26 '22 at 20:13